Skip to content

Commit

Permalink
nix: Use -split-sections with pkgsStatic to make static executable sm…
Browse files Browse the repository at this point in the history
…aller again

This works around NixOS/nixpkgs#286285 to use -split-sections
in a cross-compiling scenario. This will reduce the size of the static executable and also
remove the remaining references to /nix/store/.. reducing closure size dramatically.

This also fixes the docker image blowing up in size since we switched to pkgsStatic.
  • Loading branch information
wolfgangwalther committed Feb 6, 2024
1 parent 9fe0f50 commit ea02729
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ let
sha256 = nixpkgsVersion.tarballHash;
};

nixpkgs-patched = (import nixpkgs { inherit overlays system; }).applyPatches {
name = "nixpkgs-patched";
src = nixpkgs;
patches = [ nix/split-sections-cross.patch ];
};

allOverlays =
import nix/overlays;

Expand All @@ -46,7 +52,7 @@ let

# Evaluated expression of the Nixpkgs repository.
pkgs =
import nixpkgs { inherit overlays system; };
import nixpkgs-patched { inherit overlays system; };

postgresqlVersions =
[
Expand Down Expand Up @@ -82,7 +88,7 @@ let
inherit (pkgs.haskell) lib;
in
rec {
inherit nixpkgs pkgs;
inherit nixpkgs-patched pkgs;

# Derivation for the PostgREST Haskell package, including the executable,
# libraries and documentation. We disable running the test suite on Nix
Expand Down
14 changes: 14 additions & 0 deletions nix/split-sections-cross.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This works around https://github.com/NixOS/nixpkgs/issues/286285 by passing --enable-split-sections instead of ghc-options.
---
--- a/pkgs/development/haskell-modules/generic-builder.nix
+++ b/pkgs/development/haskell-modules/generic-builder.nix
@@ -245,8 +245,7 @@ let
(enableFeature doBenchmark "benchmarks")
"--enable-library-vanilla" # TODO: Should this be configurable?
(enableFeature enableLibraryForGhci "library-for-ghci")
- ] ++ optionals (enableDeadCodeElimination && (lib.versionOlder "8.0.1" ghc.version)) [
- "--ghc-option=-split-sections"
+ (enableFeature enableDeadCodeElimination "split-sections")
] ++ optionals dontStrip [
"--disable-library-stripping"
"--disable-executable-stripping"

0 comments on commit ea02729

Please sign in to comment.