2019-01-16 02:14:14 +01:00
|
|
|
{ lib }:
|
|
|
|
|
2021-10-27 13:58:56 +02:00
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
genList length lowerChars replaceStrings stringToCharacters upperChars;
|
|
|
|
in {
|
2019-01-16 02:14:14 +01:00
|
|
|
# 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.
|
2020-02-02 00:39:17 +01:00
|
|
|
safeChars = [ "+" "." "_" "?" "=" ] ++ lowerChars ++ upperChars
|
2019-01-16 02:14:14 +01:00
|
|
|
++ stringToCharacters "0123456789";
|
|
|
|
|
|
|
|
empties = l: genList (x: "") (length l);
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
unsafeInName =
|
|
|
|
stringToCharacters (replaceStrings safeChars (empties safeChars) path);
|
2019-01-16 02:14:14 +01:00
|
|
|
|
|
|
|
safeName = replaceStrings unsafeInName (empties unsafeInName) path;
|
2020-02-02 00:39:17 +01:00
|
|
|
in "hm_" + safeName;
|
2019-01-16 02:14:14 +01:00
|
|
|
}
|