mirror of
https://github.com/nix-community/home-manager
synced 2024-11-10 07:04:17 +00:00
files: allow arbitrary paths as home file names
By sanitizing the home file name in the derivation name, the home file name is no longer exposed to the naming restrictions for nix store paths. For example, it is now possible to define home files with spaces in their names without providing a target or source attribute.
This commit is contained in:
parent
14083a0857
commit
676f5c4b31
1 changed files with 24 additions and 2 deletions
|
@ -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)
|
||||
);
|
||||
};
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue