From d6d58a85e1bf786da503abab9c7a0e5f5c50f982 Mon Sep 17 00:00:00 2001 From: Aliaksandr Date: Fri, 24 Apr 2026 20:19:39 +0300 Subject: [PATCH 1/8] make-derivation: remove no longer valid comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The comment claimed configureFlags is "sometimes a string, sometimes null, and sometimes a list" — the normalization it referenced was removed long ago; configureFlags is always a list now. --- pkgs/stdenv/generic/make-derivation.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index e1680f07cfa4..0f3bc38352ab 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -702,7 +702,6 @@ let propagatedBuildInputs = propagatedHostTargetOutputs; depsTargetTargetPropagated = propagatedTargetTargetOutputs; - # This parameter is sometimes a string, sometimes null, and sometimes a list, yuck configureFlags = configureFlags ++ ( From 20b7f2410bd1ee9bc1f654262da601985f623567 Mon Sep 17 00:00:00 2001 From: Aliaksandr Date: Sun, 5 Apr 2026 02:51:03 +0300 Subject: [PATCH 2/8] lib/customisation: reduce // merges in extendDerivation Fold the 'all' attribute into the listToAttrs call alongside the outputs, so commonAttrs builds from drv // listToAttrs(...) // passthru // { drvPath; outPath; } instead of four separate merges with a standalone 'all' attrset. Also convert remaining optionalAttrs to nullable attr names in extendDerivation, overrideDerivation, and makeOverridable. Per-derivation // merges drop from 4 to 3. --- lib/customisation.nix | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index e9e88aff7cb5..5db9275aadc7 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -401,7 +401,25 @@ rec { condition: passthru: drv: let commonAttrs = - drv // (listToAttrs outputsList) // { all = map (x: x.value) outputsList; } // passthru; + drv + // listToAttrs ( + outputsList + ++ [ + { + name = "all"; + value = map (x: x.value) outputsList; + } + ] + ) + // passthru + // { + drvPath = + assert condition; + drv.drvPath; + outPath = + assert condition; + drv.outPath; + }; outputsList = map (outputName: { name = outputName; @@ -423,15 +441,7 @@ rec { }; }) (drv.outputs or [ "out" ]); in - commonAttrs - // { - drvPath = - assert condition; - drv.drvPath; - outPath = - assert condition; - drv.outPath; - }; + commonAttrs; /** Strip a derivation of all non-essential attributes, returning From a42becdd920c50b0d0d4169f3510c9c49f6d8998 Mon Sep 17 00:00:00 2001 From: Aliaksandr Date: Sun, 5 Apr 2026 02:51:12 +0300 Subject: [PATCH 3/8] stdenv/generic: replace // optionalAttrs with nullable attr names Convert 3 optionalAttrs in the stdenv derivation call to nullable attribute names: allowedRequisites, contentAddressedByDefault, and isDarwin sandbox/impureHostDeps. --- pkgs/stdenv/generic/default.nix | 111 +++++++++++++++----------------- 1 file changed, 52 insertions(+), 59 deletions(-) diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 8d7f00032bfd..4bc40de7dbd4 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -94,71 +94,64 @@ let in # The stdenv that we are producing. - derivation ( - lib.optionalAttrs (allowedRequisites != null) { - allowedRequisites = allowedRequisites ++ defaultNativeBuildInputs ++ defaultBuildInputs; - } - // lib.optionalAttrs config.contentAddressedByDefault { - __contentAddressed = true; - outputHashAlgo = "sha256"; - outputHashMode = "recursive"; - } - // { - inherit name pname version; - inherit disallowedRequisites; + derivation { + ${if allowedRequisites != null then "allowedRequisites" else null} = + allowedRequisites ++ defaultNativeBuildInputs ++ defaultBuildInputs; + ${if config.contentAddressedByDefault then "__contentAddressed" else null} = true; + ${if config.contentAddressedByDefault then "outputHashAlgo" else null} = "sha256"; + ${if config.contentAddressedByDefault then "outputHashMode" else null} = "recursive"; + inherit name pname version; + inherit disallowedRequisites; - # Nix itself uses the `system` field of a derivation to decide where to - # build it. This is a bit confusing for cross compilation. - inherit (buildPlatform) system; + # Nix itself uses the `system` field of a derivation to decide where to + # build it. This is a bit confusing for cross compilation. + inherit (buildPlatform) system; - builder = shell; + builder = shell; - args = [ - "-e" - ./builder.sh - ]; + args = [ + "-e" + ./builder.sh + ]; - setup = setupScript; + setup = setupScript; - # We pretty much never need rpaths on Darwin, since all library path references - # are absolute unless we go out of our way to make them relative (like with CF) - # TODO: This really wants to be in stdenv/darwin but we don't have hostPlatform - # there (yet?) so it goes here until then. - preHook = - preHook - + lib.optionalString buildPlatform.isDarwin '' - export NIX_DONT_SET_RPATH_FOR_BUILD=1 - '' - + lib.optionalString (hostPlatform.isDarwin || (!hostPlatform.isElf && !hostPlatform.isMacho)) '' - export NIX_DONT_SET_RPATH=1 - export NIX_NO_SELF_RPATH=1 - '' - + lib.optionalString (hostPlatform.isDarwin && hostPlatform.isMacOS) '' - export MACOSX_DEPLOYMENT_TARGET=${hostPlatform.darwinMinVersion} - '' - # TODO this should be uncommented, but it causes stupid mass rebuilds due to - # `pkgsCross.*.buildPackages` not being the same, resulting in cross-compiling - # for a target rebuilding all of `nativeBuildInputs` for that target. - # - # I think the best solution would just be to fixup linux RPATHs so we don't - # need to set `-rpath` anywhere. - # + lib.optionalString targetPlatform.isDarwin '' - # export NIX_DONT_SET_RPATH_FOR_TARGET=1 - # '' + # We pretty much never need rpaths on Darwin, since all library path references + # are absolute unless we go out of our way to make them relative (like with CF) + # TODO: This really wants to be in stdenv/darwin but we don't have hostPlatform + # there (yet?) so it goes here until then. + preHook = + preHook + + lib.optionalString buildPlatform.isDarwin '' + export NIX_DONT_SET_RPATH_FOR_BUILD=1 + '' + + lib.optionalString (hostPlatform.isDarwin || (!hostPlatform.isElf && !hostPlatform.isMacho)) '' + export NIX_DONT_SET_RPATH=1 + export NIX_NO_SELF_RPATH=1 + '' + + lib.optionalString (hostPlatform.isDarwin && hostPlatform.isMacOS) '' + export MACOSX_DEPLOYMENT_TARGET=${hostPlatform.darwinMinVersion} + '' + # TODO this should be uncommented, but it causes stupid mass rebuilds due to + # `pkgsCross.*.buildPackages` not being the same, resulting in cross-compiling + # for a target rebuilding all of `nativeBuildInputs` for that target. + # + # I think the best solution would just be to fixup linux RPATHs so we don't + # need to set `-rpath` anywhere. + # + lib.optionalString targetPlatform.isDarwin '' + # export NIX_DONT_SET_RPATH_FOR_TARGET=1 + # '' + ; + + inherit + initialPath + shell + defaultNativeBuildInputs + defaultBuildInputs ; - - inherit - initialPath - shell - defaultNativeBuildInputs - defaultBuildInputs - ; - } - // lib.optionalAttrs buildPlatform.isDarwin { - __sandboxProfile = stdenvSandboxProfile; - __impureHostDeps = __stdenvImpureHostDeps; - } - ) + ${if buildPlatform.isDarwin then "__sandboxProfile" else null} = stdenvSandboxProfile; + ${if buildPlatform.isDarwin then "__impureHostDeps" else null} = __stdenvImpureHostDeps; + } // { From 77d67d4b7646a82ddb27b76056a930b1425e9928 Mon Sep 17 00:00:00 2001 From: Aliaksandr Date: Sun, 5 Apr 2026 02:51:21 +0300 Subject: [PATCH 4/8] cc-wrapper: replace // optionalAttrs with nullable attr names Inline optionalAttrs for Go passthru attrs and fallback_sdk. Replace mapAttrs+optionalString for Darwin env vars with direct optionalString calls, eliminating intermediate attrset and // merge. --- pkgs/build-support/cc-wrapper/default.nix | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 103e5e9f5994..fd857d0c152d 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -453,13 +453,12 @@ stdenvNoCC.mkDerivation { inherit nixSupport; inherit defaultHardeningFlags; - } - // optionalAttrs cc.langGo or false { + # So gccgo looks more like go for buildGoModule - - inherit (targetPlatform.go) GOOS GOARCH GOARM; - - CGO_ENABLED = 1; + ${if cc.langGo or false then "GOOS" else null} = targetPlatform.go.GOOS; + ${if cc.langGo or false then "GOARCH" else null} = targetPlatform.go.GOARCH; + ${if cc.langGo or false then "GOARM" else null} = targetPlatform.go.GOARM; + ${if cc.langGo or false then "CGO_ENABLED" else null} = 1; }; dontBuild = true; @@ -995,14 +994,12 @@ stdenvNoCC.mkDerivation { inherit darwinPlatformForCC; default_hardening_flags_str = toString defaultHardeningFlags; inherit useMacroPrefixMap; - } - // lib.mapAttrs (_: lib.optionalString targetPlatform.isDarwin) { # These will become empty strings when not targeting Darwin. - inherit (targetPlatform) darwinMinVersion darwinMinVersionVariable; - } - // lib.optionalAttrs (stdenvNoCC.targetPlatform.isDarwin && apple-sdk != null) { + darwinMinVersion = lib.optionalString targetPlatform.isDarwin targetPlatform.darwinMinVersion; + darwinMinVersionVariable = lib.optionalString targetPlatform.isDarwin targetPlatform.darwinMinVersionVariable; # Wrapped compilers should do something useful even when no SDK is provided at `DEVELOPER_DIR`. - fallback_sdk = apple-sdk.__spliced.buildTarget or apple-sdk; + ${if stdenvNoCC.targetPlatform.isDarwin && apple-sdk != null then "fallback_sdk" else null} = + apple-sdk.__spliced.buildTarget or apple-sdk; }; meta = From ce3c5727ee5268e3aa0e574d2fbc2a579a358f01 Mon Sep 17 00:00:00 2001 From: Aliaksandr Date: Sun, 5 Apr 2026 02:51:35 +0300 Subject: [PATCH 5/8] bintools-wrapper: replace // optionalAttrs with nullable attr names Same pattern as cc-wrapper: inline mapAttrs+optionalString for Darwin env vars and replace optionalAttrs for fallback_sdk. --- pkgs/build-support/bintools-wrapper/default.nix | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index b97eb905bd31..1a9ce996c0dd 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -468,19 +468,14 @@ stdenvNoCC.mkDerivation { libc_lib ; default_hardening_flags_str = toString defaultHardeningFlags; - } - // lib.mapAttrs (_: lib.optionalString targetPlatform.isDarwin) { # These will become empty strings when not targeting Darwin. - inherit (targetPlatform) - darwinPlatform - darwinSdkVersion - darwinMinVersion - darwinMinVersionVariable - ; - } - // lib.optionalAttrs (stdenvNoCC.targetPlatform.isDarwin && apple-sdk != null) { + darwinPlatform = lib.optionalString targetPlatform.isDarwin targetPlatform.darwinPlatform; + darwinSdkVersion = lib.optionalString targetPlatform.isDarwin targetPlatform.darwinSdkVersion; + darwinMinVersion = lib.optionalString targetPlatform.isDarwin targetPlatform.darwinMinVersion; + darwinMinVersionVariable = lib.optionalString targetPlatform.isDarwin targetPlatform.darwinMinVersionVariable; # Wrapped compilers should do something useful even when no SDK is provided at `DEVELOPER_DIR`. - fallback_sdk = apple-sdk.__spliced.buildTarget or apple-sdk; + ${if stdenvNoCC.targetPlatform.isDarwin && apple-sdk != null then "fallback_sdk" else null} = + apple-sdk.__spliced.buildTarget or apple-sdk; }; meta = From 702420055d73abe212e13be26b3b191997613426 Mon Sep 17 00:00:00 2001 From: Aliaksandr Date: Sun, 5 Apr 2026 02:51:36 +0300 Subject: [PATCH 6/8] top-level/stage: replace // optionalAttrs with nullable attr names Convert 2 optionalAttrs: Darwin extraBuildInputs in stdenvNoCC override, and !isSupported stdenv override in pkgsi686Linux. --- pkgs/top-level/stage.nix | 47 +++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix index 048ab88854ed..ac56e93e344e 100644 --- a/pkgs/top-level/stage.nix +++ b/pkgs/top-level/stage.nix @@ -54,15 +54,13 @@ in # `stdenv` without a C compiler. Passing in this helps avoid infinite # recursions, and may eventually replace passing in the full stdenv. - stdenvNoCC ? stdenv.override ( - { - cc = null; - hasCC = false; - } + stdenvNoCC ? stdenv.override { + cc = null; + hasCC = false; # Darwin doesn’t need an SDK in `stdenvNoCC`. Dropping it shrinks the closure # size down from ~1 GiB to ~83 MiB, which is a considerable reduction. - // lib.optionalAttrs stdenv.hostPlatform.isDarwin { extraBuildInputs = [ ]; } - ), + ${if stdenv.hostPlatform.isDarwin then "extraBuildInputs" else null} = [ ]; + }, # This is used because stdenv replacement and the stdenvCross do benefit from # the overridden configuration provided by the user, as opposed to the normal @@ -218,26 +216,21 @@ let if !config.allowAliases || isSupported then nixpkgsFun { overlays = [ - ( - self': super': - { - pkgsi686Linux = super'; - } - // lib.optionalAttrs (!isSupported) { - # Overrides pkgsi686Linux.stdenv.mkDerivation to produce only broken derivations, - # when used on a non x86_64-linux platform in CI. - # TODO: Remove this, once pkgsi686Linux can become a variant. - stdenv = super'.stdenv // { - mkDerivation = - args: - (super'.stdenv.mkDerivation args).overrideAttrs (prevAttrs: { - meta = prevAttrs.meta or { } // { - broken = true; - }; - }); - }; - } - ) + (self': super': { + pkgsi686Linux = super'; + # Overrides pkgsi686Linux.stdenv.mkDerivation to produce only broken derivations, + # when used on a non x86_64-linux platform in CI. + # TODO: Remove this, once pkgsi686Linux can become a variant. + ${if !isSupported then "stdenv" else null} = super'.stdenv // { + mkDerivation = + args: + (super'.stdenv.mkDerivation args).overrideAttrs (prevAttrs: { + meta = prevAttrs.meta or { } // { + broken = true; + }; + }); + }; + }) ] ++ overlays; ${if stdenv.hostPlatform == stdenv.buildPlatform then "localSystem" else "crossSystem"} = { From fbfe0b610e06300f78646a08cb7171e3a2853447 Mon Sep 17 00:00:00 2001 From: Aliaksandr Date: Sun, 5 Apr 2026 02:51:37 +0300 Subject: [PATCH 7/8] rust/hooks: replace // optionalAttrs with nullable attr names Convert 5 identical optionalAttrs (stdenv.isLinux) for testCross in cargo{Build,Check,Install,Nextest,Setup}Hook passthru.tests. --- pkgs/build-support/rust/hooks/default.nix | 25 +++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pkgs/build-support/rust/hooks/default.nix b/pkgs/build-support/rust/hooks/default.nix index 0814f78edfef..1cfb56f785c0 100644 --- a/pkgs/build-support/rust/hooks/default.nix +++ b/pkgs/build-support/rust/hooks/default.nix @@ -26,9 +26,8 @@ }; passthru.tests = { test = tests.rust-hooks.cargoBuildHook; - } - // lib.optionalAttrs (stdenv.hostPlatform.isLinux) { - testCross = pkgsCross.riscv64.tests.rust-hooks.cargoBuildHook; + ${if stdenv.hostPlatform.isLinux then "testCross" else null} = + pkgsCross.riscv64.tests.rust-hooks.cargoBuildHook; }; } ./cargo-build-hook.sh; @@ -40,9 +39,8 @@ }; passthru.tests = { test = tests.rust-hooks.cargoCheckHook; - } - // lib.optionalAttrs (stdenv.hostPlatform.isLinux) { - testCross = pkgsCross.riscv64.tests.rust-hooks.cargoCheckHook; + ${if stdenv.hostPlatform.isLinux then "testCross" else null} = + pkgsCross.riscv64.tests.rust-hooks.cargoCheckHook; }; } ./cargo-check-hook.sh; @@ -53,9 +51,8 @@ }; passthru.tests = { test = tests.rust-hooks.cargoInstallHook; - } - // lib.optionalAttrs (stdenv.hostPlatform.isLinux) { - testCross = pkgsCross.riscv64.tests.rust-hooks.cargoInstallHook; + ${if stdenv.hostPlatform.isLinux then "testCross" else null} = + pkgsCross.riscv64.tests.rust-hooks.cargoInstallHook; }; } ./cargo-install-hook.sh; @@ -67,9 +64,8 @@ }; passthru.tests = { test = tests.rust-hooks.cargoNextestHook; - } - // lib.optionalAttrs (stdenv.hostPlatform.isLinux) { - testCross = pkgsCross.riscv64.tests.rust-hooks.cargoNextestHook; + ${if stdenv.hostPlatform.isLinux then "testCross" else null} = + pkgsCross.riscv64.tests.rust-hooks.cargoNextestHook; }; } ./cargo-nextest-hook.sh; @@ -106,9 +102,8 @@ passthru.tests = { test = tests.rust-hooks.cargoSetupHook; - } - // lib.optionalAttrs (stdenv.hostPlatform.isLinux) { - testCross = pkgsCross.riscv64.tests.rust-hooks.cargoSetupHook; + ${if stdenv.hostPlatform.isLinux then "testCross" else null} = + pkgsCross.riscv64.tests.rust-hooks.cargoSetupHook; }; } ./cargo-setup-hook.sh; From 18e7551efc7beca866fd2cfa3092d9386eb1dd34 Mon Sep 17 00:00:00 2001 From: Aliaksandr Date: Sun, 5 Apr 2026 03:34:41 +0300 Subject: [PATCH 8/8] buildenv: replace // optionalAttrs with nullable attr names Convert 2 optionalAttrs (args ? nativeBuildInputs, args ? buildInputs) in the compatArgs block into nullable attribute names in a single attrset. --- pkgs/build-support/buildenv/default.nix | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/buildenv/default.nix b/pkgs/build-support/buildenv/default.nix index 13ab910ab6b8..797126aa7644 100644 --- a/pkgs/build-support/buildenv/default.nix +++ b/pkgs/build-support/buildenv/default.nix @@ -86,13 +86,10 @@ lib.makeOverridable ( buildInputs ? null, }@args: let - compatArgs = - lib.optionalAttrs (args ? nativeBuildInputs) { - inherit nativeBuildInputs; - } - // lib.optionalAttrs (args ? buildInputs) { - inherit buildInputs; - }; + compatArgs = { + ${if args ? nativeBuildInputs then "nativeBuildInputs" else null} = nativeBuildInputs; + ${if args ? buildInputs then "buildInputs" else null} = buildInputs; + }; in compatArgs // derivationArgs