Created
July 2, 2020 15:33
-
-
Save 3noch/e5cfa3556507680294c5c3907fd6e98f to your computer and use it in GitHub Desktop.
Make a string into a valid Nix derivation name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ lib }: rec { | |
isValidDrvNameChar = c: "a" <= c && c <= "z" || "A" <= c && c <= "Z" || "0" <= c && c <= "9" || c == "+" || c == "-" || c == "_" || c == "?" || c == "=" || c == "."; | |
makeValidDrvName = { str, replacement ? "?" }: | |
let | |
newName = lib.stringAsChars (c: if isValidDrvNameChar c then c else replacement) str; | |
in if builtins.substring 0 1 newName == "." then "_" + newName else newName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment