-
-
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
stdenv: run toString on lists in env to allow lists in env #217962
Conversation
will make appending to lists in env in overrideAttrs more ergonomic due to no longer needing to add spaces manually ``` nix-repl> keepassxc.NIX_CFLAGS_COMPILE "-Wno-old-style-cast -Wno-error -D__BIG_ENDIAN__=0" nix-repl> (keepassxc.overrideAttrs(oA: { passthru.oA = oA; })).oA.env.NIX_CFLAGS_COMPILE [ "-Wno-old-style-cast" "-Wno-error" "-D__BIG_ENDIAN__=0" ] nix-repl> (keepassxc.overrideAttrs(oA: { passthru.oA = oA; })).oA.NIX_CFLAGS_COMPILE error: … while evaluating the attribute 'oA.NIX_CFLAGS_COMPILE' at «string»:1:32: 1| (keepassxc.overrideAttrs(oA: { passthru.oA = oA; })).oA.NIX_CFLAGS_COMPILE | ^ error: attribute 'NIX_CFLAGS_COMPILE' missing at «string»:1:1: 1| (keepassxc.overrideAttrs(oA: { passthru.oA = oA; })).oA.NIX_CFLAGS_COMPILE | ^ ```
keepassxc> cc1: warning: command-line option '-Wno-old-style-cast' is valid for C++/ObjC++ but not for C declare -x NIX_CFLAGS_COMPILE="..."
one issue i can think of is that users may use the env list values outside of overrideAttrs so they will be strings, but in that case there will be a error so it shouldn't be a big issue |
after digging in #72074 found #72074 (comment)
|
I do still think this would be nice to have for ergonomics |
(I was asked to add a comment here after a discussion earlier today.) I don't exactly know if it is desirable or undesirable to handle lists in I think it is cumbersome as a public API to externalize building lists of things as strings. I do not think it is confusing for lists in My opinion is that we probably should follow those semantics here, as |
(n: v: assert lib.assertMsg (lib.isString v || lib.isBool v || lib.isInt v || lib.isDerivation v) | ||
"The ‘env’ attribute set can only contain derivation, string, boolean or integer attributes. The ‘${n}’ attribute is of type ${builtins.typeOf v}."; v) | ||
(n: v: assert lib.assertMsg (lib.isString v || lib.isBool v || lib.isInt v || lib.isDerivation v || lib.isList v) | ||
"The ‘env’ attribute set can only contain derivation, list, string, boolean or integer attributes. The ‘${n}’ attribute is of type ${builtins.typeOf v}."; (if lib.isList v then toString v else v)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think toString
is the right behavior.
IIUC, env
is treated as a normal string coercion, and not a toString
invocation. This affects the list item interpretation of paths:
nix-repl> "${./lib}"
"/nix/store/68rmyx4vrvghbkkqlhvb9kv63n761nvc-lib"
nix-repl> "${toString [./lib]}"
"/home/user/nixpkgs/lib"
I expect the same inconsistency to occur in env
(although tbh I didn't check). This is bad. Paths should always behave the same. Their default interpretation is as a vehicle for inserting sources into derivations, and I think we should stick to that. The eval-time location of the sources has nothing to do with the build.
Furthermore, in many, but not all cases, a separator would be expected to be inserted, usually :
. I don't think we should make any assumptions about this either. Explicit concatStringsSep
is good for reading and understanding, whereas implicit behavior is where we expose ourselves to silly bugs and overcomplicated compatibility behaviors. There's even a performance cost. mkDerivation
is basically our most low level function when it comes to packaging, so we better be careful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Furthermore, in many, but not all cases, a separator would be expected to be inserted
I think it would be fine, and maybe desirable, to resort to the basic derivation
bare attributes semantics, instead of making new ones here. My opinion is that moving things that should be in the environment and not bash variables should be limited to only moving the attribute from the bare derivation to the env
attrset. Any different behaviour would be a cause for surprises.
(everything else prior I have no issues with.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving something to env
is a manual action. We may as well use this opportunity to "ask" the author to make their intent explicit. A surprise is ok if it leads to a better outcome overall.
"The ‘env’ attribute set can only contain derivation, list, string, boolean or integer attributes. The ‘${n}’ attribute is of type ${builtins.typeOf v}."; (if lib.isList v then toString v else v)) | |
"The ‘env’ attribute set can only contain derivation, string, boolean or integer attributes. The ‘${n}’ attribute is of type ${builtins.typeOf v}.${optionalString (lib.isList v) " ‘env’ requires you to be explicit about how the list should be rendered. Use for example `lib.concatStringsSep \":\" (<your_value>)` and consider whether escaping is needed."}"; v) |
I've probably butchered the code with that suggestion, but you catch my drift. I chose :
because I think that's the most likely candidate in the general case. Moving something to env
seems a bit odd to me, whereas adding a :
-separated environment variable seems much more likely.
I find those arguments compelling.
I intend to enable structuredAttrs by default eventually.. and with that I am facing a huge number of attributes that potentially need to be moved to Looking at the example made in this PR and here:
... I can't help myself thinking that all those I conclude: We shouldn't do this, thus closing. Please re-open, if you disagree. |
will make appending to lists in env in overrideAttrs more ergonomic due
to no longer needing to add spaces manually
if merged revert most changes in #217206
Description of changes
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)