-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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-setup: use set -u
#28057
stdenv-setup: use set -u
#28057
Conversation
@Ericson2314, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @dezgeg and @wkennington to be potential reviewers. |
pkgs/stdenv/generic/setup.sh
Outdated
@@ -1,4 +1,4 @@ | |||
set -e | |||
set -eux |
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.
Just did set -x
while debugging.
pkgs/stdenv/generic/setup.sh
Outdated
local hookName="$1" | ||
shift | ||
local var="$hookName" | ||
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi | ||
local -a "var=(\${$var[@]})" |
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.
Yes, this abomination actually works.
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 believe you can use
hooksRef="${hookName%Hook}Hooks[@]"
hooks=("${!hooksRef}")
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 did the trailing [@]
trick before, but set -u
doesn't like it. Bash is such a mess.
%Hook
is cool though; I'll definitely use that!
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.
It is surprising that bash is happy with option 1:
set -eu
hooksVar=abcHooks
hooksRef="${hooksVar}[@]"
p() {
# option 1
local -a hooks="(\"\${$hooksVar[@]}\")"
# option 2
hooks=("${!hooksRef+${!hooksRef}}")
echo "${#hooks[@]} item(s):"
for item in "${hooks[@]}"; do
printf ' %q\n' "$item"
done
}
# not empty
abcHooks=('a b' 'c d')
p
# empty item
abcHooks=('')
p
# empty array
abcHooks=()
p
# undefined
unset abcHooks
p
pkgs/stdenv/generic/setup.sh
Outdated
_eval "$hook" "$@" | ||
done | ||
|
||
eval "$oldOpts" |
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.
Want to be robust no matter who calls
set -u
set -u
52566b7
to
ab628e7
Compare
Ok after much wrestling, stdenv seems to be building sucessfully now on macOS and Linux. |
@@ -987,3 +1041,6 @@ runHook userHook | |||
|
|||
|
|||
dumpVars | |||
|
|||
# Disable nounset for nix-shell. | |||
set +u |
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.
We should probably make nix-shell
do this, like it does for set -e
.
Sorry if this observation is not well informed, but why are |
@orivej I try to do that. The worst offender is because |
@orivej BTW, I'd love to get rid of the redundancy between |
ab563c4
to
9fc7726
Compare
@globin Good to go now |
Not a fan. All this |
Older bash version, like those in the bootstrap tools and on macOS, currently confuse variables defined as an empty array with undefined variables. `${foo+"${foo[@]}"}` will prevent `set -u` problems with empty arrays and older without making a single '' in the empty case. Care is taken to `set +u` when running hooks so as to not break existing packages.
8148360
to
81194ee
Compare
Rebased an rebuilt. I'm trying to clean up cc-wrapper's |
See https://github.com/NixOS/nixpkgs/projects/8 for all my PRs that (directly or indirectly) depend on this. To unblock those, I hope we can merge this, and merge it soon. |
OK I'm merging this now. I just need this to have a reasonable debugging environment to finish https://github.com/NixOS/nixpkgs/projects/8. After that project, if anyone insists this is change bad, I will personally revert. (It won't commute with other changes, so it's a somewhat less trivial revert I'm promising). |
N.B. Checked each failure in https://hydra.mayflower.de/jobset/mayflower/hydra-jobs-production and confirmed it was unrelated. |
Like, WTF is this new apparent "policy" that feedback from others in multiple pull requests can just be ignored just on the basis on "I am in a hurry" or "I need this"? We are using git after all.... |
Environment variable filter in substituteAll was not precise and produced undefined and invalid variable names. Vladimír Čunát tried to fix that in [1], but `env -0` did not work during Darwin bootstrap, so [2] reverted this change and replaced an error due to invalid variables with a warning. Recently in NixOS#28057 John Ericson added `set -u` to `setup.sh` and undefined variables made the setup fail during e.g. `nix-build -A gnat` with `setup: line 519: !varName: unbound variable`. [1] NixOS@62fc885 [2] NixOS@81df035
Environment variable filter in substituteAll was not precise and produced undefined and invalid variable names. Vladimír Čunát tried to fix that in [1], but `env -0` did not work during Darwin bootstrap, so [2] reverted this change and replaced an error due to invalid variables with a warning. Recently in #28057 John Ericson added `set -u` to `setup.sh` and undefined variables made the setup fail during e.g. `nix-build -A gnat` with `setup: line 519: !varName: unbound variable`. [1] 62fc885 [2] 81df035 (cherry picked from commit a09d9e7)
I am no longer trying to squeeze my cross work into 17.03, so there is no rush. I will continue to need this for cross work on master for 18.03, but I did merge it over other's objections. If someone wants to revert it until there is more consensus, I cannot complain. |
Motivation for this change
For my cross work, I need to make some fairly in-depth changes to stdenv's setup. This, and other development, is var easier with
set -u
as a debugging aid.Care is taken to
set +u
when running hooks so as to not break existing packages. Eventually, we might try to useset -u
everywhere but that is a far larger project.Things done
Please check what applies. Note that these are not hard requirements but merely serve as information for reviewers.
(nix.useSandbox on NixOS,
or option
build-use-sandbox
innix.conf
on non-NixOS)
nix-shell
still works on macOSnix-shell -p nox --run "nox-review wip"
./result/bin/
)CC @orivej