Skip to content

Instantly share code, notes, and snippets.

@3noch
Created July 2, 2020 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3noch/e5cfa3556507680294c5c3907fd6e98f to your computer and use it in GitHub Desktop.
Save 3noch/e5cfa3556507680294c5c3907fd6e98f to your computer and use it in GitHub Desktop.
Make a string into a valid Nix derivation name
{ 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