mirror of
https://github.com/nix-community/home-manager
synced 2024-11-27 13:39:46 +01:00
7c04351a57
In particular support source files whose name start with `.` or contain characters not allowed in the nix store, such as spaces. Also add some test cases for `home.file`.
27 lines
671 B
Nix
27 lines
671 B
Nix
{ lib }:
|
|
|
|
with lib;
|
|
|
|
{
|
|
# 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
|
|
"hm_" + safeName;
|
|
}
|