diff --git a/modules/files.nix b/modules/files.nix index 71b940d2..011f685e 100644 --- a/modules/files.nix +++ b/modules/files.nix @@ -67,16 +67,34 @@ in }; mode = mkOption { - type = types.str; - default = "444"; - description = "The permissions to apply to the file."; + type = types.nullOr types.str; + default = null; + description = '' + The permissions to apply to the file. + + DEPRECATED: use home.file.<name?>.executable + instead. + ''; + }; + + executable = mkOption { + type = types.nullOr types.bool; + default = null; + description = '' + Set the execute bit. If null, defaults to the mode + of the source file or to false + for files created through the text option. + ''; }; }; config = { target = mkDefault name; source = mkIf (config.text != null) ( - mkDefault (pkgs.writeText (storeFileName name) config.text) + mkDefault (pkgs.writeTextFile { + inherit (config) executable text; + name = storeFileName name; + }) ); }; }) @@ -105,6 +123,19 @@ in }) ]; + warnings = + let + badFiles = + map (f: f.target) + (filter (f: f.mode != null) + (attrValues cfg)); + badFilesStr = toString badFiles; + in + mkIf (badFiles != []) [ + ("The 'mode' field is deprecated for 'home.file', " + + "use 'executable' instead: ${badFilesStr}") + ]; + # This verifies that the links we are about to create will not # overwrite an existing file. home.activation.checkLinkTargets = dagEntryBefore ["writeBoundary"] ( @@ -238,7 +269,15 @@ in "mkdir -p $out\n" + concatStringsSep "\n" ( mapAttrsToList (n: v: - '' + let + mode = + if v.mode != null + then v.mode + else + if v.executable != null + then (if v.executable then "+x" else "-x") + else "+r"; # Acts as a no-op. + in '' target="$(realpath -m "$out/${v.target}")" # Target file must be within $HOME. @@ -251,7 +290,7 @@ in mkdir -p "$(dirname "$out/${v.target}")" ln -s "${v.source}" "$target" else - install -D -m${v.mode} "${v.source}" "$target" + install -D -m${mode} "${v.source}" "$target" fi '' ) cfg diff --git a/modules/misc/news.nix b/modules/misc/news.nix index ac969f16..44b9d7f5 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -425,6 +425,23 @@ in A new window manager module is available: 'xsession.windowManager.i3'. ''; } + + { + time = "2017-11-06T13:23:17+00:00"; + condition = any (f: f.mode != null) (attrValues config.home.file); + message = '' + The + + home.file..mode + + option is now deprecated. Please use + + home.file..executable + + instead. The 'mode' option will be completely removed + December 6, 2017. + ''; + } ]; }; } diff --git a/modules/misc/xdg.nix b/modules/misc/xdg.nix index 8dcf1fba..7dd5f456 100644 --- a/modules/misc/xdg.nix +++ b/modules/misc/xdg.nix @@ -126,13 +126,7 @@ in }) { - home.file = - let - f = n: v: { - inherit (v) source target; - mode = if v.executable then "777" else "444"; - }; - in mapAttrsToList f cfg.configFile; + home.file = cfg.configFile; } ]; } diff --git a/modules/xsession.nix b/modules/xsession.nix index d51bb6b4..9f06e76b 100644 --- a/modules/xsession.nix +++ b/modules/xsession.nix @@ -105,7 +105,7 @@ in ''; home.file.".xsession" = { - mode = "555"; + executable = true; text = '' if [[ ! -v HM_XPROFILE_SOURCED ]]; then . ~/.xprofile