From ed496a871b441ab0279c56007457d1cc1a1a99d8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 3 Nov 2020 16:03:49 +0100 Subject: [PATCH] nixos: fix potentialy conflicting option, add missing config, add testing-mode. and enable back nixos test. --- nix/nixos/smash-service.nix | 33 ++++++++++++++++++++++----------- nix/nixos/tests/default.nix | 2 +- nix/nixos/tests/smash-test.nix | 23 ++++++++++++++++++----- nix/sources.json | 8 ++++---- release.nix | 5 ++++- 5 files changed, 49 insertions(+), 22 deletions(-) diff --git a/nix/nixos/smash-service.nix b/nix/nixos/smash-service.nix index 0ae0006..ea671ff 100644 --- a/nix/nixos/smash-service.nix +++ b/nix/nixos/smash-service.nix @@ -2,7 +2,7 @@ let cfg = config.services.smash; - self = config.internal.smashPackages; + inherit (cfg.smashPkgs) smashHaskellPackages smashTestingHaskellPackages iohkNix; smashConfig = cfg.explorerConfig // { inherit (cfg.nodeConfig) ByronGenesisFile ShelleyGenesisFile ByronGenesisHash ShelleyGenesisHash Protocol RequiresNetworkMagic; }; @@ -10,20 +10,31 @@ let in { options = { - internal = lib.mkOption { - type = lib.types.attrs; - internal = true; - default = { smashPackages = import ../. {}; }; - }; services.smash = { enable = lib.mkEnableOption "enable the smash server"; script = lib.mkOption { internal = true; type = lib.types.package; }; + smashPkgs = lib.mkOption { + type = lib.types.attrs; + default = import ../. {}; + defaultText = "smash pkgs"; + description = '' + The smash packages and library that should be used. + ''; + internal = true; + }; + testing-mode = lib.mkOption { + type = lib.types.bool; + default = false; + description = "enable testing APIs"; + }; package = lib.mkOption { type = lib.types.package; - default = pkgs.smashHaskellPackages.smash.components.exes.smash-exe or (import ../. {}).smashHaskellPackages.smash.components.exes.smash-exe; + default = if cfg.testing-mode + then smashTestingHaskellPackages.smash.components.exes.smash-exe + else smashHaskellPackages.smash.components.exes.smash-exe; }; explorerConfig = lib.mkOption { type = lib.types.attrs; @@ -35,11 +46,11 @@ in { }; environment = lib.mkOption { type = lib.types.nullOr lib.types.attrs; - default = self.iohkNix.cardanoLib.environments.${cfg.environmentName}; + default = iohkNix.cardanoLib.environments.${cfg.environmentName}; }; logConfig = lib.mkOption { type = lib.types.attrs; - default = self.iohkNix.cardanoLib.defaultExplorerLogConfig; + default = iohkNix.cardanoLib.defaultExplorerLogConfig; }; environmentName = lib.mkOption { type = lib.types.str; @@ -107,7 +118,7 @@ in { export SMASHPGPASSFILE=/$RUNTIME_DIRECTORY/pgpass ''} - ${cfg.package}/bin/smash-exe run-migrations --mdir ${../../schema} + ${cfg.package}/bin/smash-exe run-migrations --config ${configFile} --mdir ${../../schema} exec ${cfg.package}/bin/smash-exe run-app-with-db-sync \ --config ${configFile} \ --socket-path "$CARDANO_NODE_SOCKET_PATH" \ @@ -117,7 +128,7 @@ in { systemd.services.smash = { path = [ cfg.package pkgs.netcat pkgs.postgresql ]; preStart = '' - for x in {1..10}; do + for x in {1..30}; do nc -z localhost ${toString config.services.smash.postgres.port} && break echo loop $x: waiting for postgresql 2 sec... sleep 2 diff --git a/nix/nixos/tests/default.nix b/nix/nixos/tests/default.nix index 4dc9b93..ab7aaac 100644 --- a/nix/nixos/tests/default.nix +++ b/nix/nixos/tests/default.nix @@ -9,7 +9,7 @@ with pkgs.commonLib; forAllSystems = genAttrs supportedSystems; importTest = fn: args: system: let imported = import fn; - test = import (pkgs.path + "/nixos/tests/make-test.nix") imported; + test = import (pkgs.path + "/nixos/tests/make-test-python.nix") imported; in test ({ inherit pkgs system config; } // args); diff --git a/nix/nixos/tests/smash-test.nix b/nix/nixos/tests/smash-test.nix index 4ef4453..431c705 100644 --- a/nix/nixos/tests/smash-test.nix +++ b/nix/nixos/tests/smash-test.nix @@ -17,14 +17,24 @@ with pkgs; with commonLib; ]; services.smash = { enable = true; - environmentName = "shelley_testnet"; + environmentName = "mainnet"; + smashPkgs = pkgs; inherit (config.services.cardano-node) socketPath; }; + systemd.services.smash.serviceConfig = { + # Put cardano-db-sync in "cardano-node" group so that it can write socket file: + SupplementaryGroups = "cardano-node"; + }; services.cardano-node = { enable = true; - environment = "shelley_testnet"; + environment = "mainnet"; package = smashHaskellPackages.cardano-node.components.exes.cardano-node; + topology = cardanoLib.mkEdgeTopology { + port = 3001; + edgeNodes = [ "127.0.0.1" ]; + }; }; + systemd.services.cardano-node.serviceConfig.Restart = lib.mkForce "no"; services.postgresql = { enable = true; package = postgresql_12; @@ -50,9 +60,12 @@ with pkgs; with commonLib; }; }; testScript = '' - startAll - $machine->waitForUnit("postgresql.service"); - $machine->waitForUnit("cardano-node.service"); + start_all() + machine.wait_for_unit("postgresql.service") + machine.wait_for_unit("cardano-node.service") + machine.wait_for_open_port(3001) + machine.wait_for_unit("smash.service") + machine.wait_for_open_port(3100) ''; } diff --git a/nix/sources.json b/nix/sources.json index d462a1e..c380c55 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -1,14 +1,14 @@ { "cardano-node": { - "branch": "tags/1.14.2", + "branch": "refs/tags/1.24.2", "description": "The core component that is used to participate in a Cardano decentralised blockchain.", "homepage": "https://cardano.org", "owner": "input-output-hk", "repo": "cardano-node", - "rev": "924a6f7d8c2bdb1bf525be8b0d5626e440697b01", - "sha256": "0bi1vwmb1w6wc2szpr8v1nbsci9y36lnjr4v5pli1wvll1hhpw3c", + "rev": "400d18092ce604352cf36fe5f105b0d7c78be074", + "sha256": "19r4mamm9bxc1hz32qgsrfnrfxwp4pgnb4d28fzai3izznil03vi", "type": "tarball", - "url": "https://github.com/input-output-hk/cardano-node/archive/924a6f7d8c2bdb1bf525be8b0d5626e440697b01.tar.gz", + "url": "https://github.com/input-output-hk/cardano-node/archive/400d18092ce604352cf36fe5f105b0d7c78be074.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "haskell.nix": { diff --git a/release.nix b/release.nix index 7be2e6e..5281a6b 100644 --- a/release.nix +++ b/release.nix @@ -69,11 +69,14 @@ let (packagePlatforms project); in (mapTestOn (__trace (__toJSON filteredBuilds) filteredBuilds)); # only build nixos tests on first supported system (linux) + inherit (pkgsFor (builtins.head supportedSystems)) nixosTests; } // (mkRequiredJob (concatLists [ (collectJobs jobs.native.checks) (collectJobs jobs.native.libs) (collectJobs jobs.native.exes) - [ jobs.native.cardano-node.x86_64-linux ] + [ jobs.nixosTests.smashTest.x86_64-linux + jobs.native.cardano-node.x86_64-linux + ] ])); in jobs