Skip to content

Commit

Permalink
nix: Provide deployment info in $CARDANO_NODE_CONFIGS
Browse files Browse the repository at this point in the history
This can be used for the restore benchmark, and during development.

It will make it easier to support the shelley ff testnet in the
restore benchmark/test.

It can also be used by cardano-launcher to provide configurations for
its unit tests.
  • Loading branch information
rvl committed May 27, 2020
1 parent 8b10273 commit 2c6a726
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 39 deletions.
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ let
sqlite-interactive
pythonPackages.openapi-spec-validator
]);
CARDANO_NODE_CONFIGS = cardano-node.configs;
CARDANO_NODE_CONFIGS = cardano-node.deployments;
meta.platforms = lib.platforms.unix;
};
stackShell = import ./nix/stack-shell.nix {
Expand Down
16 changes: 9 additions & 7 deletions lib/byron/bench/Restore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ import qualified Data.Text.Encoding as T

main :: IO ()
main = do
testnetGenesis <- getEnv "TESTNET_GENESIS"
configs <- getEnv "CARDANO_NODE_CONFIGS"
let testnetGenesis = configs </> "testnet" </> "genesis.json"
let opts = info (fmap exec (networkConfigurationOption testnetGenesis)) mempty
join $ execParser opts

Expand Down Expand Up @@ -215,12 +216,13 @@ exec c = do

----------------------------------------------------------------------------
-- Environment variables set by nix/haskell.nix (or manually)
topology <- case c of
MainnetConfig _ -> getEnv "MAINNET_TOPOLOGY"
TestnetConfig _ -> getEnv "TESTNET_TOPOLOGY"
config <- case c of
MainnetConfig _ -> getEnv "MAINNET_NODE_CONFIG"
TestnetConfig _ -> getEnv "TESTNET_NODE_CONFIG"
configs <- getEnv "CARDANO_NODE_CONFIGS"
let networkDir = case c of
MainnetConfig _ -> "mainnet"
TestnetConfig _ -> "testnet"
topology = configs </> networkDir </> "topology.json"
config = configs </> networkDir </> "configuration.json"

----------------------------------------------------------------------------
-- Environment variables set by ./buildkite/bench-restore.sh (or manually)
nodeDB <- getEnv "NODE_DB"
Expand Down
6 changes: 1 addition & 5 deletions nix/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ let
build-tools = [ pkgs.makeWrapper ];
postInstall = ''
wrapProgram $out/bin/restore \
--set TESTNET_NODE_CONFIG ${pkgs.cardano-node.testnet.configFile} \
--set TESTNET_TOPOLOGY ${pkgs.cardano-node.topologyFiles.testnet} \
--set TESTNET_GENESIS ${pkgs.cardano-node.testnet.genesisFile} \
--set MAINNET_NODE_CONFIG ${pkgs.cardano-node.mainnet.configFile} \
--set MAINNET_TOPOLOGY ${pkgs.cardano-node.topologyFiles.mainnet} \
--set CARDANO_NODE_CONFIGS ${pkgs.cardano-node.deployments} \
--prefix PATH : ${pkgs.cardano-node}/bin
'';
};
Expand Down
1 change: 1 addition & 0 deletions nix/package-cardano-node.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pkgs.stdenv.mkDerivation rec {
'' + (if pkgs.stdenv.hostPlatform.isWindows then ''
cp --remove-destination -v ${pkgs.libffi}/bin/libffi-6.dll $out/bin
cp --remove-destination -v ${cardano-node}/bin/* $out/bin
cp -Rv ${cardano-node.deployments} $out/deployments
cp -Rv ${cardano-node.configs} $out/configuration
'' else (if pkgs.stdenv.hostPlatform.isDarwin then ''
cp -v ${cardano-node}/bin/cardano-node $out/bin
Expand Down
53 changes: 30 additions & 23 deletions nix/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,38 @@ let
in pkgs: super: with pkgs; {
jmPkgs = import ./jormungandr.nix { inherit (pkgs) commonLib; inherit pkgs; };
cardanoNodePkgs = import sources.cardano-node { inherit system crossSystem config; };
cardano-node = cardanoNodePkgs.cardano-node
// commonLib.cardanoLib.forEnvironments (env:
env // {
configFile =
let
rawCfg = env.nodeConfig // {
GenesisFile = env.genesisFile;
minSeverity = "Notice";
};
in
builtins.toFile "cardano-node-config" (builtins.toJSON rawCfg);
})
// {
topologyFiles = {
# Note: It was easier to define as topologyFiles.testnet than testnet.topologyFile.
# TODO: Retrieve these from iohk-nix or cardano-node directly.
mainnet = builtins.toFile "topology" "{\"Producers\":[{\"addr\":\"relays-new.cardano-mainnet.iohk.io\",\"port\":3001,\"valency\":1}]}";
testnet = builtins.toFile "topology" "{\"Producers\":[{\"addr\":\"relays-new.cardano-testnet.iohkdev.io\",\"port\":3001,\"valency\":1}]}";
cardano-node = cardanoNodePkgs.cardano-node // {
# Provide real deployment configurations for use in dev/tests/benchmarks.
# https://hydra.iohk.io/job/Cardano/iohk-nix/cardano-deployment/latest/download/1/index.html
deployments = let
environments = {
inherit (pkgs.commonLib.cardanoLib.environments) ff mainnet testnet;
};

# provide configuration directory as a convenience
configs = pkgs.runCommand "cardano-node-configs" {} ''
cp -R ${sources.cardano-node}/configuration $out;
'';
updateConfig = cfg: cfg // {
GenesisFile = "genesis.json";
minSeverity = "Notice";
};
mkTopology = env: pkgs.commonLib.cardanoLib.mkEdgeTopology {
edgeNodes = [ env.relaysNew ];
valency = 2;
};
mapAttrsToString = f: attrs:
pkgs.lib.concatStringsSep "\n" (pkgs.lib.mapAttrsToList f attrs);
in pkgs.runCommand "cardano-node-deployments" {
nativeBuildInputs = [ pkgs.buildPackages.jq ];
} (mapAttrsToString (name: env: ''
cfg=$out/${name}
mkdir -p $cfg
jq . < ${__toFile "${name}-config.json" (__toJSON (updateConfig env.nodeConfig))} > $cfg/configuration.json
jq . < ${env.genesisFile} > $cfg/genesis.json
jq . < ${mkTopology env} > $cfg/topology.json
'') environments);

# Provide configuration directory as a convenience
configs = pkgs.runCommand "cardano-node-configs" {} ''
cp -R ${sources.cardano-node}/configuration $out;
'';
};
inherit (cardanoNodePkgs.haskellPackages.cardano-cli.components.exes) cardano-cli;
inherit (pkgs1903) stack;
}
6 changes: 3 additions & 3 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"homepage": null,
"owner": "input-output-hk",
"repo": "iohk-nix",
"rev": "30cf81c421d7fca198660e1e995038dd8b6f3d13",
"sha256": "0sy9gza5gsrbqfbizp0dd98njnymigchj0aszswkfzxndskknarj",
"rev": "b11279c2441f737407c31792fa9c93c59e6ab347",
"sha256": "0b90hw5h3iwkzjyrc4zwd7987j30rsq6c0hwa7j9g29134v4fk98",
"type": "tarball",
"url": "https://github.com/input-output-hk/iohk-nix/archive/30cf81c421d7fca198660e1e995038dd8b6f3d13.tar.gz",
"url": "https://github.com/input-output-hk/iohk-nix/archive/b11279c2441f737407c31792fa9c93c59e6ab347.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
Expand Down
10 changes: 10 additions & 0 deletions nix/windows-release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ in pkgs.runCommand name { buildInputs = [ pkgs.buildPackages.zip ]; } ''
zip -r $out/${exe.name}-configuration.zip .
echo "file binary-dist $out/${exe.name}-configuration.zip" >> $out/nix-support/hydra-build-products
fi
# make a separate deployments configuration package if needed
if [ -d ${exe}/deployments ]; then
cp -R ${exe}/deployments ..
cd ../deployments
chmod -R +w .
zip -r $out/${exe.name}-deployments.zip .
echo "file binary-dist $out/${exe.name}-deployments.zip" >> $out/nix-support/hydra-build-products
fi
''

0 comments on commit 2c6a726

Please sign in to comment.