From 7efca2ca18062791cbaa838f4d3e23d629bb1473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BChmel?= Date: Wed, 25 Jan 2023 22:58:35 +0100 Subject: [PATCH] files: allow disabling creation of a file PR #3622 --- modules/files.nix | 2 +- modules/lib/file-type.nix | 8 ++++++++ tests/modules/files/default.nix | 1 + tests/modules/files/disabled.nix | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/modules/files/disabled.nix diff --git a/modules/files.nix b/modules/files.nix index daeeb0b1..0f4207fe 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 cc23292b..b12b3262 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 52e44d22..2c35b9a2 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 00000000..b9ed858a --- /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 + ''; +}