Skip to content

Commit

Permalink
Merge #864
Browse files Browse the repository at this point in the history
864: nix: Provide derivations for Daedalus installer r=KtorZ a=rvl

Relates to #863.
Based on #828.

# Overview

- @disassembler @cleverca22 It's not exactly the same as before but should work ok I think.
- Adds source filtering to avoid unnecessary rebuilds.

# Comments

To build:

```
nix-build -A cardano-wallet-jormungandr
nix-build release.nix -A daedalus-jormungandr.windows -o daedalus-jormungandr-windows
nix-build release.nix -A daedalus-jormungandr.macos -o daedalus-jormungandr-macos
nix-build release.nix -A daedalus-jormungandr.linux -o daedalus-jormungandr-linux
```

Note that `daedalus-jormungandr.{windows,macos,linux}` from `release.nix` reference the same `cardano-wallet-jormungandr` derivation, only with different `system` or `crossSystem` arguments. So Daedalus may also import from `default.nix` rather than `release.nix`.

Co-authored-by: Rodney Lorrimar <[email protected]>
  • Loading branch information
iohk-bors[bot] and rvl authored Oct 22, 2019
2 parents 5231e58 + cc7b2c2 commit fbc0d05
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 66 deletions.
16 changes: 10 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ let
haskell = iohkLib.nix-tools.haskell { inherit pkgs; };
src = iohkLib.cleanSourceHaskell ./.;

inherit (import ./nix/jormungandr.nix { inherit iohkLib pkgs; })
jormungandr jormungandr-cli;
jmPkgs = import ./nix/jormungandr.nix { inherit iohkLib pkgs; };
inherit (jmPkgs) jormungandr jormungandr-cli;

cardano-http-bridge = iohkLib.rust-packages.pkgs.callPackage
./nix/cardano-http-bridge.nix { inherit pkgs; };
Expand All @@ -26,15 +26,19 @@ let
inherit (iohkLib.nix-tools) iohk-extras iohk-module;
};

