Bind mounts are useful on NixOS August 1, 2026

Often, a NixOS module will not surface an option for overriding the default filesystem path for that module's persistence. Often labeled dataDir or stateDir, this option is useful for placing stateful data in a known location for backups or other organizational reasons.

In the case of the Unifi module there is no such exposed option. Though Nix/NixOS has several solutions to this predicament.

In the module definition there is a clear let variable for stateDir already. But, let expressions cannot be overridden by overrideAttrs. And ${stateDir} is called ten times in the module, and often interpolated into strings. It would be very annoying to override each calling attribute just to change this path.

The right thing to do is to open a pull request against Nixpkgs to surface dataDir as an option, which someone did in January. And it's clean because it only concerns the /data subpath in the modules stateDir root. The rest of the contents in stateDir are not crucial for persistence.

        BindPaths = [
          [...]
+         "${cfg.dataDir}:${stateDir}/data"
          [...]
        ];

But in the interim I will leverage filesystem bind mounts, referencing the hard coded path in the module.

{ ... }:

{
  services.unifi = {
    enable = true;
    openFirewall = false;
  };
  
  fileSystems."/var/lib/unifi/data" = {
    device = "/persist/unifi"; # Where I tend to keep things.
    fsType = "none";
    options = [ "bind" ];
  };
}

Pretty readable and understandable!