From 21af82e003c551ba45153d0ec30ff2f0c615a706 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Wed, 7 Feb 2024 11:19:45 +0100 Subject: [PATCH 1/4] Add missing libblst to GHC options of wrapped-cabal in static mode. --- flake.nix | 4 ++++ static.nix | 1 + 2 files changed, 5 insertions(+) diff --git a/flake.nix b/flake.nix index ce4fc59..9e2c0cc 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,10 @@ static-openssl = (final.openssl.override { static = true; }); static-zlib = final.zlib.override { shared = false; }; static-pcre = final.pcre.override { shared = false; }; + static-libblst = final.libblst.overrideDerivation (old: { + configureFlags = old.configureFlags ++ [ "--enable-static" "--disable-shared" ]; + postFixup = ""; + }); }); # the haskell inline-r package depends on internals of the R # project that have been hidden in R 4.2+. See diff --git a/static.nix b/static.nix index 39127d6..2b2fd71 100644 --- a/static.nix +++ b/static.nix @@ -39,6 +39,7 @@ let tool-version-map = import ./tool-map.nix; --ghc-option=-L${lib.getLib static-gmp}/lib \ --ghc-option=-L${lib.getLib static-libsodium-vrf}/lib \ --ghc-option=-L${lib.getLib static-secp256k1}/lib \ + --ghc-option=-L${lib.getLib static-libblst}/lib \ --ghc-option=-L${lib.getLib static-openssl}/lib ;; clean|unpack) From 2f50808ab3ed7bde66bc7cabd7c4c13f8756e2c8 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Wed, 14 Feb 2024 09:44:18 +0100 Subject: [PATCH 2/4] comment out post-fixup --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index 9e2c0cc..553eec5 100644 --- a/flake.nix +++ b/flake.nix @@ -25,7 +25,6 @@ static-pcre = final.pcre.override { shared = false; }; static-libblst = final.libblst.overrideDerivation (old: { configureFlags = old.configureFlags ++ [ "--enable-static" "--disable-shared" ]; - postFixup = ""; }); }); # the haskell inline-r package depends on internals of the R From e693c639ad1e226f4f7ef4d4374505066b603f37 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Wed, 14 Feb 2024 10:23:10 +0100 Subject: [PATCH 3/4] Overwrite buildPhase for libblst static The current buildPhase in NixOS/nixpkgs does something like this: ``` ./build.sh ${lib.optionalString stdenv.hostPlatform.isWindows "flavour=mingw64"} ./build.sh -shared ${lib.optionalString stdenv.hostPlatform.isWindows "flavour=mingw64"} ``` So we do build both a dynamic and static version, for convenience, which is then correctly visible in the nix store (both `.a` and `.dylib` are present). BUT, it seems that because of the presence of the dynamic lib, cabal or GHC (?) still chose to bundle the library dynamically despite the static flags. Removing the `.dylib` from the nix store recover the expected behavior (libblst being statically linked). This is odd, but the current fix is to not build the `-shared` version of the library at all when in the static shell. Co-authored-by: yvan-sraka --- flake.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/flake.nix b/flake.nix index 553eec5..2be304a 100644 --- a/flake.nix +++ b/flake.nix @@ -25,6 +25,12 @@ static-pcre = final.pcre.override { shared = false; }; static-libblst = final.libblst.overrideDerivation (old: { configureFlags = old.configureFlags ++ [ "--enable-static" "--disable-shared" ]; + buildPhase = '' + runHook preBuild + ./build.sh + runHook postBuild + ''; + postFixup = ""; }); }); # the haskell inline-r package depends on internals of the R From 8782f65e14f339568057457efdbb2888d8380a7a Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Thu, 21 Mar 2024 15:06:14 +0100 Subject: [PATCH 4/4] Enforce the use of static libraries in `-static` devshell --- static.nix | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/static.nix b/static.nix index 2b2fd71..ffe8ba6 100644 --- a/static.nix +++ b/static.nix @@ -106,15 +106,14 @@ pkgs.mkShell (rec { # it _should_ probably call out to a g++ or clang++ but doesn't. stdenv.cc.cc.lib ]) ++ map lib.getDev ([ - static-gmp - - zlib pcre - openssl + static-gmp + static-openssl + static-zlib ] ++ lib.optionals withIOG [ - libblst - libsodium-vrf - secp256k1 + static-libblst + static-libsodium-vrf + static-secp256k1 #R_4_1_3 # for plutus postgresql # for db-sync icu # for cardano-cli