home-manager/modules/lib/strings.nix

23 lines
633 B
Nix
Raw Normal View History

{ 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.
2020-02-01 23:39:17 +00:00
safeChars = [ "+" "." "_" "?" "=" ] ++ lowerChars ++ upperChars
++ stringToCharacters "0123456789";
empties = l: genList (x: "") (length l);
2020-02-01 23:39:17 +00:00
unsafeInName =
stringToCharacters (replaceStrings safeChars (empties safeChars) path);
safeName = replaceStrings unsafeInName (empties unsafeInName) path;
2020-02-01 23:39:17 +00:00
in "hm_" + safeName;
}