substituteAll: validate arguments

So no one can repeat my mistakes.
This commit is contained in:
K900 2024-10-20 18:31:12 +03:00
parent c46a2c35ab
commit 05624e48e2

View File

@ -1,8 +1,12 @@
{ stdenvNoCC }: { lib, stdenvNoCC }:
args:
# see the substituteAll in the nixpkgs documentation for usage and constraints # see the substituteAll in the nixpkgs documentation for usage and constraints
args:
let
# keep this in sync with substituteAll
isInvalidArgName = x: builtins.match "^[a-z][a-zA-Z0-9_]*$" x == null;
invalidArgs = builtins.filter isInvalidArgName (builtins.attrNames args);
in
if invalidArgs == [] then
stdenvNoCC.mkDerivation ({ stdenvNoCC.mkDerivation ({
name = if args ? name then args.name else baseNameOf (toString args.src); name = if args ? name then args.name else baseNameOf (toString args.src);
builder = ./substitute-all.sh; builder = ./substitute-all.sh;
@ -10,3 +14,9 @@ stdenvNoCC.mkDerivation ({
preferLocalBuild = true; preferLocalBuild = true;
allowSubstitutes = false; allowSubstitutes = false;
} // args) } // args)
else throw ''
Argument names for `pkgs.substituteAll` must:
- start with a lower case ASCII letter
- only contain ASCII letters, digits and underscores
Found invalid argument names: ${lib.concatStringsSep ", " invalidArgs}.
''