From 2a4a064ce098fcc7105440802e77ef50c4b65889 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Wed, 23 Oct 2019 16:25:32 +1000 Subject: [PATCH 1/8] Switch to Haskell.nix overlays release --- default.nix | 20 ++++++--------- nix/default.nix | 23 ++++++----------- nix/dep.nix | 11 +++++++++ nix/haskell-nix-src.json | 7 ++++++ nix/nixpkgs-haskell.nix | 49 +++++++++++++++++++++++++++++++++++++ nix/nixpkgs-src.json | 7 ++++++ nix/package-jormungandr.nix | 7 +++--- 7 files changed, 94 insertions(+), 30 deletions(-) create mode 100644 nix/dep.nix create mode 100644 nix/haskell-nix-src.json create mode 100644 nix/nixpkgs-haskell.nix create mode 100644 nix/nixpkgs-src.json diff --git a/default.nix b/default.nix index a9893a929df..2a20104e553 100644 --- a/default.nix +++ b/default.nix @@ -3,23 +3,20 @@ , config ? {} # Import IOHK common nix lib , iohkLib ? import ./nix/iohk-common.nix { inherit system crossSystem config; } -# Use nixpkgs pin from iohkLib -, pkgs ? iohkLib.pkgs +# Use pinned Nixpkgs with Haskell.nix overlay +, pkgs ? import ./nix/nixpkgs-haskell.nix { inherit system crossSystem config; } }: with import ./nix/util.nix { inherit pkgs; }; let - haskell = iohkLib.nix-tools.haskell { inherit pkgs; }; - src = iohkLib.cleanSourceHaskell ./.; + src = pkgs.haskell-nix.cleanSourceHaskell ./.; - jmPkgs = import ./nix/jormungandr.nix { inherit iohkLib pkgs; }; + jmPkgs = import ./nix/jormungandr.nix { inherit iohkLib; }; inherit (jmPkgs) jormungandr jormungandr-cli; haskellPackages = import ./nix/default.nix { - inherit pkgs haskell src; - inherit jmPkgs; - inherit (iohkLib.nix-tools) iohk-extras iohk-module; + inherit pkgs src jmPkgs; }; inherit (haskellPackages.cardano-wallet-core.identifier) version; @@ -48,10 +45,9 @@ in { bech32 text-class ]; - buildInputs = - with pkgs.haskellPackages; [ stylish-haskell weeder ghcid ] + buildInputs = (with pkgs.haskellPackages; [ weeder ghcid ]) + ++ (with iohkLib; [ hlint stylish-haskell openapi-spec-validator ]) ++ [ jormungandr jormungandr-cli - pkgs.pkgconfig pkgs.sqlite-interactive - iohkLib.hlint iohkLib.openapi-spec-validator ]; + pkgs.pkgconfig pkgs.sqlite-interactive ]; }; } diff --git a/nix/default.nix b/nix/default.nix index 83a7118a36f..ed41394826c 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,21 +1,15 @@ { pkgs -# haskell.nix -, haskell - # Filtered sources of this project , src # Dependencies of cardano-wallet-jormungandr , jmPkgs - -# Customisations for cross-compiling -, iohk-extras ? {} -, iohk-module ? {} - }: let + haskell = pkgs.haskell-nix; + # our packages stack-pkgs = import ./.stack.nix/default.nix; @@ -87,15 +81,14 @@ let # Katip has Win32 (>=2.3 && <2.6) constraint packages.katip.doExactConfig = true; } - - # The iohk-module will supply us with the necessary - # cross compilation plumbing to make Template Haskell - # work when cross compiling. - iohk-module ]; pkg-def-extras = [ - # Use the iohk-extras patched GHC for cross-compiling. - iohk-extras.${compiler} + # Workaround for https://github.com/input-output-hk/haskell.nix/issues/214 + (hackage: { + packages = { + "hsc2hs" = (((hackage.hsc2hs)."0.68.4").revisions).default; + }; + }) ]; }; diff --git a/nix/dep.nix b/nix/dep.nix new file mode 100644 index 00000000000..740cd9e4add --- /dev/null +++ b/nix/dep.nix @@ -0,0 +1,11 @@ +# Provides a function for fetching a GitHub repo from a JSON spec. +{ name, specJSON }: + +let + spec = builtins.fromJSON (builtins.readFile specJSON); +in + builtins.fetchTarball { + inherit name; + url = "${spec.url}/archive/${spec.rev}.tar.gz"; + inherit (spec) sha256; + } diff --git a/nix/haskell-nix-src.json b/nix/haskell-nix-src.json new file mode 100644 index 00000000000..b05ad43b146 --- /dev/null +++ b/nix/haskell-nix-src.json @@ -0,0 +1,7 @@ +{ + "url": "https://github.com/input-output-hk/haskell.nix", + "rev": "4d27798d6d297d3fa764e1104c63c8d10cb95c6d", + "date": "2019-11-02T01:21:30+13:00", + "sha256": "0bvf1d9gh08gl8lw43wv4dv2dpgc7114p3l2nvc6vx0lj3i2bgp9", + "fetchSubmodules": false +} diff --git a/nix/nixpkgs-haskell.nix b/nix/nixpkgs-haskell.nix new file mode 100644 index 00000000000..3fa1a50fab2 --- /dev/null +++ b/nix/nixpkgs-haskell.nix @@ -0,0 +1,49 @@ +############################################################################ +# Nixpkgs 19.03 with Haskell.nix overlay +# +# This works by importing the base Nixpkgs with extra config and +# overlays provided by Haskell.nix. It will contain patched GHCs +# suitable for cross-compiling to Windows, and the `haskell-nix` +# component builder. +# +# To update the Nixpkgs version, use: +# +# nix-prefetch-git https://github.com/NixOS/nixpkgs-channels refs/heads/nixpkgs-19.03-darwin | tee nix/nixpkgs-src.json +# +# This will pick the latest revision on the 19.03 branch. +# +# To update the Haskell.nix version, use: +# +# nix-prefetch-git https://github.com/input-output-hk/haskell.nix | tee nix/haskell-nix-src.json +# +############################################################################ + +# Arguments to pass when importing nixpkgs. +{ system ? builtins.currentSystem +, crossSystem ? null +, config ? {} +}: + +let + haskell-nix-src = import ./dep.nix { + name = "haskell.nix"; + specJSON = ./haskell-nix-src.json; + }; + nixpkgs = import ./dep.nix { + name = "nixpkgs"; + specJSON = ./nixpkgs-src.json; + }; + + haskellNixArgs = import haskell-nix-src; + + # Merge config and overlays provided by Haskell.nix into + # our own nixpkgs args. + args = haskellNixArgs // { + inherit system crossSystem; + config = (haskellNixArgs.config or {}) // config; + overlays = (haskellNixArgs.overlays or []) ++ overlays; + }; + + overlays = []; +in + import nixpkgs args diff --git a/nix/nixpkgs-src.json b/nix/nixpkgs-src.json new file mode 100644 index 00000000000..03e56fe3451 --- /dev/null +++ b/nix/nixpkgs-src.json @@ -0,0 +1,7 @@ +{ + "url": "https://github.com/NixOS/nixpkgs", + "rev": "a8f81dc037a5977414a356dd068f2621b3c89b60", + "date": "2019-10-13T18:41:59-04:00", + "sha256": "01z13axll5g5yl00lz9adr2jw2bs12g9skhbb1vxy8p7fjjbhhhm", + "fetchSubmodules": false +} diff --git a/nix/package-jormungandr.nix b/nix/package-jormungandr.nix index 11761694616..13bc1095e9d 100644 --- a/nix/package-jormungandr.nix +++ b/nix/package-jormungandr.nix @@ -9,9 +9,7 @@ { pkgs , version , cardano-wallet-jormungandr -, jmPkgs ? import ./jormungandr.nix { inherit pkgs; } -, jormungandr ? jmPkgs.jormungandr -, jormungandr-win64 ? jmPkgs.jormungandr-win64 +, jmPkgs }: with pkgs.lib; @@ -19,6 +17,9 @@ with pkgs.lib; let name = "cardano-wallet-jormungandr-${version}"; + jormungandr = jmPkgs.jormungandr; + jormungandr-win64 = jmPkgs.jormungandr-win64; + deps = { nix = '' strip $out/bin/cardano-wallet-jormungandr From 08def31006e595f628b609df32568d3a09089812 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Thu, 24 Oct 2019 15:43:26 +1000 Subject: [PATCH 2/8] nix: Use upstreamed collectComponents --- nix/util.nix | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/nix/util.nix b/nix/util.nix index 6854bf48195..e9a0621ec0a 100644 --- a/nix/util.nix +++ b/nix/util.nix @@ -7,10 +7,5 @@ with pkgs.lib; (hasPrefix "cardano-wallet" package.identifier.name) || (elem package.identifier.name [ "text-class" "bech32" ]); - # TODO: use upstreamed version: - # https://github.com/input-output-hk/haskell.nix/pull/224 - collectComponents = group: packageSel: haskellPackages: - (mapAttrs (_: package: package.components.${group} // { recurseForDerivations = true; }) - (filterAttrs (name: package: (package.isHaskell or false) && packageSel package) haskellPackages)) - // { recurseForDerivations = true; }; + inherit (pkgs.haskell-nix.haskellLib) collectComponents; } From 153be4dcb472ff472736fb5ac2a6ad7345d5acd0 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Thu, 24 Oct 2019 15:44:19 +1000 Subject: [PATCH 3/8] nix: Add cross builds to Hercules-CI --- nix/ci.nix | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/nix/ci.nix b/nix/ci.nix index bb2dab0706b..d04b2b19189 100644 --- a/nix/ci.nix +++ b/nix/ci.nix @@ -2,18 +2,35 @@ # https://hercules-ci.com/github/input-output-hk/cardano-wallet # https://docs.hercules-ci.com/hercules-ci/getting-started/minimal-repository/ -builtins.mapAttrs (system: _: - let - walletPkgs = import ../default.nix { inherit system; }; - in +let + inherit (import ./nixpkgs-haskell.nix {}) lib; + + walletJobs = walletPkgs: walletPkgs.pkgs.recurseIntoAttrs { inherit (walletPkgs) cardano-wallet-jormungandr tests benchmarks; - } -) { - x86_64-linux = {}; - # Uncomment to test build on macOS too - # x86_64-darwin = {}; -} + }; + + nativeBuilds = builtins.mapAttrs (system: _: + walletJobs (import ../default.nix { inherit system; }) + ) { + x86_64-linux = {}; + # Uncomment to test build on macOS too + # x86_64-darwin = {}; + }; + + crossSystems = with lib.systems.examples; + [ mingwW64 ]; + + crossBuilds = lib.listToAttrs (map (crossSystem: { + name = crossSystem.config; + value = walletJobs (import ../default.nix { + system = "x86_64-linux"; + inherit crossSystem; + }); + }) crossSystems); + +in + nativeBuilds // crossBuilds From 43ad7163a02bedb976852fd8757d094283710cb7 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Thu, 24 Oct 2019 16:58:52 +1000 Subject: [PATCH 4/8] nix: Cross build fixes --- nix/package-jormungandr.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/package-jormungandr.nix b/nix/package-jormungandr.nix index 13bc1095e9d..994c4af6b2a 100644 --- a/nix/package-jormungandr.nix +++ b/nix/package-jormungandr.nix @@ -31,7 +31,7 @@ let ''; windows = '' cp -v ${pkgs.libffi}/bin/libffi-6.dll $out/bin - cp ${jormungandr-win64}/* $out/bin + cp ${jormungandr-win64}/bin/* $out/bin ''; }; provideDeps = { nix, darwin ? "", windows ? "" }: @@ -40,7 +40,7 @@ let in pkgs.runCommand name { inherit version; - nativeBuildInputs = [ pkgs.makeWrapper pkgs.binutils ]; + nativeBuildInputs = [ pkgs.buildPackages.makeWrapper pkgs.buildPackages.binutils ]; } '' cp -R ${cardano-wallet-jormungandr} $out chmod -R +w $out From 90306e134ba613b8e551dd84b4eff6fd9e9a6503 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Thu, 24 Oct 2019 18:51:01 +1000 Subject: [PATCH 5/8] nix: Work around evaluation error in shell --- default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index 2a20104e553..564c883439d 100644 --- a/default.nix +++ b/default.nix @@ -45,8 +45,8 @@ in { bech32 text-class ]; - buildInputs = (with pkgs.haskellPackages; [ weeder ghcid ]) - ++ (with iohkLib; [ hlint stylish-haskell openapi-spec-validator ]) + buildInputs = (with iohkLib.pkgs.haskellPackages; [ stylish-haskell weeder ghcid ]) + ++ (with iohkLib; [ hlint openapi-spec-validator ]) ++ [ jormungandr jormungandr-cli pkgs.pkgconfig pkgs.sqlite-interactive ]; }; From 8a2c104c9c1dd8a64d5a5fa725296c2aa47a8739 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Thu, 24 Oct 2019 19:06:58 +1000 Subject: [PATCH 6/8] nix: Include tests and updated .BAT files in the Windows bundle --- nix/windows-release.nix | 24 +++++++++++++++++++++--- release.nix | 2 ++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/nix/windows-release.nix b/nix/windows-release.nix index 653242b64a7..6df29750499 100644 --- a/nix/windows-release.nix +++ b/nix/windows-release.nix @@ -8,8 +8,10 @@ ############################################################################ { pkgs -, cardano-wallet-jormungandr , project +, cardano-wallet-jormungandr +, tests ? [] +, benchmarks ? [] }: let @@ -19,10 +21,15 @@ let jormungandr.exe --config config.yaml --genesis-block block0.bin --secret secret.yaml ''; cw-bat = pkgs.writeText "cw.bat" '' - cardano-wallet-jormungandr.exe serve --node-port 8081 --genesis-hash HASH --database c:\\cardano-wallet-jormungandr\\wallet.db + cardano-wallet-jormungandr.exe serve --node-port 8080 --genesis-block-hash HASH --database c:\\cardano-wallet-jormungandr\\wallets + ''; + launch-bat = pkgs.writeText "launch.bat" '' + cardano-wallet-jormungandr.exe launch --genesis-block-hash HASH --state-dir c:\\cardano-wallet-jormungandr %* ''; + in pkgs.runCommand name { nativeBuildInputs = [ pkgs.zip pkgs.jq pkgs.gnused project.jormungandr-cli ]; + passthru = { inherit tests benchmarks; }; } '' mkdir -pv jm $out/nix-support cd jm @@ -32,8 +39,19 @@ in pkgs.runCommand name { cp -v ${jm-bat} jm.bat hash="$(jcli genesis hash --input block0.bin)" sed -e "s/HASH/$hash/" ${cw-bat} > cw.bat - sed -e 's/storage:.*/storage: "c:\\\\cardano-wallet-jormungandr\\\\storage"/' \ + sed -e "s/HASH/$hash/" ${launch-bat} > launch.bat + sed -e 's/storage:.*/storage: "c:\\\\cardano-wallet-jormungandr\\\\chain"/' \ ${testData}/config.yaml > config.yaml + + ${pkgs.lib.concatMapStringsSep "\n" (test: '' + pkg=`ls -1 ${test}` + exe=`cd ${test}; ls -1 $pkg` + name=$pkg-test-$exe + cp ${test}/$pkg/$exe $name + echo $name >> tests.bat + echo "if %errorlevel% neq 0 exit /b %errorlevel%" >> tests.bat + '') tests} + chmod -R +w . zip -r $out/${name}.zip . diff --git a/release.nix b/release.nix index d9d54beac99..4a6b6633c0b 100644 --- a/release.nix +++ b/release.nix @@ -39,6 +39,8 @@ let cardano-wallet-jormungandr-win64 = import ./nix/windows-release.nix { inherit pkgs project; cardano-wallet-jormungandr = jobs.x86_64-pc-mingw32.cardano-wallet-jormungandr.x86_64-linux; + tests = collectTests jobs.x86_64-pc-mingw32.tests; + benchmarks = collectTests jobs.x86_64-pc-mingw32.benchmarks; }; # These derivations are used for the Daedalus installer. From 6f425fa9278948f3372720e8959be965416dce59 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Mon, 28 Oct 2019 14:54:11 +1000 Subject: [PATCH 7/8] Update to PR input-output-hk/haskell.nix#289 branch Fixes stack stack/nix build errors resulting from Haskell.nix update. --- default.nix | 2 +- nix/haskell-nix-src.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/default.nix b/default.nix index 564c883439d..ffd96a95e3e 100644 --- a/default.nix +++ b/default.nix @@ -45,7 +45,7 @@ in { bech32 text-class ]; - buildInputs = (with iohkLib.pkgs.haskellPackages; [ stylish-haskell weeder ghcid ]) + buildInputs = (with pkgs.haskellPackages; [ stylish-haskell weeder ghcid ]) ++ (with iohkLib; [ hlint openapi-spec-validator ]) ++ [ jormungandr jormungandr-cli pkgs.pkgconfig pkgs.sqlite-interactive ]; diff --git a/nix/haskell-nix-src.json b/nix/haskell-nix-src.json index b05ad43b146..69fe1343733 100644 --- a/nix/haskell-nix-src.json +++ b/nix/haskell-nix-src.json @@ -1,7 +1,7 @@ { "url": "https://github.com/input-output-hk/haskell.nix", - "rev": "4d27798d6d297d3fa764e1104c63c8d10cb95c6d", - "date": "2019-11-02T01:21:30+13:00", - "sha256": "0bvf1d9gh08gl8lw43wv4dv2dpgc7114p3l2nvc6vx0lj3i2bgp9", + "rev": "fcba9447b31a0802fab15f46fa18d6b9675ab528", + "date": "2019-11-02T21:33:00+13:00", + "sha256": "0s7gdcjxv8y7bmbi7wd5cp8jlvdcn2bgf8kaqyy25x0bqcdafaz3", "fetchSubmodules": false } From d27da42d44a9095786e70eb2bdd448a2f08283f6 Mon Sep 17 00:00:00 2001 From: Michael Bishop Date: Mon, 4 Nov 2019 09:03:40 -0400 Subject: [PATCH 8/8] improve CI times by pre-building stylish-haskell on hydra --- .buildkite/pipeline.yml | 4 ++-- release.nix | 6 ++++++ shell.nix | 9 ++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index ff75a5f5cce..8856b07e2a4 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -21,12 +21,12 @@ steps: system: x86_64-linux - label: 'Check Stylish Haskell' - command: 'nix-shell --run .buildkite/check-stylish.sh' + command: 'nix-shell -A ci-shell --run .buildkite/check-stylish.sh' agents: system: x86_64-linux - label: 'HLint' - command: 'nix-shell --run "hlint lib"' + command: 'nix-shell -A ci-shell --run "hlint lib"' agents: system: x86_64-linux diff --git a/release.nix b/release.nix index 4a6b6633c0b..b45a7d0dfcb 100644 --- a/release.nix +++ b/release.nix @@ -25,6 +25,12 @@ let "${mingwW64.config}" = mapTestOnCross mingwW64 (packagePlatformsCross project); } // { + ci-tools = { + inherit (import ./nix/iohk-common.nix {}) hlint; + inherit ((import ./nix/nixpkgs-haskell.nix {}).haskellPackages) stylish-haskell; + }; + inherit ((import ./. {}).pkgs.haskell-nix) haskellNixRoots; + # This aggregate job is what IOHK Hydra uses to update # the CI status in GitHub. required = mkRequiredJob ( diff --git a/shell.nix b/shell.nix index 82fb296083f..2812f2248e4 100644 --- a/shell.nix +++ b/shell.nix @@ -1 +1,8 @@ -(import ./default.nix {}).shell +let + self = import ./default.nix {}; + # a shell that only has basic CI tools, and no dependencies + ci-shell = self.pkgs.stdenv.mkDerivation { + name = "ci-shell"; + buildInputs = [ self.pkgs.haskellPackages.stylish-haskell self.iohkLib.hlint ]; + }; +in self.shell // { inherit ci-shell; }