Commit b9e5637a authored by Artturin's avatar Artturin
Browse files

config.replaceCrossStdenv: add

Example with `clangUseLLVM` which is the default when using `useLLVM`

```nix
config.replaceCrossStdenv = { buildPackages, baseStdenv }:
  if baseStdenv.targetPlatform.useLLVM or false
  then (buildPackages.stdenvAdapters.overrideCC baseStdenv buildPackages.llvmPackages_16.clangUseLLVM)
  else baseStdenv;
```

The conditional necessary, otherwise the other sets(such as `pkgsCross.aarch64-multiplatform.llvmPackages`)
without `useLLVM` will use the stdenv without the necessary conditions to avoid infinite
recursion because of [targetLlvmLibraries](https://github.com/NixOS/nixpkgs/blob/644b234e1c17aad539c03ac8020f831e20241d50/pkgs/development/compilers/llvm/16/default.nix#L208)
usage.

[`replaceStdenv` is not used when cross-compiling](https://github.com/NixOS/nixpkgs/blob/d77bda728d5041c1294a68fb25c79e2d161f62b9/pkgs/stdenv/cross/default.nix#L12-L13)

`replaceStdenv` uses an additional stage to replace the stdenv to avoid
infinite recursion and other issues but that should not be necessary for cross.
parent ba1a718f
Loading
Loading
Loading
Loading
+40 −37
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ let
    crossOverlays = [];

    # Ignore custom stdenvs when cross compiling for compatibility
    # Use replaceCrossStdenv instead.
    config = builtins.removeAttrs config [ "replaceStdenv" ];
  };

@@ -44,7 +45,8 @@ in lib.init bootStages ++ [
    inherit config;
    overlays = overlays ++ crossOverlays;
    selfBuild = false;
    stdenv = adaptStdenv (buildPackages.stdenv.override (old: rec {
    stdenv = let
      baseStdenv = adaptStdenv (buildPackages.stdenv.override (old: rec {
        buildPlatform = localSystem;
        hostPlatform = crossSystem;
        targetPlatform = crossSystem;
@@ -85,6 +87,7 @@ in lib.init bootStages ++ [
               buildPackages.updateAutotoolsGnuConfigScriptsHook
          ;
      }));
    in if config ? replaceCrossStdenv then config.replaceCrossStdenv { inherit buildPackages baseStdenv; } else baseStdenv;
  })

]