Skip to content

Commit

Permalink
substituteAll: validate arguments
Browse files Browse the repository at this point in the history
So no one can repeat my mistakes.
  • Loading branch information
K900 committed Oct 20, 2024
1 parent c46a2c3 commit 05624e4
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions pkgs/build-support/substitute/substitute-all.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{ stdenvNoCC }:

args:

{ lib, stdenvNoCC }:
# see the substituteAll in the nixpkgs documentation for usage and constraints
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)
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}.
''

0 comments on commit 05624e4

Please sign in to comment.