Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an example daedalus-bridge #828

Closed
wants to merge 15 commits into from
Closed
46 changes: 38 additions & 8 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{ system ? builtins.currentSystem
, crossSystem ? null
, config ? {}
# Import IOHK common nix lib
, iohkLib ? import ./nix/iohk-common.nix { inherit system crossSystem config; }
# Use nixpkgs pin from iohkLib
, pkgs ? iohkLib.pkgs
{ config ? {}
, target ? builtins.currentSystem
, backend ? "jormungandr" # TODO, make this work: cardano or jormungandr
}:

with import ./nix/util.nix { inherit pkgs; };

let
commonLib = import ./lib.nix {};
lib = commonLib.pkgs.lib;
systemTable = {
x86_64-windows = builtins.currentSystem;
};
crossSystemTable = {
x86_64-windows = lib.systems.examples.mingwW64;
};
system = systemTable.${target} or target;
crossSystem = crossSystemTable.${target} or null;
# Import IOHK common nix lib
iohkLib = import ./lib.nix { inherit system crossSystem config; };
# Use nixpkgs pin from iohkLib
pkgs = iohkLib.pkgs;
in
with import ./nix/util.nix { inherit pkgs; };
let
haskell = iohkLib.nix-tools.haskell { inherit pkgs; };
src = iohkLib.cleanSourceHaskell ./.;
Expand Down Expand Up @@ -39,6 +51,8 @@ in {
tests = collectComponents "tests" isCardanoWallet haskellPackages;
benchmarks = collectComponents "benchmarks" isCardanoWallet haskellPackages;

daedalus-bridge = import ./nix/daedalus-bridge.nix { inherit target pkgs haskellPackages system crossSystem jormungandr jormungandr-cli; };

shell = haskellPackages.shellFor {
name = "cardano-wallet-shell";
packages = ps: with ps; [
Expand All @@ -58,4 +72,20 @@ in {
pkgs.pkgconfig pkgs.sqlite-interactive
iohkLib.hlint iohkLib.openapi-spec-validator ];
};
devopsShell = pkgs.stdenv.mkDerivation {
name = "devops-shell";
buildInputs = [ iohkLib.niv ];
shellHook = ''
echo "DevOps Tools" \
| ${pkgs.figlet}/bin/figlet -f banner -c \
| ${pkgs.lolcat}/bin/lolcat

echo "NOTE: you may need to export GITHUB_TOKEN if you hit rate limits with niv"
echo "Commands:
* niv update <package> - update package

"
'';

};
}
11 changes: 11 additions & 0 deletions lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ ... }@args:

let
sources = import ./nix/sources.nix;
iohkNix = import sources.iohk-nix (args // { nixpkgsOverride = import sources.nixpkgs args; });
niv = (import sources.niv {}).niv;
jormungandrLib = import (sources.jormungandr-nix + "/lib.nix");
in
iohkNix.pkgs.lib // iohkNix // {
inherit sources niv jormungandrLib;
}
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ waitForNetwork nw policy = do
-- for no longer than a minute.
defaultRetryPolicy :: Monad m => RetryPolicyM m
defaultRetryPolicy =
limitRetriesByCumulativeDelay (60 * second) (exponentialBackoff 10000)
limitRetriesByCumulativeDelay (3600 * second) (exponentialBackoff 10000)
Copy link
Contributor Author

@cleverca22 cleverca22 Oct 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be lowered (or undone), once we are updated to include input-output-hk/jormungandr#977

Copy link
Member

@KtorZ KtorZ Oct 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We (We = me tomorrow) are actually going to change the start-up logic. Right now, you can't start the wallet if there's no backend to connect to, but that's bonkers. The wallet can simply wait an poll regularly until a backend shows up; so this whole timeout will go away here. Maybe not.

where
second = 1000*1000

Expand Down
4 changes: 2 additions & 2 deletions lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ withJormungandr tr (JormungandrConfig stateDir block0 mPort logSeverity output e
startBackend (apiPort, baseUrl) = getGenesisBlockArg block0 >>= \case
Right (block0H, genesisBlockArg) -> do
let args = genesisBlockArg ++
[ "--config", nodeConfigFile
, "--log-level", C.toLower <$> show logSeverity
[ -- "--config", nodeConfigFile
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cardano-wallet should generate a config file with trusted peers, containing IP and ID (public key) pairs

without that, there is no way for jormungandr to sync, and daedalus cant specify its own --config file, because jormungandr crashes if you give it 2 --config flags

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming with #850

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wallet should also pass --rest-listen to jormungandr (or embedit into nodeConfigFile), based on the --node-port the wallet receives

"--log-level", C.toLower <$> show logSeverity
] ++ map T.unpack extraArgs
let cmd = Command "jormungandr" args (return ()) output
let tr' = transformLauncherTrace tr
Expand Down
33 changes: 33 additions & 0 deletions nix/daedalus-bridge.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{ target, pkgs, haskellPackages, system, crossSystem, jormungandr, jormungandr-cli }:

let
commonLib = import ../lib.nix {};
pkgsCross = commonLib.getPkgs { crossSystem = pkgs.lib.systems.examples.mingwW64; };
cardano-shell = import commonLib.sources.cardano-shell { inherit system crossSystem; }; # todo, shell should accept target
jormungandrConfig = builtins.toFile "config.yaml" (builtins.toJSON commonLib.jormungandrLib.defaultJormungandrConfig);
in pkgs.runCommandCC "daedalus-bridge" {
passthru = {
node-version = jormungandr.version;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo, use the cardano-node version if the backend is set to cardano

wallet-version = haskellPackages.cardano-wallet-jormungandr.identifier.version;
};
} ''
mkdir -pv $out/bin $out/config
cp ${jormungandrConfig} $out/config/jormungandr-config.yaml
cd $out/bin
cp ${haskellPackages.cardano-wallet-jormungandr.components.exes.cardano-wallet-jormungandr}/bin/cardano-wallet-jormungandr* .
cp ${cardano-shell.nix-tools.cexes.cardano-launcher.cardano-launcher}/bin/cardano-launcher* .
cp ${jormungandr-cli}/bin/jcli* .
#cp {nix-tools.cexes.cardano-node.cardano-node}/bin/cardano-node* .
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo, accept the backend param, and select the right node and wallet binaries

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is cardano-node here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new haskell node. Out of scope for this release.

${pkgs.lib.optionalString (target == "x86_64-windows") ''
echo ${jormungandr}
cp ${pkgsCross.libffi}/bin/libffi-6.dll .
cp ${pkgsCross.openssl.out}/lib/libeay32.dll .
''}
${pkgs.lib.optionalString (target == "x86_64-linux") ''
chmod +w -R .
for bin in cardano-launcher; do
strip $bin
patchelf --shrink-rpath $bin
done
''}
''
14 changes: 0 additions & 14 deletions nix/iohk-common.nix

This file was deleted.

7 changes: 0 additions & 7 deletions nix/iohk-nix-src.json

This file was deleted.

28 changes: 24 additions & 4 deletions nix/jormungandr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#
############################################################################

{ iohkLib ? import ./iohk-common.nix {}
{ iohkLib ? import ../lib.nix {}
, pkgs ? iohkLib.pkgs
}:

Expand All @@ -34,10 +34,30 @@ let
# Hash of git repo and all of its submodules.
sha256 = "1w0xcx1h09wv25qdyybamxxl8sqd2npja12n3vpvz0sgv88c3mix";
# Hash of all Cargo dependencies.
cargoSha256 = "0pflam5am760z4pz3j1ga4arsixmay2487sgpqrhrkiaws4nxy57";
cargoSha256 = "sha256:0pflam5am760z4pz3j1ga4arsixmay2487sgpqrhrkiaws4nxy57";
};

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 = "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;
}
2 changes: 1 addition & 1 deletion nix/regenerate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -euo pipefail

exec $(nix-build `dirname $0`/iohk-common.nix -A nix-tools.regeneratePackages --no-out-link)
exec $(nix-build `dirname $0`/../lib.nix -A nix-tools.regeneratePackages --no-out-link)
74 changes: 74 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"cardano-shell": {
"branch": "disable-tls",
"description": "Node shell, a thin layer for running the node and it's modules.",
"homepage": null,
"owner": "input-output-hk",
"repo": "cardano-shell",
"rev": "b8b07142f713119b07e40ebcb5173fb2bd304c1e",
"sha256": "1j4nnsiagvv1yqfr4h9ailnnd7iw62vim1w7bc0sb5blngfjgvjr",
"type": "tarball",
"url": "https://github.com/input-output-hk/cardano-shell/archive/b8b07142f713119b07e40ebcb5173fb2bd304c1e.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"gitignore": {
"branch": "master",
"description": "Nix function for filtering local git sources",
"homepage": "",
"owner": "hercules-ci",
"repo": "gitignore",
"rev": "f9e996052b5af4032fe6150bba4a6fe4f7b9d698",
"sha256": "0jrh5ghisaqdd0vldbywags20m2cxpkbbk5jjjmwaw0gr8nhsafv",
"type": "tarball",
"url": "https://github.com/hercules-ci/gitignore/archive/f9e996052b5af4032fe6150bba4a6fe4f7b9d698.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"iohk-nix": {
"branch": "niv-snappy-choco",
"description": "nix scripts shared across projects",
"homepage": null,
"owner": "input-output-hk",
"repo": "iohk-nix",
"rev": "2edd52c16a0e688d6611c03c47a89ca1f80fee91",
"sha256": "0lrg2rx1agh1nnv3mwanhk964x94vx22z1g7kaia8c4bc1fy3ajj",
"type": "tarball",
"url": "https://github.com/input-output-hk/iohk-nix/archive/2edd52c16a0e688d6611c03c47a89ca1f80fee91.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"jormungandr-nix": {
"branch": "master",
"description": "jormungandr nix scripts",
"homepage": null,
"owner": "input-output-hk",
"repo": "jormungandr-nix",
"rev": "219543bce9b518e5d6ccd95f9b33e33bf98ff507",
"sha256": "0l85aahvfj77kzzr0kk2il9nawxk6i26a0kx0dz1namkkqhrnrmz",
"type": "tarball",
"url": "https://github.com/input-output-hk/jormungandr-nix/archive/219543bce9b518e5d6ccd95f9b33e33bf98ff507.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
"branch": "iohk",
"description": "Easy dependency management for Nix projects",
"homepage": "https://github.com/nmattia/niv",
"owner": "input-output-hk",
"repo": "niv",
"rev": "4229fbcf62997467c34283a2f353702359e78e5a",
"sha256": "1y1h6aj0rxrrhvp9jpr6xw3zsa1l8ac25ng4xzjskr5kg620pxqr",
"type": "tarball",
"url": "https://github.com/input-output-hk/niv/archive/4229fbcf62997467c34283a2f353702359e78e5a.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "nixos-19.09",
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
"homepage": "https://github.com/NixOS/nixpkgs",
"owner": "NixOS",
"repo": "nixpkgs-channels",
"rev": "dbad7c7d59f12e81032bc3100e3d9fa44b6d4e70",
"sha256": "1pjhslnhz4gngbclyr39x4xaicrc1sz2xy8bsrvlr3cl5qrbki2b",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs-channels/archive/dbad7c7d59f12e81032bc3100e3d9fa44b6d4e70.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
Loading