Skip to content

Commit

Permalink
nix: Make bundling of dependencies separate from Haskell.nix build
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Oct 21, 2019
1 parent 28a4c24 commit cc7b2c2
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 42 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
38 changes: 6 additions & 32 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
, cardano-http-bridge

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

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

# Make a postInstall wrapping script to provide dependencies.
# For the windows build, also copy DLL dependencies.
provideDeps = { nix, darwin ? "", windows ? "" }:
with pkgs.stdenv.hostPlatform;
if isWindows then windows else (if isDarwin then darwin else nix);

# 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
Expand Down Expand Up @@ -77,31 +70,12 @@ let
unit.build-tools = [ jormungandr ];
};

packages.cardano-wallet-jormungandr.components.exes.cardano-wallet-jormungandr = {
build-tools = [ pkgs.makeWrapper];
postInstall = provideDeps {
nix = ''
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
'';
};
};

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

packages.cardano-wallet-http-bridge.components.benchmarks.restore = {
Expand Down
2 changes: 1 addition & 1 deletion nix/jormungandr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let
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 = "0dd2b2r50kcwakn61sv7xvf2s1yl586rlk8zch2bpfw9bjqrs0hl";
sha256 = "16pxgi4igvfh2kccsbyizfc4wyxr8fs1872hpsmr99ppna09rqi3";
};

jormungandr-win64 = pkgs.runCommand "jormungandr-win64-${release.version}" {
Expand Down
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}
''
12 changes: 9 additions & 3 deletions nix/windows-release.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
############################################################################
# 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
, jpkgs ? import ./jormungandr.nix { inherit pkgs; }
, jormungandr-win64 ? jpkgs.jormungandr-win64
}:

let
Expand All @@ -21,7 +28,6 @@ in pkgs.runCommand name {
cd jm
cp -v ${cardano-wallet-jormungandr}/bin/* .
cp -v ${jormungandr-win64}/bin/* .
cp -v ${testData}/block0.bin ${testData}/secret.yaml .
cp -v ${jm-bat} jm.bat
hash="$(jcli genesis hash --input block0.bin)"
Expand Down

0 comments on commit cc7b2c2

Please sign in to comment.