pkgsStatic: Finally obviate overlay!

This commit is contained in:
John Ericson 2021-08-20 06:03:45 +00:00
parent 904625852d
commit 3edba5edfc
4 changed files with 23 additions and 44 deletions

View File

@ -108,6 +108,20 @@ rec {
});
});
# Puts all the other ones together
makeStatic = stdenv: lib.foldl (lib.flip lib.id) stdenv (
lib.optional stdenv.hostPlatform.isDarwin makeStaticDarwin
++ [ makeStaticLibraries propagateBuildInputs ]
# Apple does not provide a static version of libSystem or crt0.o
# So we cant build static binaries without extensive hacks.
++ lib.optional (!stdenv.hostPlatform.isDarwin) makeStaticBinaries
# Glibc doesnt come with static runtimes by default.
# ++ lib.optional (stdenv.hostPlatform.libc == "glibc") ((lib.flip overrideInStdenv) [ self.stdenv.glibc.static ])
);
/* Modify a stdenv so that all buildInputs are implicitly propagated to
consuming derivations

View File

@ -35,12 +35,16 @@ in lib.init bootStages ++ [
})
# Run Packages
(buildPackages: {
(buildPackages: let
adaptStdenv =
if crossSystem.isStatic
then buildPackages.stdenvAdapters.makeStatic
else lib.id;
in {
inherit config;
overlays = overlays ++ crossOverlays
++ (if (with crossSystem; isWasm || isRedox) then [(import ../../top-level/static.nix)] else []);
overlays = overlays ++ crossOverlays;
selfBuild = false;
stdenv = buildPackages.stdenv.override (old: rec {
stdenv = adaptStdenv (buildPackages.stdenv.override (old: rec {
buildPlatform = localSystem;
hostPlatform = crossSystem;
targetPlatform = crossSystem;
@ -83,7 +87,7 @@ in lib.init bootStages ++ [
# to recognize 64-bit DLLs
++ lib.optional (hostPlatform.config == "x86_64-w64-mingw32") buildPackages.file
;
});
}));
})
]

View File

@ -235,7 +235,6 @@ let
overlays = [ (self': super': {
pkgsStatic = super';
})] ++ overlays;
crossOverlays = [ (import ./static.nix) ];
} // lib.optionalAttrs stdenv.hostPlatform.isLinux {
crossSystem = {
isStatic = true;

View File

@ -1,38 +0,0 @@
# Overlay that builds static packages.
# Not all packages will build but support is done on a
# best effort basic.
#
# Note on Darwin/macOS: Apple does not provide a static libc
# so any attempts at static binaries are going to be very
# unsupported.
#
# Basic things like pkgsStatic.hello should work out of the box. More
# complicated things will need to be fixed with overrides.
self: super: let
inherit (super.stdenvAdapters) makeStaticBinaries
makeStaticLibraries
propagateBuildInputs
makeStaticDarwin;
inherit (super.lib) foldl optional flip id composeExtensions;
staticAdapters =
optional super.stdenv.hostPlatform.isDarwin makeStaticDarwin
++ [ makeStaticLibraries propagateBuildInputs ]
# Apple does not provide a static version of libSystem or crt0.o
# So we cant build static binaries without extensive hacks.
++ optional (!super.stdenv.hostPlatform.isDarwin) makeStaticBinaries
# Glibc doesnt come with static runtimes by default.
# ++ optional (super.stdenv.hostPlatform.libc == "glibc") ((flip overrideInStdenv) [ self.stdenv.glibc.static ])
;
in {
# Do not add new packages here! Instead use `stdenv.hostPlatform.isStatic` to
# write conditional code in the original package.
stdenv = foldl (flip id) super.stdenv staticAdapters;
}