mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-06-05 21:03:40 +00:00
various: reduce // merges, optimize ++ chains across hot paths (#506793)
This commit is contained in:
@@ -400,7 +400,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;
|
||||
@@ -422,15 +440,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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
meta.license = lib.licenses.mit;
|
||||
} ./cargo-build-hook.sh;
|
||||
@@ -41,9 +40,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;
|
||||
};
|
||||
meta.license = lib.licenses.mit;
|
||||
} ./cargo-check-hook.sh;
|
||||
@@ -55,9 +53,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;
|
||||
};
|
||||
meta.license = lib.licenses.mit;
|
||||
} ./cargo-install-hook.sh;
|
||||
@@ -70,9 +67,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;
|
||||
};
|
||||
meta.license = lib.licenses.mit;
|
||||
} ./cargo-nextest-hook.sh;
|
||||
@@ -110,9 +106,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;
|
||||
};
|
||||
meta.license = lib.licenses.mit;
|
||||
} ./cargo-setup-hook.sh;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
// {
|
||||
|
||||
|
||||
@@ -725,7 +725,6 @@ let
|
||||
propagatedBuildInputs = propagatedHostTargetOutputs;
|
||||
depsTargetTargetPropagated = propagatedTargetTargetOutputs;
|
||||
|
||||
# This parameter is sometimes a string, sometimes null, and sometimes a list, yuck
|
||||
configureFlags =
|
||||
configureFlags
|
||||
++ (
|
||||
|
||||
@@ -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"} = {
|
||||
|
||||
Reference in New Issue
Block a user