Move all nix stuff to flake, use nix-bundle-exe for macOS release (#851)

* Move all nix stuff to flake, use nix-bundle-exe for macOS release

* Fix linux build
This commit is contained in:
Artur Cygan
2022-11-22 03:00:05 +01:00
committed by GitHub
parent b70141510b
commit 0b4e1e7124
4 changed files with 123 additions and 140 deletions
+8 -90
View File
@@ -1,90 +1,8 @@
{ pkgs ? import (builtins.fetchTarball {
name = "nixpkgs-unstable-2022-11-15";
url = "https://github.com/nixos/nixpkgs/archive/97b8d9459f7922ce0e666113a1e8e6071424ae16.tar.gz";
sha256 = "sha256:0nhmvgy2w4d9dxx4jvsy5hhzk29h8bb5z0850bdh82a3k157dnxc";
}) {},
profiling ? false,
tests ? false
}:
let
# this is not perfect for development as it hardcodes solc to 0.5.7, test suite runs fine though
# would be great to integrate solc-select to be more flexible, improve this in future
solc = pkgs.stdenv.mkDerivation {
name = "solc";
src = if pkgs.stdenv.isDarwin then
pkgs.fetchurl {
url = "https://binaries.soliditylang.org/macosx-amd64/solc-macosx-amd64-v0.5.7+commit.6da8b019";
sha256 = "095mlw5x9lpdcdl9jzlvkvw46ag03xr4nj4vly4hgn92rgivimm7";
}
else
pkgs.fetchurl {
url = "https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.5.7+commit.6da8b019";
sha256 = "0dsvzck5jh8rvdxs7zyn2ga9hif024msx8gr8ifgj4cmyb7m4341";
};
phases = ["installPhase" "patchPhase"];
installPhase = ''
mkdir -p $out/bin
cp $src $out/bin/solc
chmod +x $out/bin/solc
'';
};
v = "2.0.3";
testInputs = [ pkgs.slither-analyzer solc ];
f = { mkDerivation, aeson, ansi-terminal, base, base16-bytestring, binary
, brick, bytestring, containers, data-dword, data-has, deepseq
, directory, exceptions, filepath, hashable, hevm, hpack, html-entities
, lens, lens-aeson, MonadRandom, mtl, optparse-applicative, process
, random, semver, tasty, tasty-hunit, tasty-quickcheck, temporary, text
, transformers, unix, unliftio, unordered-containers, vector
, vector-instances, vty, word8, yaml, extra, ListLike
}:
mkDerivation rec {
pname = "echidna";
version = v;
src = ./.;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
aeson ansi-terminal base base16-bytestring binary brick bytestring
containers data-dword data-has deepseq directory exceptions
filepath hashable hevm html-entities lens lens-aeson ListLike
MonadRandom mtl optparse-applicative process random semver temporary
text transformers unix unliftio unordered-containers vector
vector-instances vty word8 yaml extra ListLike
] ++ (if pkgs.lib.inNixShell then testHaskellDepends else []);
executableHaskellDepends = libraryHaskellDepends;
testHaskellDepends = [ tasty tasty-hunit tasty-quickcheck ];
testToolDepends = testInputs;
configureFlags = if profiling then [ "--enable-profiling" "--enable-library-profiling" ] else [];
libraryToolDepends = [ hpack pkgs.slither-analyzer solc ];
preConfigure = ''
hpack
# re-enable dynamic build for Linux
sed -i -e 's/os(linux)/false/' echidna.cabal
'';
license = pkgs.lib.licenses.agpl3;
doHaddock = false;
doCheck = tests;
mainProgram = "echidna-test";
};
echidna = pkgs.haskellPackages.callPackage f { };
echidnaShell = pkgs.haskellPackages.shellFor {
packages = p: [ echidna ];
shellHook = "hpack";
buildInputs = with pkgs.haskellPackages; [
hlint
cabal-install
] ++ pkgs.lib.optional (!pkgs.stdenv.isAarch64) [
# this doesn't work due to ormolu not building
haskell-language-server
];
nativeBuildInputs = if tests then [] else testInputs;
};
in
if pkgs.lib.inNixShell
then echidnaShell
else pkgs.haskell.lib.justStaticExecutables echidna
(import (
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
})
{ src = ./.; }
).defaultNix
Generated
+53 -3
View File
@@ -1,12 +1,59 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1668681692,
"narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "009399224d5e398d03b22badca40a37ac85412a1",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nix-bundle-exe": {
"flake": false,
"locked": {
"lastModified": 1660176694,
"narHash": "sha256-cJGZ/3CjVkoyk1W9mFVs6P/5LbJ8C+42chGYiB/wB/A=",
"owner": "3noch",
"repo": "nix-bundle-exe",
"rev": "91416cec283a33ae3448aacdc5cabdece9c08793",
"type": "github"
},
"original": {
"owner": "3noch",
"repo": "nix-bundle-exe",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1668462796,
"narHash": "sha256-MdQVi7GvWqTY5vldTC+HDNm6sEKl89MBbesudjwEkgo=",
"lastModified": 1669063728,
"narHash": "sha256-xkaGi5mXSfRUjNCzbyBX2AOuweg14sNMRqawpO/GJCU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b3a285628a6928f62cdf4d09f4e656f7ecbbcafb",
"rev": "aee7510bf1c4942b3ce0f73ed69476c21b896fc4",
"type": "github"
},
"original": {
@@ -17,6 +64,9 @@
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nix-bundle-exe": "nix-bundle-exe",
"nixpkgs": "nixpkgs"
}
}
+62 -15
View File
@@ -5,21 +5,68 @@
};
inputs = {
nixpkgs.url = github:NixOS/nixpkgs;
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
nix-bundle-exe = {
url = "github:3noch/nix-bundle-exe";
flake = false;
};
};
outputs = { self, nixpkgs }: {
defaultPackage.x86_64-linux = import ./. {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
};
defaultPackage.aarch64-linux = import ./. {
pkgs = nixpkgs.legacyPackages.aarch64-linux;
};
defaultPackage.x86_64-darwin = import ./. {
pkgs = nixpkgs.legacyPackages.x86_64-darwin;
};
defaultPackage.aarch64-darwin = import ./. {
pkgs = nixpkgs.legacyPackages.aarch64-darwin;
};
};
outputs = { self, nixpkgs, flake-utils, nix-bundle-exe, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
# this is not perfect for development as it hardcodes solc to 0.5.7, test suite runs fine though
# would be great to integrate solc-select to be more flexible, improve this in future
solc = pkgs.stdenv.mkDerivation {
name = "solc";
src = if pkgs.stdenv.isDarwin then
pkgs.fetchurl {
url = "https://binaries.soliditylang.org/macosx-amd64/solc-macosx-amd64-v0.5.7+commit.6da8b019";
sha256 = "095mlw5x9lpdcdl9jzlvkvw46ag03xr4nj4vly4hgn92rgivimm7";
}
else
pkgs.fetchurl {
url = "https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.5.7+commit.6da8b019";
sha256 = "0dsvzck5jh8rvdxs7zyn2ga9hif024msx8gr8ifgj4cmyb7m4341";
};
phases = ["installPhase" "patchPhase"];
installPhase = ''
mkdir -p $out/bin
cp $src $out/bin/solc
chmod +x $out/bin/solc
'';
};
echidna = with pkgs; lib.pipe
(haskellPackages.callCabal2nix "echidna" ./. {})
[
(haskell.lib.compose.addTestToolDepends [ haskellPackages.hpack slither-analyzer solc ])
(haskell.lib.compose.disableCabalFlag "static")
];
in rec {
packages.echidna = echidna;
packages.default = echidna;
packages.echidna-bundle =
pkgs.callPackage nix-bundle-exe {} (pkgs.haskell.lib.dontCheck echidna);
devShell = with pkgs;
haskellPackages.shellFor {
packages = _: [ echidna ];
shellHook = "hpack";
buildInputs = [
solc
haskellPackages.hlint
haskellPackages.cabal-install
haskellPackages.haskell-language-server
];
withHoogle = true;
};
}
);
}
-32
View File
@@ -1,32 +0,0 @@
{ tests ? false }:
let
pkgs = import (builtins.fetchTarball {
name = "nixpkgs-unstable-2022-02-10";
url = "https://github.com/nixos/nixpkgs/archive/1882c6b7368fd284ad01b0a5b5601ef136321292.tar.gz";
sha256 = "sha256:0zg7ak2mcmwzi2kg29g4v9fvbvs0viykjsg2pwaphm1fi13s7s0i";
}) {};
echidna = import ./. { inherit tests; };
in
with pkgs; runCommand "echidna-${echidna.version}-bundled-dylibs" {
buildInputs = [
macdylibbundler
darwin.sigtool
darwin.cctools
perl
];
} ''
mkdir -p $out/bin
cp ${echidna}/bin/echidna-test $out/bin/echidna-test
chmod 755 $out/bin/echidna-test
dylibbundler -b \
-x $out/bin/echidna-test \
-d $out/bin \
-p '@executable_path'
# fix TERMINFO path in ncurses binary
perl -i -pe 's#(${pkgs.ncurses}/share/terminfo)#"/usr/share/terminfo" . "\x0" x (length($1) - 19)#e' $out/bin/libncursesw.6.dylib
# re-sign the binaries since the load paths were modified
codesign -s - -f $out/bin/*
tar -czvf $out/echidna-${echidna.version}-${stdenv.system}.tar.gz -C $out/bin .
''