stdenvAdapters: refactor in terms of overrideMkDerivationArgs
The newly added function `overrideMkDerivationArgs` [1] is strictly more general than some of the stdenv adapters. We rewrite suitable functions in terms of `overrideMkDerivationArgs` in order to simplify their implementation. This commit is based off of @SomeoneSerge's PR [2]. [1] https://github.com/NixOS/nixpkgs/pull/496862 [2] https://github.com/NixOS/nixpkgs/pull/350350 Co-authored-by: SomeoneSerge <else+aalto@someonex.net>
This commit is contained in:
co-authored by
SomeoneSerge
parent
0be36453b2
commit
bcb20ae99e
+47
-73
@@ -121,27 +121,23 @@ rec {
|
||||
|
||||
# Return a modified stdenv that builds static libraries instead of
|
||||
# shared libraries.
|
||||
makeStaticLibraries =
|
||||
stdenv:
|
||||
stdenv.override (old: {
|
||||
mkDerivationFromStdenv = extendMkDerivationArgs old (
|
||||
args:
|
||||
{
|
||||
dontDisableStatic = true;
|
||||
}
|
||||
// lib.optionalAttrs (!(args.dontAddStaticConfigureFlags or false)) {
|
||||
configureFlags = (args.configureFlags or [ ]) ++ [
|
||||
"--enable-static"
|
||||
"--disable-shared"
|
||||
];
|
||||
cmakeFlags = (args.cmakeFlags or [ ]) ++ [ "-DBUILD_SHARED_LIBS:BOOL=OFF" ];
|
||||
mesonFlags = (args.mesonFlags or [ ]) ++ [
|
||||
"-Ddefault_library=static"
|
||||
"-Ddefault_both_libraries=static"
|
||||
];
|
||||
}
|
||||
);
|
||||
});
|
||||
makeStaticLibraries = overrideMkDerivationArgs (
|
||||
args:
|
||||
{
|
||||
dontDisableStatic = true;
|
||||
}
|
||||
// lib.optionalAttrs (!(args.dontAddStaticConfigureFlags or false)) {
|
||||
configureFlags = (args.configureFlags or [ ]) ++ [
|
||||
"--enable-static"
|
||||
"--disable-shared"
|
||||
];
|
||||
cmakeFlags = (args.cmakeFlags or [ ]) ++ [ "-DBUILD_SHARED_LIBS:BOOL=OFF" ];
|
||||
mesonFlags = (args.mesonFlags or [ ]) ++ [
|
||||
"-Ddefault_library=static"
|
||||
"-Ddefault_both_libraries=static"
|
||||
];
|
||||
}
|
||||
);
|
||||
|
||||
# Best effort static binaries. Will still be linked to libSystem,
|
||||
# but more portable than Nix store binaries.
|
||||
@@ -190,14 +186,10 @@ rec {
|
||||
Modify a stdenv so that all buildInputs are implicitly propagated to
|
||||
consuming derivations
|
||||
*/
|
||||
propagateBuildInputs =
|
||||
stdenv:
|
||||
stdenv.override (old: {
|
||||
mkDerivationFromStdenv = extendMkDerivationArgs old (args: {
|
||||
propagatedBuildInputs = (args.propagatedBuildInputs or [ ]) ++ (args.buildInputs or [ ]);
|
||||
buildInputs = [ ];
|
||||
});
|
||||
});
|
||||
propagateBuildInputs = overrideMkDerivationArgs (args: {
|
||||
propagatedBuildInputs = (args.propagatedBuildInputs or [ ]) ++ (args.buildInputs or [ ]);
|
||||
buildInputs = [ ];
|
||||
});
|
||||
|
||||
/*
|
||||
Modify a stdenv so that the specified attributes are added to
|
||||
@@ -209,11 +201,7 @@ rec {
|
||||
{ env.NIX_CFLAGS_COMPILE = "-O0"; }
|
||||
stdenv;
|
||||
*/
|
||||
addAttrsToDerivation =
|
||||
extraAttrs: stdenv:
|
||||
stdenv.override (old: {
|
||||
mkDerivationFromStdenv = extendMkDerivationArgs old (_: extraAttrs);
|
||||
});
|
||||
addAttrsToDerivation = extraAttrs: overrideMkDerivationArgs (_: extraAttrs);
|
||||
|
||||
/*
|
||||
Modify a stdenv so as to extend `mkDerivation`'s arguments.
|
||||
@@ -263,28 +251,20 @@ rec {
|
||||
binaries have debug info, and compiler optimisations are
|
||||
disabled.
|
||||
*/
|
||||
keepDebugInfo =
|
||||
stdenv:
|
||||
stdenv.override (old: {
|
||||
mkDerivationFromStdenv = extendMkDerivationArgs old (args: {
|
||||
dontStrip = true;
|
||||
env = (args.env or { }) // {
|
||||
NIX_CFLAGS_COMPILE = toString (args.env.NIX_CFLAGS_COMPILE or "") + " -ggdb -Og";
|
||||
NIX_RUSTFLAGS = toString (args.env.NIX_RUSTFLAGS or "") + " -g -C opt-level=0 -C strip=none";
|
||||
};
|
||||
});
|
||||
});
|
||||
keepDebugInfo = overrideMkDerivationArgs (args: {
|
||||
dontStrip = true;
|
||||
env = (args.env or { }) // {
|
||||
NIX_CFLAGS_COMPILE = toString (args.env.NIX_CFLAGS_COMPILE or "") + " -ggdb -Og";
|
||||
NIX_RUSTFLAGS = toString (args.env.NIX_RUSTFLAGS or "") + " -g -C opt-level=0 -C strip=none";
|
||||
};
|
||||
});
|
||||
|
||||
# Modify a stdenv so that it uses the Gold linker.
|
||||
useGoldLinker =
|
||||
stdenv:
|
||||
stdenv.override (old: {
|
||||
mkDerivationFromStdenv = extendMkDerivationArgs old (args: {
|
||||
env = (args.env or { }) // {
|
||||
NIX_CFLAGS_LINK = toString (args.env.NIX_CFLAGS_LINK or "") + " -fuse-ld=gold";
|
||||
};
|
||||
});
|
||||
});
|
||||
useGoldLinker = overrideMkDerivationArgs (args: {
|
||||
env = (args.env or { }) // {
|
||||
NIX_CFLAGS_LINK = toString (args.env.NIX_CFLAGS_LINK or "") + " -fuse-ld=gold";
|
||||
};
|
||||
});
|
||||
|
||||
/*
|
||||
Copy the libstdc++ from the model stdenv to the target stdenv.
|
||||
@@ -383,20 +363,16 @@ rec {
|
||||
|
||||
WARNING: this breaks purity!
|
||||
*/
|
||||
impureUseNativeOptimizations =
|
||||
stdenv:
|
||||
stdenv.override (old: {
|
||||
mkDerivationFromStdenv = extendMkDerivationArgs old (args: {
|
||||
env = (args.env or { }) // {
|
||||
NIX_CFLAGS_COMPILE = toString (args.env.NIX_CFLAGS_COMPILE or "") + " -march=native";
|
||||
};
|
||||
impureUseNativeOptimizations = overrideMkDerivationArgs (args: {
|
||||
env = (args.env or { }) // {
|
||||
NIX_CFLAGS_COMPILE = toString (args.env.NIX_CFLAGS_COMPILE or "") + " -march=native";
|
||||
};
|
||||
|
||||
NIX_ENFORCE_NO_NATIVE = false;
|
||||
NIX_ENFORCE_NO_NATIVE = false;
|
||||
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
});
|
||||
});
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
});
|
||||
|
||||
/*
|
||||
Modify a stdenv so that it builds binaries with the specified list of
|
||||
@@ -413,13 +389,11 @@ rec {
|
||||
];
|
||||
*/
|
||||
withCFlags =
|
||||
compilerFlags: stdenv:
|
||||
stdenv.override (old: {
|
||||
mkDerivationFromStdenv = extendMkDerivationArgs old (args: {
|
||||
env = (args.env or { }) // {
|
||||
NIX_CFLAGS_COMPILE = toString (args.env.NIX_CFLAGS_COMPILE or "") + " ${toString compilerFlags}";
|
||||
};
|
||||
});
|
||||
compilerFlags:
|
||||
overrideMkDerivationArgs (args: {
|
||||
env = (args.env or { }) // {
|
||||
NIX_CFLAGS_COMPILE = toString (args.env.NIX_CFLAGS_COMPILE or "") + " ${toString compilerFlags}";
|
||||
};
|
||||
});
|
||||
|
||||
withDefaultHardeningFlags =
|
||||
|
||||
Reference in New Issue
Block a user