inherit (haskellPackages.cardano-wallet-core.identifier) version;
in {
inherit pkgs iohkLib src haskellPackages;
inherit pkgs iohkLib src haskellPackages version;
inherit cardano-http-bridge cardano-sl-node jormungandr jormungandr-cli;
inherit (haskellPackages.cardano-wallet-core.identifier) version;

inherit (haskellPackages.cardano-wallet-http-bridge.components.exes)
cardano-wallet-http-bridge;
inherit (haskellPackages.cardano-wallet-jormungandr.components.exes)
cardano-wallet-jormungandr;

cardano-wallet-jormungandr = import ./nix/package-jormungandr.nix {
inherit (haskellPackages.cardano-wallet-jormungandr.components.exes)
cardano-wallet-jormungandr;
inherit pkgs jmPkgs version;
};

tests = collectComponents "tests" isCardanoWallet haskellPackages;
benchmarks = collectComponents "benchmarks" isCardanoWallet haskellPackages;
Expand Down
51 changes: 25 additions & 26 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
# Test dependencies of cardano-wallet
, cardano-sl-node
, cardano-http-bridge
, jormungandr

# Dependencies of cardano-wallet-jormungandr
, jmPkgs ? import ./jormungandr.nix { inherit pkgs; }
, jormungandr ? jmPkgs.jormungandr

# Customisations for cross-compiling
, iohk-extras ? {}
Expand All @@ -24,27 +27,32 @@ let
# Grab the compiler name from stack-to-nix output.
compiler = (stack-pkgs.extras {}).compiler.nix-name;

# Use a postInstall wrapping script if this is not a windows
# build. Otherwise, copy DLL dependencies.
wrapForPosix = postInstall: if pkgs.stdenv.hostPlatform.isWindows
then ''
cp -v ${pkgs.libffi}/bin/libffi-6.dll $out/bin
'' else postInstall;
# Chop out a subdirectory of the source, so that the package is only
# rebuilt when something in the subdirectory changes.
filterSubDir = dir: with pkgs.lib; let
isFiltered = src ? _isLibCleanSourceWith;
origSrc = if isFiltered then src.origSrc else src;
in cleanSourceWith {
inherit src;
filter = path: type:
type == "directory" ||
hasPrefix (toString origSrc + toString dir) path;
} + dir;

pkgSet = haskell.mkStackPkgSet {
inherit stack-pkgs;
modules = [
# Add source filtering to local packages
{
packages.cardano-wallet-core.src = src + /lib/core;
packages.cardano-wallet-core-integration.src = src + /lib/core-integration;
packages.cardano-wallet-cli.src = src + /lib/cli;
packages.cardano-wallet-launcher.src = src + /lib/launcher;
packages.cardano-wallet-http-bridge.src = src + /lib/http-bridge;
packages.cardano-wallet-jormungandr.src = src + /lib/jormungandr;
packages.cardano-wallet-test-utils.src = src + /lib/test-utils;
packages.text-class.src = src + /lib/text-class;
packages.bech32.src = src + /lib/bech32;
packages.cardano-wallet-core.src = filterSubDir /lib/core;
packages.cardano-wallet-core-integration.src = filterSubDir /lib/core-integration;
packages.cardano-wallet-cli.src = filterSubDir /lib/cli;
packages.cardano-wallet-launcher.src = filterSubDir /lib/launcher;
packages.cardano-wallet-http-bridge.src = filterSubDir /lib/http-bridge;
packages.cardano-wallet-jormungandr.src = filterSubDir /lib/jormungandr;
packages.cardano-wallet-test-utils.src = filterSubDir /lib/test-utils;
packages.text-class.src = filterSubDir /lib/text-class;
packages.bech32.src = filterSubDir /lib/bech32;
}

# Add dependencies
Expand All @@ -62,18 +70,9 @@ let
unit.build-tools = [ jormungandr ];
};


packages.cardano-wallet-jormungandr.components.exes.cardano-wallet-jormungandr = {
build-tools = [ pkgs.makeWrapper];
postInstall = wrapForPosix ''
wrapProgram $out/bin/cardano-wallet-jormungandr \
--prefix PATH : ${jormungandr}/bin
'';
};

packages.cardano-wallet-http-bridge.components.exes.cardano-wallet-http-bridge = {
build-tools = [ pkgs.makeWrapper];
postInstall = wrapForPosix ''
postInstall = ''
wrapProgram $out/bin/cardano-wallet-http-bridge \
--prefix PATH : ${cardano-http-bridge}/bin
'';
Expand Down
24 changes: 22 additions & 2 deletions nix/jormungandr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,27 @@ let
cargoSha256 = "1kba65rnm2vyqsjhcnfwy1m44x1w3xxlzinykmb89jy6qr8gvp42";
};

windows = rec {
# URL and hash of windows binary release
url = "https://github.com/input-output-hk/jormungandr/releases/download/v${release.version}/jormungandr-v${release.version}-x86_64-pc-windows-msvc.zip";
sha256 = "16pxgi4igvfh2kccsbyizfc4wyxr8fs1872hpsmr99ppna09rqi3";
};

jormungandr-win64 = pkgs.runCommand "jormungandr-win64-${release.version}" {
nativeBuildInputs = [ pkgs.buildPackages.unzip ];
} ''
mkdir -p $out/bin
cd $out/bin
unzip ${pkgs.fetchurl windows}
'';

nonWindows = pkg: if pkgs.stdenv.hostPlatform.isWindows
then jormungandr-win64
else pkg;

in {
jormungandr = iohkLib.rust-packages.pkgs.makeJormungandr release;
jormungandr-cli = iohkLib.rust-packages.pkgs.makeJcli release;
jormungandr = nonWindows (iohkLib.rust-packages.pkgs.makeJormungandr release);
jormungandr-cli = nonWindows (iohkLib.rust-packages.pkgs.makeJcli release);

inherit jormungandr-win64;
}
48 changes: 48 additions & 0 deletions nix/package-jormungandr.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
############################################################################
# Release package for cardano-wallet-jormungandr
#
# This makes release builds of cardano-wallet-jormungandr and bundles
# dependencies as required for different systems.
#
############################################################################

{ pkgs
, version
, cardano-wallet-jormungandr
, jmPkgs ? import ./jormungandr.nix { inherit pkgs; }
, jormungandr ? jmPkgs.jormungandr
, jormungandr-win64 ? jmPkgs.jormungandr-win64
}:

with pkgs.lib;

let
name = "cardano-wallet-jormungandr-${version}";

deps = {
nix = ''
strip $out/bin/cardano-wallet-jormungandr
wrapProgram $out/bin/cardano-wallet-jormungandr \
--prefix PATH : ${jormungandr}/bin
'';
darwin = ''
cp ${jormungandr}/bin/* $out/bin
'';
windows = ''
cp -v ${pkgs.libffi}/bin/libffi-6.dll $out/bin
cp ${jormungandr-win64}/* $out/bin
'';
};
provideDeps = { nix, darwin ? "", windows ? "" }:
with pkgs.stdenv.hostPlatform;
if isWindows then windows else (if isDarwin then darwin else nix);

in pkgs.runCommand name {
inherit version;
nativeBuildInputs = [ pkgs.makeWrapper pkgs.binutils ];
} ''
cp -R ${cardano-wallet-jormungandr} $out
chmod -R +w $out
${provideDeps deps}
''
41 changes: 41 additions & 0 deletions nix/windows-release.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
############################################################################
# Windows release CARDAN~1.ZIP
#
# This bundles up the windows build and its dependencies, adds an
# example self-node configuration, and some .BAT files for launching,
# and sets up the Hydra build artifact.
#
############################################################################

{ pkgs
, cardano-wallet-jormungandr
, project
}:

let
testData = ../lib/jormungandr/test/data/jormungandr;
name = "cardano-wallet-jormungandr-${project.version}-win64";
jm-bat = pkgs.writeText "jm.bat" ''
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
'';
in pkgs.runCommand name {
nativeBuildInputs = [ pkgs.zip pkgs.jq pkgs.gnused project.jormungandr-cli ];
} ''
mkdir -pv jm $out/nix-support
cd jm
cp -v ${cardano-wallet-jormungandr}/bin/* .
cp -v ${testData}/block0.bin ${testData}/secret.yaml .
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"/' \
${testData}/config.yaml > config.yaml
chmod -R +w .
zip -r $out/${name}.zip .
echo "file binary-dist $out/${name}.zip" > $out/nix-support/hydra-build-products
''
44 changes: 12 additions & 32 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,18 @@ let
]
);

cardano-wallet-jormungandr-win64 = let
jm = pkgs.fetchurl {
url = https://github.com/input-output-hk/jormungandr/releases/download/v0.3.3/jormungandr-v0.3.3-x86_64-pc-windows-msvc.zip;
sha256 = "0psva16vq86gcld701k0fi6kk1ydnm2q3yd2mdgflb0x8zpm2i3g";
};
testData = ./lib/jormungandr/test/data/jormungandr;
name = "cardano-wallet-jormungandr-${project.version}-win64.zip";
jm-bat = pkgs.writeText "jm.bat" ''
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-block-hash HASH --database c:\\cardano-wallet-jormungandr\\wallets
'';
in pkgs.runCommand "cardano-wallet-jormungandr-win64" {
buildInputs = [ pkgs.zip pkgs.unzip pkgs.jq pkgs.gnused project.jormungandr-cli ];
} ''
mkdir -pv jm $out/nix-support
cd jm
cp -v ${jobs.x86_64-pc-mingw32.cardano-wallet-jormungandr.x86_64-linux}/bin/* .
unzip ${jm}
cp -v ${testData}/block0.bin ${testData}/secret.yaml .
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"/' \
${testData}/config.yaml > config.yaml
chmod -R +w .
zip -r $out/${name} .
echo "file binary-dist $out/${name}" > $out/nix-support/hydra-build-products
'';
# This is used for testing the build on windows.
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;
};

# These derivations are used for the Daedalus installer.
daedalus-jormungandr = with jobs; {
linux = native.cardano-wallet-jormungandr.x86_64-linux;
macos = native.cardano-wallet-jormungandr.x86_64-darwin;
windows = x86_64-pc-mingw32.cardano-wallet-jormungandr.x86_64-linux;
};
}
# Build the shell derivation in Hydra so that all its dependencies
# are cached.
Expand Down

0 comments on commit fbc0d05

Please sign in to comment.