cc-wrapper: Hygiene and set -u#27672
Conversation
|
@Ericson2314 If I'm reading this correctly, won't this cause problems where we use e.g. Your |
|
@cstrahan Indeed that is exactly the flaw I'm worried about. I'm not sure what to do about that, considering the order of flags does matter. |
LnL7
left a comment
There was a problem hiding this comment.
I'm probably missing something. But wouldn't the issues with setting NIX_*FLAGS during a build be solved by having the wrappers look at both the salted and unsalted versions of the environment variables?
|
@LnL7 Just saw. Well non-
|
970c819 to
52f2f3a
Compare
set -u for CC-wrapper
set -u for CC-wrapperset -u for CC-wrapper
|
OK! Rewrote this sort of as described. Probably best to review commit-by-commit as some commits are noisy but borring. |
There was a problem hiding this comment.
Ah it used to say $hardeningDisabled or whatever
set -u for CC-wrapperset -u
set -uset -u
grahamc
left a comment
There was a problem hiding this comment.
Nicely palindromic PR #
Generally looks fine, but I admit to not being really familiar with stdenv and the various things we do with it.
There was a problem hiding this comment.
can you add some more info to this comment as to what it means, for future archeologists?
There was a problem hiding this comment.
hmm you sure?
[grahamc@Morbo:~]$ declare -i n=0
[grahamc@Morbo:~]$ i+=1
[grahamc@Morbo:~]$ echo $i
1
[grahamc@Morbo:~]$ i+=1
[grahamc@Morbo:~]$ echo $i
11
There was a problem hiding this comment.
Hmm not sure why we're keeping this
There was a problem hiding this comment.
I don't know anything about gnat --- I'd figure I'd at least keep the comment up to date?
90be90b to
8c8f87f
Compare
This is an ugly temp hack for cross compilation, but now we have something better on the way. Bind `infixSalt` as an environment variable as it will be used in it.
This is basically a sed job, in preparation of the next commit. The rules are more or less: - s"NIX_(.._WRAPPER_)?([a-zA-Z0-9@]*)"NIX_\1@infixSalt@_\2"g - except for non-cc-wrapper-specific vars like `NIX_DEBUG`
See the added comments for what exactly has been done.
Now is an opportune time to do this, as the infixSalt conversion in `add-flags.sh` ensures that all the relevant `NIX_*` vars will be defined even if empty.
8c8f87f to
2493454
Compare
|
Rebased just to get rid of merge conflict with my macOS Sierra linking hack---just a nix conflict no hashes were affected so my old builds are still valid. |
|
This broke postgresql https://hydra.nixos.org/build/58192157. |
|
Postgresql |
|
Very weird---https://github.com/NixOS/nixpkgs/pull/27672/files#diff-ae6d7fc8f1059168bd391972ef177c31R70 should do the trick. When developing this, a lack of respecting that up caused the Linux stdenv to fail to build at all, so the current issue must be especially subtle. Also, I'm fine reverting this, especially as the next cross PR won't be ready for a while. |
|
Some fragments from That reminds me of #27940 where |
|
@Ericson2314 if you don't think you will be able to fix this before the next staging evaluation, then I recommend reverting these changes. |
|
@FRidh Found it. The problem is very silly; I slurped (For cross I'll eventually need to have a different monoid for these numeric env vars, but for native it suffices to just stop slurping twice.) |
|
Fixed in 810fb0c |
|
@Ericson2314 It seems that this pull request broke standalone |
|
Ah, that's unfortunate. It's because in the case that no "role" is defined, none of those variables get set. We should come up with some sane defaults for that case (all empty would probably be backwards compatible). @globin With the LLVM test failure you found, it's possible the environment has been cleaned somehow, leading to the roles being undefined. |
|
It appears that LLVM tests sanitize the environment for programs they run during the test. ( where |
|
Um, why is this |
|
I tried to describe it in the code comment: then we can't get away with |
|
Sure, the names of the wrapped tools being after the platform triplet is fine, I just don't understand the need for the |
|
@dezgeg We could use a hash of I'm open to doing that or similar, though. What would you prefer? |
This is needed now after #27672.
| fi | ||
| # Easiest to just do this to deal with either the input or (old) output. | ||
| set +u | ||
| export ${outputVar}+="${delimiter}${!inputVar}" |
There was a problem hiding this comment.
This appears to be setting the variables unconditionally, which broke #6688 (standalone clang++). I'm not sure what the exact interactions here are but nix run nixpkgs.clang can't find the C++ standard library headers and I've tracked it down to this variable assignment.
There was a problem hiding this comment.
Probably the right fix is to use ${NIX_CXXSTDLIB_COMPILE:-@default_cxx_stdlib_compile@} instead of ${NIX_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}, in cc-wrapper.sh to treat the empty variable the same way as if it was uninitialized, IIRC.
EDIT: opened as #44221.

Motivation for this change
For cross compilation, we need to have multiple cc-wrappers in use at once (usually so we can generate built-tools on the fly along with building the derivation itself). But cc-wrapper leaks a bunch of environment variables in its setup hook to be picked up by the wrapper scripts, so multiple cc-wrappers would stomp all over each other. The hack solution to that alone is simple---make sure the two cc-wrapper don't use the same identifiers, which
${infixSalt}accomplishes.The catch is that many derivations try to mess with this process by modifying those variables. I specially modified the setup hook to pick up "unsalted" environment variables from derivation itself (or an earlier setup hook...yikes), but derivations (like glibc; see the last commit) also inject bash to modify these too.
git grep 'export NIX_'can give one a scale of this.I do not yet have a general solution for how not to break these packages......Now I do. I do the conversion in add-flags instead. Also, normal host-platform-targetting env vars keep their existing notation, so this (at least by the standards of my recent PRs :D) is highly backwards compatible. The only semantics change I remember off-hand is that the
START_HOOKs are now evaluated afteradd-flags.sh, but those are probably dead code---unused in nixpkgs at least.This is best reviewed commit-by-commit, as some commits are basically seddish and bump up the diff count. Also start with #27879
[Longer term, instead of an unconditional
envHook, I'd like to use pkg-config. By default, cc-wrapper will inject the appropriatepkg-configinvocations, but this can be disabled per-derivation. Derivations likeglibcthat want to be tricky instead call it or do a deferred injection themselves.]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-sandboxinnix.confon non-NixOS)
nix-shell -p nox --run "nox-review wip"./result/bin/)CC @orivej, as you have been working on this a fair amount lately.