diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 9e1c73a57db1..971be95e935d 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -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 can’t build static binaries without extensive hacks. + ++ lib.optional (!stdenv.hostPlatform.isDarwin) makeStaticBinaries + + # Glibc doesn’t 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 diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index 18a6e2a47372..613b8d5304c0 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -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 ; - }); + })); }) ] diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix index b01ef584d206..eef337ea40c7 100644 --- a/pkgs/top-level/stage.nix +++ b/pkgs/top-level/stage.nix @@ -235,7 +235,6 @@ let overlays = [ (self': super': { pkgsStatic = super'; })] ++ overlays; - crossOverlays = [ (import ./static.nix) ]; } // lib.optionalAttrs stdenv.hostPlatform.isLinux { crossSystem = { isStatic = true; diff --git a/pkgs/top-level/static.nix b/pkgs/top-level/static.nix deleted file mode 100644 index 3cc3f6b79f4b..000000000000 --- a/pkgs/top-level/static.nix +++ /dev/null @@ -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 can’t build static binaries without extensive hacks. - ++ optional (!super.stdenv.hostPlatform.isDarwin) makeStaticBinaries - - # Glibc doesn’t 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; -}