1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-24 09:50:58 +01:00

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`.
This commit is contained in:
Robert Helgesson 2019-01-16 02:14:14 +01:00
parent 46f787950a
commit 7c04351a57
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
12 changed files with 121 additions and 38 deletions

27
modules/lib/strings.nix Normal file
View file

@ -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;
}