Skip to content

Instantly share code, notes, and snippets.

@rycee
Created September 9, 2017 14:53
Show Gist options
  • Save rycee/15a82c0516670e480bf95b174f8e8bee to your computer and use it in GitHub Desktop.
Save rycee/15a82c0516670e480bf95b174f8e8bee to your computer and use it in GitHub Desktop.
diff --git a/modules/home-environment.nix b/modules/home-environment.nix
index 212e1c6..4f52b5a 100644
--- a/modules/home-environment.nix
+++ b/modules/home-environment.nix
@@ -92,6 +92,8 @@ let
homeFilePattern = "-home-manager-files/";
+ safeBaseNameOf = f: replaceStrings [ " " ] [ "_" ] (baseNameOf f);
+
in
{
@@ -126,6 +128,15 @@ in
'';
};
+ mode = mkOption {
+ type = types.nullOr types.str;
+ default = null;
+ description = ''
+ The permissions to apply to the file.
+ DEPRECATED: use <varname>executable</varname> instead.
+ '';
+ };
+
executable = mkOption {
type = types.bool;
default = false;
@@ -137,7 +148,7 @@ in
target = mkDefault name;
source = mkIf (config.text != null)
(mkDefault (pkgs.writeTextFile {
- name = "home-file";
+ name = "home-file-" + safeBaseNameOf config.target;
text = config.text;
executable = config.executable;
}));
@@ -229,6 +240,20 @@ in
assertion = badFiles == [];
message = "Source file names must not start with '.': ${badFilesStr}";
})
+
+ (let
+ badFiles =
+ map (f: baseNameOf (toString f.source))
+ (filter (f: f.mode != null)
+ (attrValues cfg.file));
+ badFilesStr = toString badFiles;
+ in
+ {
+ assertion = badFiles == [];
+ message =
+ "The 'mode' field is deprecated for 'home.file', "
+ + "use 'executable' instead: ${badFilesStr}";
+ })
];
home.sessionVariables =
@@ -410,40 +435,38 @@ in
home-files = pkgs.stdenv.mkDerivation {
name = "home-manager-files";
- buildCommand =
# Symlink directories, hardlink files that have the right execute bit
# and copy files that need their execute bit changed.
- ''
- mkdir -p $out
-
- function insertFile() {
- local src=$1
- local dest="$2"
- local executable=$3
-
- mkdir -p "$(dirname "$dest")"
- if [[ -d $src ]]; then
+ buildCommand = ''
+ mkdir -p $out
+
+ function insertFile() {
+ local src=$1
+ local dest="$2"
+ local executable=$3
+
+ mkdir -p "$(dirname "$dest")"
+ if [[ -d $src ]]; then
+ ln -s $src "$dest"
+ else
+ [[ -x $src ]] && isExecutable=1 || isExecutable=""
+ if [[ $isExecutable == $executable ]]; then
ln -s $src "$dest"
else
- [[ -x $src ]] && isExecutable=1 || isExecutable=""
- if [[ $isExecutable == $executable ]]; then
- ln $src "$dest"
+ cp $src "$dest"
+ if [[ $executable ]]; then
+ chmod +x "$dest"
else
- cp $src "$dest"
- if [[ $executable ]]; then
- chmod +x "$dest"
- else
- chmod -x "$dest"
- fi
+ chmod -x "$dest"
fi
fi
- }
- '' +
- concatStringsSep "\n" (
- mapAttrsToList (n: v:
- ''insertFile ${v.source} "$out/${v.target}" ${builtins.toString v.executable}''
- ) cfg.file
- );
+ fi
+ }
+ '' + concatStrings (
+ mapAttrsToList (n: v: ''
+ insertFile ${v.source} "$out/${v.target}" ${builtins.toString v.executable}
+ '') cfg.file
+ );
};
in
pkgs.stdenv.mkDerivation {
diff --git a/modules/misc/news.nix b/modules/misc/news.nix
index 3bb9ce8..130cf86 100644
--- a/modules/misc/news.nix
+++ b/modules/misc/news.nix
@@ -141,6 +141,25 @@ in
by commenting in https://git.io/v5BJL.
'';
}
+
+ {
+ time = "2017-09-08T22:08:27+00:00";
+ condition = any (f: f.mode != null) (attrValues config.home.file);
+ message = ''
+ To clean up and fix the semantics of installing files with
+ non-default permissions into the home directory, we
+ unfortunately had to immediately disable the use of the
+
+ home.file.<name?>.mode
+
+ field. This mode field will be removed completely in the
+ future. Please use
+
+ home.file.<name?>.executable
+
+ instead.
+ '';
+ }
];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment