Skip to content

Commit 81d1639

Browse files
committed
flake: compile with pkgMusl on Linux, refactor Darwin deps
This should allow the use of GHC 9.8 on Linux
1 parent 5d48ad6 commit 81d1639

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

flake.nix

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,42 @@
2727

2828
# prefer musl on Linux, static glibc + threading does not work properly
2929
# TODO: maybe only override it for echidna-redistributable?
30-
pkgsStatic = if pkgs.stdenv.hostPlatform.isLinux then pkgs.pkgsStatic else pkgs;
30+
pkgsGHC = if pkgs.stdenv.hostPlatform.isLinux then pkgs.pkgsMusl else pkgs;
31+
pkgsDeps = if pkgs.stdenv.hostPlatform.isLinux then pkgs.pkgsStatic else pkgs;
3132
# this is not perfect for development as it hardcodes solc to 0.5.7, test suite runs fine though
3233
# 0.5.7 is not available on aarch64 darwin so alternatively pick 0.8.5
3334
solc = solc-pkgs.mkDefault pkgs (pkgs.solc_0_5_7 or pkgs.solc_0_8_5);
3435

35-
secp256k1-static = pkgsStatic.secp256k1.overrideAttrs (attrs: {
36+
secp256k1-static = pkgsDeps.secp256k1.overrideAttrs (attrs: {
3637
configureFlags = attrs.configureFlags ++ [ "--enable-static" ];
3738
});
3839

39-
ncurses-static = pkgsStatic.ncurses.override { enableStatic = true; };
40+
ncurses-static = pkgsDeps.ncurses.override { enableStatic = true; };
4041

41-
hsPkgs = ps :
42-
ps.haskellPackages.override {
43-
overrides = hfinal: hprev: {
44-
with-utf8 =
45-
if (with ps.stdenv; hostPlatform.isDarwin && hostPlatform.isx86)
46-
then ps.haskell.lib.compose.overrideCabal (_ : { extraLibraries = [ps.libiconv]; }) hprev.with-utf8
47-
else hprev.with-utf8;
48-
# TODO: temporary fix for static build which is still on 9.4
49-
witch = ps.haskell.lib.doJailbreak hprev.witch;
50-
};
51-
};
42+
dependencies-static = with pkgsDeps; [
43+
(gmp.override { withStatic = true; })
44+
secp256k1-static
45+
(libff.override { enableStatic = true; })
46+
ncurses-static
47+
] ++ lib.optionals (!pkgs.stdenv.hostPlatform.isDarwin) [
48+
# darwin provides these
49+
(zlib.override { static = true; shared = false; })
50+
(libffi.overrideAttrs (_: { dontDisableStatic = true; }))
51+
];
5252

53-
hevm = pkgs: pkgs.lib.pipe ((hsPkgs pkgs).callCabal2nix "hevm" (pkgs.fetchFromGitHub {
54-
owner = "ethereum";
55-
repo = "hevm";
56-
rev = "7fa6a959bea935f476100037aa84531523cd9d8a";
57-
sha256 = "sha256-4dTXB/3F3180L5tBhDVky2A6irbGDN4rZHdnDdc+j64=";
58-
}) { secp256k1 = pkgs.secp256k1; })
59-
([
60-
pkgs.haskell.lib.compose.dontCheck
61-
]);
53+
hevm = pkgs: pkgs.lib.pipe
54+
(pkgs.haskellPackages.callCabal2nix "hevm" (pkgs.fetchFromGitHub {
55+
owner = "ethereum";
56+
repo = "hevm";
57+
rev = "7fa6a959bea935f476100037aa84531523cd9d8a";
58+
sha256 = "sha256-4dTXB/3F3180L5tBhDVky2A6irbGDN4rZHdnDdc+j64=";
59+
}) { secp256k1 = pkgs.secp256k1; })
60+
([
61+
pkgs.haskell.lib.compose.dontCheck
62+
]);
6263

6364
echidna = pkgs: with pkgs; lib.pipe
64-
((hsPkgs pkgs).callCabal2nix "echidna" ./. { hevm = hevm pkgs; })
65+
(haskellPackages.callCabal2nix "echidna" ./. { hevm = hevm pkgs; })
6566
([
6667
# FIXME: figure out solc situation, it conflicts with the one from
6768
# solc-select that is installed with slither, disable tests in the meantime
@@ -70,18 +71,11 @@
7071
(haskell.lib.compose.disableCabalFlag "static")
7172
]);
7273

73-
echidna-static = with pkgsStatic; lib.pipe
74-
(echidna pkgsStatic)
74+
echidna-static = with pkgsGHC; lib.pipe
75+
(echidna pkgsGHC)
7576
[
7677
(haskell.lib.compose.appendConfigureFlags
77-
[
78-
"--extra-lib-dirs=${stripDylib (gmp.override { withStatic = true; })}/lib"
79-
"--extra-lib-dirs=${stripDylib secp256k1-static}/lib"
80-
"--extra-lib-dirs=${stripDylib (libff.override { enableStatic = true; })}/lib"
81-
"--extra-lib-dirs=${zlib.override { static = true; shared = false; }}/lib"
82-
"--extra-lib-dirs=${stripDylib (libffi.overrideAttrs (_: { dontDisableStatic = true; }))}/lib"
83-
"--extra-lib-dirs=${stripDylib (ncurses-static)}/lib"
84-
])
78+
(map (drv: "--extra-lib-dirs=${stripDylib drv}/lib") dependencies-static))
8579
(haskell.lib.compose.enableCabalFlag "static")
8680
];
8781

@@ -100,35 +94,36 @@
10094
in if pkgs.stdenv.isLinux
10195
then pkgs.runCommand "echidna-stripNixRefs" {} ''
10296
mkdir -p $out/bin
103-
cp ${pkgsStatic.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/
97+
cp ${pkgs.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/
10498
# fix TERMINFO path in ncurses
10599
${perl} -i -pe 's#(${ncurses-static}/share/terminfo)#"/etc/terminfo:/lib/terminfo:/usr/share/terminfo:/usr/lib/terminfo" . "\x0" x (length($1) - 65)#e' $out/bin/echidna
106100
chmod 555 $out/bin/echidna
107101
'' else pkgs.runCommand "echidna-stripNixRefs" {} ''
108102
mkdir -p $out/bin
109-
cp ${pkgsStatic.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/
110-
# get the list of dynamic libs from otool and tidy the output
111-
libs=$(${otool} -L $out/bin/echidna | tail -n +2 | sed 's/^[[:space:]]*//' | cut -d' ' -f1)
112-
# get the path for libcxx
113-
cxx=$(echo "$libs" | ${grep} '^/nix/store/.*/libc++\.')
114-
cxxabi=$(echo "$libs" | ${grep} '^/nix/store/.*/libc++abi\.')
115-
iconv=$(echo "$libs" | ${grep} '^/nix/store/.*/libiconv\.')
103+
cp ${pkgs.haskell.lib.dontCheck echidna-static}/bin/echidna $out/bin/
116104
# rewrite /nix/... library paths to point to /usr/lib
117-
chmod 777 $out/bin/echidna
118-
${install_name_tool} -change "$cxx" /usr/lib/libc++.1.dylib $out/bin/echidna
119-
${install_name_tool} -change "$cxxabi" /usr/lib/libc++abi.dylib $out/bin/echidna
120-
${install_name_tool} -change "$iconv" /usr/lib/libiconv.dylib $out/bin/echidna
105+
exe="$out/bin/echidna"
106+
chmod 777 "$exe"
107+
for lib in $(${otool} -L "$exe" | awk '/nix\/store/{ print $1 }'); do
108+
case "$lib" in
109+
*libc++.*.dylib) ${install_name_tool} -change "$lib" /usr/lib/libc++.dylib "$exe" ;;
110+
*libc++abi.*.dylib) ${install_name_tool} -change "$lib" /usr/lib/libc++abi.dylib "$exe" ;;
111+
*libffi.*.dylib) ${install_name_tool} -change "$lib" /usr/lib/libffi.dylib "$exe" ;;
112+
*libiconv.2.dylib) ${install_name_tool} -change "$lib" /usr/lib/libiconv.2.dylib "$exe" ;;
113+
*libz.dylib) ${install_name_tool} -change "$lib" /usr/lib/libz.dylib "$exe" ;;
114+
esac
115+
done
121116
# fix TERMINFO path in ncurses
122117
${perl} -i -pe 's#(${ncurses-static}/share/terminfo)#"/usr/share/terminfo" . "\x0" x (length($1) - 19)#e' $out/bin/echidna
123118
# check that no nix deps remain
124-
nixdeps=$(${otool} -L $out/bin/echidna | tail -n +2 | { ${grep} /nix/store -c || test $? = 1; })
119+
nixdeps=$(${otool} -L "$exe" | tail -n +2 | { ${grep} /nix/store -c || test $? = 1; })
125120
if [ ! "$nixdeps" = "0" ]; then
126121
echo "Nix deps remain in redistributable binary!"
127122
exit 255
128123
fi
129124
# re-sign binary
130-
CODESIGN_ALLOCATE=${codesign_allocate} ${codesign} -f -s - $out/bin/echidna
131-
chmod 555 $out/bin/echidna
125+
CODESIGN_ALLOCATE=${codesign_allocate} ${codesign} -f -s - "$exe"
126+
chmod 555 "$exe"
132127
'';
133128

134129
# if we pass a library folder to ghc via --extra-lib-dirs that contains

0 commit comments

Comments
 (0)