Skip to content
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: concatTo: fallback for non-__structuredAttrs derivations #334973

Merged
merged 2 commits into from
Aug 18, 2024

Conversation

SomeoneSerge
Copy link
Contributor

@SomeoneSerge SomeoneSerge commented Aug 15, 2024

Description of changes

The first commit fixes sudo #318614 (comment), making it output a warning instead of failing (using log level "error", otherwise I couldn't see the warning without extra flags...):

./configure: interpreter directive changed from "#! /bin/sh" to "/nix/store/agkxax48k35wdmkhmmija2i2sxg8i7ny-bash-5.2p26/bin/sh"
concatTo(): configureFlagsArray is not declared as array, treating as a singleton. This will become an error in future

The second makes sudo a structuredAttrs derivation.

Not sure if I should target staging or staging-next

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

Comment on lines 403 to 411
if [[ "$name" = *"Array" ]]; then
nixErrorLog "concatTo(): $name is not declared as array, treating as a singleton. This will become an error in future"
targetref+=( "${nameref-}" )
else
# shellcheck disable=SC2206
targetref+=( ${nameref-} )
fi
;;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emilazy @tie ok to me this is super innocuous I mean what can go wrong testing string for a suffix, but tell me did I step on any of the bash landmines

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Bash looks fine to me. Is there any chance we could make the warning happen at evaluation time so it’s more visible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. I guess we could add a warning in mkDerivation, and that'd also make Ofborg light up all (ab)users in Nixpkgs. The fallback, if we choose to go with the fallback and we probably do because of out-of-tree users, is still easiest to implement in bash though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the fallback is good. We should probably even warn in Bash too, because you could set the wrong thing in bash code. But a mkDerivation warning would be nice if it’s not too invasive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be using ${arr[@]} notation for *Array variables.

Copy link
Member

@tie tie Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sudo had an issue because it set *Array variable as a derivation argument, so it got exported as a string and with ${var[@]} expansion strings are treated as single-element arrays.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance we could make the warning happen at evaluation time so it’s more visible?

Never touched check-meta.nix before, opening a separate PR targetting master for this discussion: #335110

I think this should be using ${arr[@]} notation for *Array variables.

Cannot think of a single case test case where this would produce a different result, but I recovered the original code (including the ${nameref+...} part) verbatim

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be using ${arr[@]} notation for *Array variables.

Cannot think of a single case test case where this would produce a different result, but I recovered the original code (including the ${nameref+...} part) verbatim

I don't think we should use [@] notation here - because we don't actually have an array here. That's the whole point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't reply before the merge, I was away. I agree to some extend, and I did start with treating the input as just a string. But then I do hope to remove this branch maybe after a release, and the intent of reintroducing this branch was to mimic exactly what the old implementation was doing so... I guess it's OK we merged it the way it was

Copy link
Member

@rhendric rhendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the sudo change has my 👍; I haven't been following what changes are happening with concatTo and have no opinion on that part of this.

@ofborg ofborg bot requested a review from rhendric August 16, 2024 15:36
# shellcheck disable=SC2206
targetref+=( ${nameref-} ) ;;
if [[ "$name" = *"Array" ]]; then
nixErrorLog "concatTo(): $name is not declared as array, treating as a singleton. This will become an error in future"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nixErrorLog "concatTo(): $name is not declared as array, treating as a singleton. This will become an error in future"
nixErrorLog "concatTo(): $name is not declared as array, treating as a singleton. This will become an error in future."

Also, should this use nixWarnLog, since it's not an error, yet?

Copy link
Contributor

@wolfgangwalther wolfgangwalther Aug 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, just read this:

making it output a warning instead of failing (using log level "error", otherwise I couldn't see the warning without extra flags...):

Hm.. nixErrorLog is not used anywhere in nixpkgs right now. Although.. none of the other log functions are used either, except for nixTalkativeLog and nixWarnLog directly inside generic/setup.sh.

This makes me wonder whether this is really the right "tool" to use?

With my arguments in #335110 (comment), maybe we should just silently apply the fallback here and do all the warnings / errors only on the nix-level?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is right, since nixErrorLog just spits something out on stderr. It might become structured logging in the future.

Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from the stdenv side.

# shellcheck disable=SC2206
targetref+=( ${nameref-} ) ;;
if [[ "$name" = *"Array" ]]; then
nixErrorLog "concatTo(): $name is not declared as array, treating as a singleton. This will become an error in future"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is right, since nixErrorLog just spits something out on stderr. It might become structured logging in the future.

@philiptaron philiptaron merged commit 4ef32bd into NixOS:staging Aug 18, 2024
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants