Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/release-notes/rl-2511.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
and newer series. However, embedded chips without LSX (Loongson SIMD eXtension), such as 2K0300 SoC, are not
supported. `pkgsCross.loongarch64-linux-embedded` can be used to build software and systems for these platforms.

- Added `cc` as a path towards providing a C compiler without inheriting it inside the standard environment.
Packages which wish to pick a compiler can explicitly do it or utilize the new `ccChooser`.

## Backward Incompatibilities {#sec-nixpkgs-release-25.11-incompatibilities}

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/ma/makeBinaryWrapper/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
dieHook,
writeShellScript,
tests,
cc ? targetPackages.stdenv.cc,
cc,
sanitizers ? [ ],
}:

Expand Down
25 changes: 1 addition & 24 deletions pkgs/stdenv/cross/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,7 @@ lib.init bootStages

hasCC = !stdenvNoCC.targetPlatform.isGhcjs;

cc =
if crossSystem.useiOSPrebuilt or false then
buildPackages.darwin.iosSdkPkgs.clang
else if crossSystem.useAndroidPrebuilt or false then
buildPackages."androidndkPkgs_${crossSystem.androidNdkVersion}".clang
else if
targetPlatform.isGhcjs
# Need to use `throw` so tryEval for splicing works, ugh. Using
# `null` or skipping the attribute would cause an eval failure
# `tryEval` wouldn't catch, wrecking accessing previous stages
# when there is a C compiler and everything should be fine.
then
throw "no C compiler provided for this platform"
else if crossSystem.isDarwin then
buildPackages.llvmPackages.libcxxClang
else if crossSystem.useLLVM or false then
buildPackages.llvmPackages.clang
else if crossSystem.useZig or false then
buildPackages.zig.cc
else if crossSystem.useArocc or false then
buildPackages.arocc
else
buildPackages.gcc;

cc = buildPackages.ccChooser crossSystem buildPackages null;
};
in
if config ? replaceCrossStdenv then
Expand Down
17 changes: 17 additions & 0 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check
overrides = self: super: {
inherit (prevStage) ccWrapperStdenv cctools ld64;

# TODO: change this when CC is no longer provided by the stdenv
inherit (self.stdenv) cc;

binutils-unwrapped = builtins.throw "nothing in the Darwin bootstrap should depend on GNU binutils";
curl = builtins.throw "nothing in the Darwin bootstrap can depend on curl";

Expand Down Expand Up @@ -735,6 +738,9 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check
{
inherit (prevStage) ccWrapperStdenv;

# TODO: change this when CC is no longer provided by the stdenv
inherit (self.stdenv) cc;

# Disable ld64’s install check phase because the required LTO libraries are not built yet.
ld64 = super.ld64.overrideAttrs { doInstallCheck = false; };

Expand Down Expand Up @@ -800,6 +806,9 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check
{
inherit (prevStage) ccWrapperStdenv;

# TODO: change this when CC is no longer provided by the stdenv
inherit (self.stdenv) cc;

# Avoid an infinite recursion due to the SDK’s including ncurses, which depends on bash in its `dev` output.
bashNonInteractive = super.bashNonInteractive.override { stdenv = self.darwin.bootstrapStdenv; };

Expand Down Expand Up @@ -884,6 +893,9 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check
{
inherit (prevStage) ccWrapperStdenv;

# TODO: change this when CC is no longer provided by the stdenv
inherit (self.stdenv) cc;

# Disable tests because they use dejagnu, which fails to run.
libffi = super.libffi.override { doCheck = false; };

Expand Down Expand Up @@ -965,6 +977,9 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check
{
inherit (prevStage) ccWrapperStdenv;

# TODO: change this when CC is no longer provided by the stdenv
inherit (self.stdenv) cc;

# Rebuild locales and sigtool with the new clang.
darwin = super.darwin.overrideScope (
_: superDarwin:
Expand Down Expand Up @@ -1204,6 +1219,8 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check
patch
;

inherit cc;

"apple-sdk_${sdkMajorVersion}" = self.apple-sdk;

darwin = super.darwin.overrideScope (
Expand Down
38 changes: 38 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8197,6 +8197,44 @@ with pkgs;
null;

# We can choose:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment looks potentially incomplete? Or at least I don't understand what it is trying to convey beyond the rest of the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not incomplete, copies what libcCrossChooser says:

# We can choose:
libcCrossChooser =
name:

ccChooser =
platform: pkgs: fallback:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to make this more self-explanatory.

Suggested change
platform: pkgs: fallback:
targetPlatform: hostPkgs: fallback:
  • pkgs.ccChooser (pkgs.stdenv.targetPlatform) pkgs null (where pkgs is what the returned CC targets)

or

Suggested change
platform: pkgs: fallback:
hostPlatform: buildPkgs: fallback:
  • pkgs.ccChooser (pkgs.stdenv.hostPlatform) pkgs.buildPackages null (where pkgs is what the returned CC will be running on)

Copy link
Member

@axelkar axelkar Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is all-packages.nix really the place for this? Could there be a "Nixpkgs-specific lib"? This function doesn't reference outside variables but takes in pkgs so it's not really a fit for lib.

Or don't take pkgs as a parameter and do what libcCrossChooser does by referencing the with pkgs; at the top of the file.

libcCrossChooser could be simpler, here's how I picture it:

  • Currently: hello to buildPackages.clang to buildPackages.libcCross to buildPackages.targetPackages.bionic to buildPackages.targetPackages.stdenvNoCC
  • What it could be: hello to buildPackages.clang to buildPackages.targetPackages.libc to buildPackages.targetPackages.bionic to buildPackages.targetPackages.stdenvNoCC

Can someone explain this?

Edit: I was looking at a two-month old Nixpkgs clone.. But asking on the stdenv team's Matrix channel.

let
# TODO: use cc when https://github.com/NixOS/nixpkgs/pull/365057 is merged
inherit (platform) useLLVM isDarwin isGhcjs;
useArocc = platform.useArocc or false;
useZig = platform.useZig or false;
useiOSPrebuilt = platform.useiOSPrebuilt or false;
useAndroidPrebuilt = platform.useAndroidPrebuilt or false;
in
if useiOSPrebuilt then
pkgs.darwin.iosSdkPkgs.clang or fallback
else if useAndroidPrebuilt then
pkgs."androidndkPkgs_${platform.androidNdkVersion}".clang or fallback
else if isGhcjs then
# Need to use `throw` so tryEval for splicing works, ugh. Using
# `null` or skipping the attribute would cause an eval failure
# `tryEval` wouldn't catch, wrecking accessing previous stages
# when there is a C compiler and everything should be fine.
# NOTE: maybe we remove this and return null instead?
throw "no C compiler provided for this platform"
else if isDarwin then
pkgs.llvmPackages.libcxxClang or fallback
else if useArocc then
pkgs.arocc or fallback
else if useZig then
pkgs.zig.cc or fallback
else if useLLVM then
pkgs.llvmPackages.clang or fallback
else
# NOTE: we shouldn't imply GCC, ideally we should either fallback, null, or error.
pkgs.gcc or fallback;

# The default C compiler to use, this has been provided by the stdenv for a long time.
# However, we're working to move it out of the stdenv. It is recommended to switch to
# this attribute and using an "stdenvNoCC" as soon as possible.
cc = ccChooser stdenv.targetPlatform pkgs null;

libc =
let
inherit (stdenv.hostPlatform) libc;
Expand Down
2 changes: 2 additions & 0 deletions pkgs/top-level/release-cross.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ let
buildPackages.binutils = nativePlatforms;
buildPackages.gcc = nativePlatforms;
libc = nativePlatforms;
cc = nativePlatforms;
};

common = {
buildPackages.binutils = nativePlatforms;
gmp = nativePlatforms;
libc = nativePlatforms;
cc = nativePlatforms;
nix = nativePlatforms;
nixVersions.git = nativePlatforms;
mesa = nativePlatforms;
Expand Down