diff --git a/modules/files.nix b/modules/files.nix index daeeb0b1f..0f4207fe8 100644 --- a/modules/files.nix +++ b/modules/files.nix @@ -4,7 +4,7 @@ with lib; let - cfg = config.home.file; + cfg = filterAttrs (n: f: f.enable) config.home.file; homeDirectory = config.home.homeDirectory; diff --git a/modules/lib/file-type.nix b/modules/lib/file-type.nix index cc23292ba..b12b3262a 100644 --- a/modules/lib/file-type.nix +++ b/modules/lib/file-type.nix @@ -15,6 +15,14 @@ in fileType = basePathDesc: basePath: types.attrsOf (types.submodule ( { name, config, ... }: { options = { + enable = mkOption { + type = types.bool; + default = true; + description = '' + Whether this file should be generated. This option allows specific + files to be disabled. + ''; + }; target = mkOption { type = types.str; apply = p: diff --git a/tests/modules/files/default.nix b/tests/modules/files/default.nix index 52e44d22b..2c35b9a2e 100644 --- a/tests/modules/files/default.nix +++ b/tests/modules/files/default.nix @@ -1,4 +1,5 @@ { + files-disabled = ./disabled.nix; files-executable = ./executable.nix; files-hidden-source = ./hidden-source.nix; files-out-of-store-symlink = ./out-of-store-symlink.nix; diff --git a/tests/modules/files/disabled.nix b/tests/modules/files/disabled.nix new file mode 100644 index 000000000..b9ed858aa --- /dev/null +++ b/tests/modules/files/disabled.nix @@ -0,0 +1,14 @@ +{ ... }: + +{ + home.file."disabled" = { + enable = false; + text = '' + This file should not exist + ''; + }; + + nmt.script = '' + assertPathNotExists home-files/disabled + ''; +}