Conditionally add filesystem options

Hi,

I want to have default mount point options defined in a shared module (for all my server), this is what I have in my .nix config:

  fileSystems = lib.mkMerge [
    (lib.mkIf (builtins.elem "/tmp" config.fileSystems) {
      "/tmp".options = [
        "bind"
        "nodev"
        "nosuid"
      ];
    })
  ];

And this is an example config for a server:

  fileSystems."/tmp" = {
    device = "none";
    fsType = "tmpfs";
  };

Unfortunately this doesn’t work, I get the error:

error: infinite recursion encountered

Note that the main reason for doing that is to avoid forgetting to add the options, also note that not all servers have all the partitions, thus the need for conditional enabling it.

nixos version: 24.11
nix version: 2.24.11

An option can’t depend on itself.
For now you can write a function to produce your desired attrset. Or you can define a new option.
In the the next release you’ll get an .enable option:

And for /tmp specifically there’s already boot.tmp.useTmpfs which you may find suitable: