Change:
The Linux stdenv sets But that flag is specific to GNU strip, and LLVM's strip will fail if passed it. Conveniently, we silence all errors from stripping, so this has gone unnoticed until now: I noticed this while trying to fix . One of the reasons it doesn't work is that it has in , and strip should be removing that reference but isn't. What I'm not sure about here is the best way to fix this. There's nothing platform-specific about this option, so it shouldn't live in the Linux stdenv. (Other platforms like NetBSD use GNU binutils by default.) Ideally it would be a conditional in the strip setup hook, but we don't really have a bash equivalent to . So where (in Nix) should we check this and set the variable? cc
With what we have at the moment, I can only think of hacky workarounds like checking if ends in . However such an approach (and even checking ) is actually incorrect: and don't have to be matched, e. g. with as linker and GNU bintools is quite common actually. Looking at prior art in nixpkgs, I'm quite convinced that the cleanest solution for now would be to bite the bullet and extend to also wrap . In fact, we already seem to have a strip wrapper for darwin.
Hmm, I don't like the idea of globally adding a flag only to remove it again in a wrapper. Another idea I had was to do this in the definition of make- — the hardening flags are precedent for doing manipulation of environment variables for setup hooks in there. We could add an isGNU attribute to the possible values of , and use that? I don't much like this idea either, but I like it better than adding the flag globally and then wrapping to remove it. What do you think?
Since this flag is unconditionally in general, I think we can just remove it from the linux hook and instead add it in the binutils-wrapper. This should also solve the issue of this being binutils-specific and not linux-specific AIUI.
Oh, you mean wrap GNU binutils' strip to add this flag? That sounds fine to me.
If I understand correctly this is now done:

Discussion:
echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/libc-ldflags '' <ins> ## ## GNU specific extra strip flags ## # TODO(@sternenseemann): make a generic strip wrapper? + optionalString (bintools.isGNU or false) '' wrap ${targetPrefix}strip ${./gnu-binutils-strip-wrapper.sh}  "${bintools_bin}/bin/${targetPrefix}strip" '' </ins> ### ### Remove LC_UUID ###

<ins> #! @shell@ # shellcheck shell=bash exec @prog@ --enable-deterministic-archives "$@" </ins>

if [ -n "${dirs}" ]; then header "stripping (with command $cmd and flags $stripFlags) in$dirs" <del> find $dirs -type f -exec $cmd $commonStripFlags $stripFlags '{}' ; 2>/dev/null </del> <ins> find $dirs -type f -exec $cmd $stripFlags '{}' ; 2>/dev/null </ins> stopNest fi }

CPPFLAGS = concatStringsSep " " (map (p: "-I${getDev p}/include") buildInputs); LDFLAGS = concatStringsSep " " (map (p: "-L${getLib p}/lib") buildInputs); LIBS = "${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"; <del> NIX_LDFLAGS = optionalString (stdenv.isLinux && !stdenv.hostPlatform.isMusl) "-lgcc_s" + optionalString stdenv.hostPlatform.isMusl "-lgcc_eh"; </del> <ins> NIX_LDFLAGS = lib.optionalString stdenv.cc.isGNU ({ "glibc" = "-lgcc_s"; "musl" = "-lgcc_eh"; }."${stdenv.hostPlatform.libc}" or ""); </ins> # Determinism: We fix the hashes of str, bytes and datetime objects. PYTHONHASHSEED=0;

targetPlatform = localSystem; inherit config; <del> preHook = '' # Make "strip" produce deterministic output, by setting # timestamps etc. to a fixed value. commonStripFlags="--enable-deterministic-archives" ${commonPreHook} ''; </del> <ins> preHook = commonPreHook; </ins> initialPath = ((import ../common-path.nix) {pkgs = prevStage;});