From 58f5a861f30dedcc81618819d702db932e23d886 Mon Sep 17 00:00:00 2001 From: Paul Brinkmeier Date: Sun, 13 Jul 2025 13:37:08 +0200 Subject: [PATCH] Add some comments regarding the static build options --- flake.nix | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 747a66b..0aee4fd 100644 --- a/flake.nix +++ b/flake.nix @@ -26,23 +26,29 @@ # And some build configuration. # See https://nixos.org/manual/nixpkgs/unstable/#haskell-packaging-helpers. [ + # Configurable static build. Set cabal options... compose.disableSharedExecutables compose.disableSharedLibraries + # ... and link required static libraries. (compose.appendConfigureFlags [ "--ghc-option=-optl=-static" "--ghc-option=-optl=-pthread" - "--ghc-option=-optl=-L${pkgs.gmp6.override { withStatic = true; }}/lib" - "--ghc-option=-optl=-L${pkgs.zlib.static}/lib" - "--ghc-option=-optl=-L${pkgs.glibc.static}/lib" + "--extra-lib-dirs=${pkgs.gmp6.override { withStatic = true; }}/lib" + "--extra-lib-dirs=${pkgs.zlib.static}/lib" + "--extra-lib-dirs=${pkgs.glibc.static}/lib" "--extra-lib-dirs=${pkgs.libffi.overrideAttrs (old: { dontDisableStatic = true; })}/lib" ]) - # Remove warp which pulls GHC into the runtime deps for some reason. + # Remove all references to the Nix store from the executable. + # This is important because Nix uses the references for calculating + # what needs to be in the Docker container. + # FIXME: Using static linking, these references shouldn't even still be there. + # Can we somehow make GHC stop emitting them? (compose.overrideCabal (drv: { postInstall = '' - remove-references-to -t ${pkgs.haskellPackages.warp} $out/bin/utoy + ${pkgs.nukeReferences}/bin/nuke-refs $out/bin/utoy ''; })) - # Return only the bin folder to curb image size + # Return only the bin folder to curb image size. compose.justStaticExecutables ]; in {