diff --git a/modules/files.nix b/modules/files.nix index e294f97f0..71b940d20 100644 --- a/modules/files.nix +++ b/modules/files.nix @@ -6,8 +6,31 @@ with import ./lib/dag.nix { inherit lib; }; let cfg = config.home.file; + homeDirectory = config.home.homeDirectory; + # Figures out a valid Nix store name for the given path. + storeFileName = path: + let + # All characters that are considered safe. Note "-" is not + # included to avoid "-" followed by digit being interpreted as a + # version. + safeChars = + [ "+" "." "_" "?" "=" ] + ++ lowerChars + ++ upperChars + ++ stringToCharacters "0123456789"; + + empties = l: genList (x: "") (length l); + + unsafeInName = stringToCharacters ( + replaceStrings safeChars (empties safeChars) path + ); + + safeName = replaceStrings unsafeInName (empties unsafeInName) path; + in + "home_file_" + safeName; + in { @@ -53,8 +76,7 @@ in config = { target = mkDefault name; source = mkIf (config.text != null) ( - let name' = "user-etc-" + baseNameOf name; - in mkDefault (pkgs.writeText name' config.text) + mkDefault (pkgs.writeText (storeFileName name) config.text) ); }; })