diff options
author | Robert Helgesson <robert@rycee.net> | 2019-01-16 02:14:14 +0100 |
---|---|---|
committer | Robert Helgesson <robert@rycee.net> | 2019-01-19 12:44:58 +0100 |
commit | 7c04351a57bb36133e6cf3b609e573b9e18b8eec (patch) | |
tree | d13a92128c443860acf79ba99dbe15b2ad9b21bb /modules/lib/strings.nix | |
parent | 46f787950ab7cd76e02a0e15af12756321f926c9 (diff) |
files: allow a wider range of source file names
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`.
Diffstat (limited to 'modules/lib/strings.nix')
-rw-r--r-- | modules/lib/strings.nix | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/lib/strings.nix b/modules/lib/strings.nix new file mode 100644 index 00000000000..13d6bb03be6 --- /dev/null +++ b/modules/lib/strings.nix @@ -0,0 +1,27 @@ +{ 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; +} |