nixpkgs/pkgs/build-support/substitute/substitute-all.nix
K900 05624e48e2 substituteAll: validate arguments
So no one can repeat my mistakes.
2024-10-20 18:55:15 +03:00

23 lines
834 B
Nix

{ lib, stdenvNoCC }:
# 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 ({
name = if args ? name then args.name else baseNameOf (toString args.src);
builder = ./substitute-all.sh;
inherit (args) src;
preferLocalBuild = true;
allowSubstitutes = false;
} // 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}.
''