Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

pkgsStatic: Finally obviate overlay!

+23 -44
+14
pkgs/stdenv/adapters.nix
··· 108 108 }); 109 109 }); 110 110 111 + # Puts all the other ones together 112 + makeStatic = stdenv: lib.foldl (lib.flip lib.id) stdenv ( 113 + lib.optional stdenv.hostPlatform.isDarwin makeStaticDarwin 114 + 115 + ++ [ makeStaticLibraries propagateBuildInputs ] 116 + 117 + # Apple does not provide a static version of libSystem or crt0.o 118 + # So we can’t build static binaries without extensive hacks. 119 + ++ lib.optional (!stdenv.hostPlatform.isDarwin) makeStaticBinaries 120 + 121 + # Glibc doesn’t come with static runtimes by default. 122 + # ++ lib.optional (stdenv.hostPlatform.libc == "glibc") ((lib.flip overrideInStdenv) [ self.stdenv.glibc.static ]) 123 + ); 124 + 111 125 112 126 /* Modify a stdenv so that all buildInputs are implicitly propagated to 113 127 consuming derivations
+9 -5
pkgs/stdenv/cross/default.nix
··· 35 35 }) 36 36 37 37 # Run Packages 38 - (buildPackages: { 38 + (buildPackages: let 39 + adaptStdenv = 40 + if crossSystem.isStatic 41 + then buildPackages.stdenvAdapters.makeStatic 42 + else lib.id; 43 + in { 39 44 inherit config; 40 - overlays = overlays ++ crossOverlays 41 - ++ (if (with crossSystem; isWasm || isRedox) then [(import ../../top-level/static.nix)] else []); 45 + overlays = overlays ++ crossOverlays; 42 46 selfBuild = false; 43 - stdenv = buildPackages.stdenv.override (old: rec { 47 + stdenv = adaptStdenv (buildPackages.stdenv.override (old: rec { 44 48 buildPlatform = localSystem; 45 49 hostPlatform = crossSystem; 46 50 targetPlatform = crossSystem; ··· 83 87 # to recognize 64-bit DLLs 84 88 ++ lib.optional (hostPlatform.config == "x86_64-w64-mingw32") buildPackages.file 85 89 ; 86 - }); 90 + })); 87 91 }) 88 92 89 93 ]
-1
pkgs/top-level/stage.nix
··· 235 235 overlays = [ (self': super': { 236 236 pkgsStatic = super'; 237 237 })] ++ overlays; 238 - crossOverlays = [ (import ./static.nix) ]; 239 238 } // lib.optionalAttrs stdenv.hostPlatform.isLinux { 240 239 crossSystem = { 241 240 isStatic = true;
-38
pkgs/top-level/static.nix
··· 1 - # Overlay that builds static packages. 2 - 3 - # Not all packages will build but support is done on a 4 - # best effort basic. 5 - # 6 - # Note on Darwin/macOS: Apple does not provide a static libc 7 - # so any attempts at static binaries are going to be very 8 - # unsupported. 9 - # 10 - # Basic things like pkgsStatic.hello should work out of the box. More 11 - # complicated things will need to be fixed with overrides. 12 - 13 - self: super: let 14 - inherit (super.stdenvAdapters) makeStaticBinaries 15 - makeStaticLibraries 16 - propagateBuildInputs 17 - makeStaticDarwin; 18 - inherit (super.lib) foldl optional flip id composeExtensions; 19 - 20 - staticAdapters = 21 - optional super.stdenv.hostPlatform.isDarwin makeStaticDarwin 22 - 23 - ++ [ makeStaticLibraries propagateBuildInputs ] 24 - 25 - # Apple does not provide a static version of libSystem or crt0.o 26 - # So we can’t build static binaries without extensive hacks. 27 - ++ optional (!super.stdenv.hostPlatform.isDarwin) makeStaticBinaries 28 - 29 - # Glibc doesn’t come with static runtimes by default. 30 - # ++ optional (super.stdenv.hostPlatform.libc == "glibc") ((flip overrideInStdenv) [ self.stdenv.glibc.static ]) 31 - ; 32 - 33 - in { 34 - # Do not add new packages here! Instead use `stdenv.hostPlatform.isStatic` to 35 - # write conditional code in the original package. 36 - 37 - stdenv = foldl (flip id) super.stdenv staticAdapters; 38 - }