-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
substituteAll
is a terrible function and we need to stop using it / fix it respectively
#237216
Comments
substituteAll
is a terrible function and we need to stop using itsubstituteAll
is a terrible function and we need to stop using it / fix it respectively
While the intent of the code was correct, the system string can not be used in the substituteAll function. See #237216
Much simpler than structured attrs is probably just prefixing the env vars or dumping the argument to |
The `substituteAll` bash function that was previously used substitutes all environment variables. This can cause surprising behaviour, because some environment variables, like `system`, and not under control of the expression author that calls `substituteAll`. This commit changes the nixpkgs `substituteAll` function to use `substitute` with an explicit variable list instead. This ensures that the only variables that will be substituted are those that the caller specified, and not any that stdenv.mkDerivation or Nix itself added/modified. Partially addresses NixOS#237216.
This should be still a Bash program? |
I think it's pure bash because that makes it easy to use as part of bootstrapping.
Or we could use command line arguments. I don't think the limitations of the process env+args memory space apply here because it's pure bash without any |
Also not immediately obvious is the fact that the When the bash |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/string-interpolation-in-files-without-substituteall/38779/1 |
For generating build scripts, we could have a function that produces a At that point I think we have all the conveniences and all that remains is remove usages of the bad flags, and perhaps deprecate them. |
Elephant in the room: |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/shellcheck-inline-scripts-during-test-phase/16274/7 |
This comment was marked as duplicate.
This comment was marked as duplicate.
Any updates? Hit this today while trying to replace something containing a slash. (example: Maybe we can replace substituteV2 = {src, ...} @ args: let
args' = builtins.removeAttrs args ["src"];
in
pkgs.substitute {
inherit src;
substitutions = lib.flatten (lib.mapAttrsToList (n: v: ["--subst-var-by" n v]) args');
}; |
Now that the PR above has landed, my plan is to send out a bunch of PRs for simple uses of |
@wolfgangwalther has taken up the torch and is driving the refactor tractor around Nixpkgs, delivering a set of wonderful gifts. |
Driving NixOS#237216 forward.
Driving NixOS#237216 forward.
Issue description
substituteAll
is a bash function and a Nix function inpkgs
.The bash function is bad because
mkDerivation
arguments, in which case it is not clear that any relation exists between the definition and the usage.--subst-var
complaint as wellThe Nix function is even worse. Nix has semi-structured data, so the expectations are a bit higher. Variables passed to the
pkgs.substituteAll
functions all get substituted into the file, right? ... WRONG! Those variables are poured carelessly intomkDerivation
, which assigns special meaning to them, and even ignores and replaces some, likesystem
.Steps to reproduce
hostPlatform.system
innixos-generate-config
#228133 (comment)Technical details
substituteAll
would be useful if it wasn't such a hack. Maybe something could be achieved with structuredAttrs, so that the variables aren't taken from the environment, but from a separate, safe, json file.There's also this. Not sure if I want to know more about the horrors inside.
The text was updated successfully, but these errors were encountered: