Change:
making a pr fixing cross compilation for some things and found this
... and defaults to which is per shrug : /
Something that seems to fix the problem, weirdly, is to add to instead of , and use in I have no idea what's going on, need a cross-compilation guru ( ?).
is special: All packages in a package set are host→target (e.g. the normal attribute), however is derived from and re-exposed as the thing that builds this package set. This gives rise to the inconsistency that is one of the few attributes in the package set that's build→host. Putting into (where it conceptually belongs) will of course pick , since it itself comes from . To pick the default compiler we should use to build here, it should take by default where would then be the package set produced by which is the actual cross compiled set: . We need to jump through these hoops because, unfortunately the default compiler / libc etc. picking logic is only done as part of picking the 's from the previous package set.
Do you mean host→target here?
Yes, fixed.
Attempting a fix in
Thanks for reporting this Artturin! Verified the PR that was made and merged :)

Discussion:
{ stdenv <ins> , targetPackages </ins> , lib , makeSetupHook , dieHook , writeShellScript , tests <del> , cc ? stdenv.cc </del> <ins> , cc ? targetPackages.stdenv.cc </ins> , sanitizers ? [] }:

++ lib.optional (stdenv.isDarwin && stdenv.isAarch64) cc; substitutions = { <del> cc = "${cc}/bin/cc ${lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers)}"; </del> <ins> cc = "${cc}/bin/${cc.targetPrefix}cc ${lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers)}"; </ins> # Extract the function call used to create a binary wrapper from its embedded docstring passthru.extractCmd = writeShellScript "extract-binary-wrapper-cmd" ''

<ins> { stdenv , runCommand , makeBinaryWrapper , binutils , expectedArch ? stdenv.hostPlatform.parsed.cpu.name }: runCommand "make-binary-wrapper-test-cross" { nativeBuildInputs = [ makeBinaryWrapper binutils ]; inherit expectedArch; } '' touch prog chmod +x prog makeWrapper prog $out read -r _ arch < <($READELF --file-header $out | grep Machine:) if [[ ''${arch,,} != *"''${expectedArch,,}"* ]]; then echo "expected $expectedArch, got $arch" exit 1 fi '' </ins>

<del> { lib, coreutils, python3, gcc, writeText, writeScript, runCommand, makeBinaryWrapper }: </del> <ins> { lib , stdenv , pkgsCross , makeBinaryWrapper , writeText , runCommand , runCommandCC }: </ins> let <del> env = { buildInputs = [ makeBinaryWrapper ]; }; envCheck = runCommand "envcheck" env '' ${gcc}/bin/cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c} </del> <ins> env = { nativeBuildInputs = [ makeBinaryWrapper ]; }; envCheck = runCommandCC "envcheck" env '' cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c} </ins> ''; <del> makeGoldenTest = testname: runCommand "test-wrapper_${testname}" env '' mkdir -p ./tmp/foo </del> <ins> makeGoldenTest = testname: runCommand "make-binary-wrapper-test-${testname}" env '' mkdir -p tmp/foo # for the chdir test </ins> params=$(<"${./.}/${testname}.cmdline") eval "makeCWrapper /send/me/flags $params" > wrapper.c

cp wrapper.c $out ''; <del> tests = let names = [ "add-flags" "argv0" "basic" "chdir" "combination" "env" "inherit-argv0" "invalid-env" "prefix" "suffix" "overlength-strings" ]; f = name: lib.nameValuePair name (makeGoldenTest name); in builtins.listToAttrs (builtins.map f names); in writeText "make-binary-wrapper-test" '' ${lib.concatStringsSep "n" (lib.mapAttrsToList (_: test: '' "${test.name}" "${test}" '') tests)} </del> <ins> tests = lib.genAttrs [ "add-flags" "argv0" "basic" "chdir" "combination" "env" "inherit-argv0" "invalid-env" "overlength-strings" "prefix" "suffix" ] makeGoldenTest // lib.optionalAttrs (! stdenv.isDarwin) { cross = pkgsCross.aarch64-multiplatform.callPackage ./cross.nix { }; }; in writeText "make-binary-wrapper-tests" '' ${lib.concatStringsSep "n" (builtins.attrValues tests)} </ins> '' // tests