From 2da3648d2ae55c410642b1c9fa8c4fcefbe5eb84 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Wed, 14 Feb 2024 13:54:21 +0100 Subject: [PATCH 1/3] refactor: unused args --- modules/cardano-node/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cardano-node/default.nix b/modules/cardano-node/default.nix index 49d14dc..1ce30cc 100644 --- a/modules/cardano-node/default.nix +++ b/modules/cardano-node/default.nix @@ -1,4 +1,4 @@ -{...}: { +{ imports = [ ./instance.nix ./relay.nix From 6e20908d17a3dede15d9cbe6654e148b3b1505d4 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Wed, 14 Feb 2024 13:54:38 +0100 Subject: [PATCH 2/3] feat: allow passing custom nix arguments --- checks/run-test.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/checks/run-test.nix b/checks/run-test.nix index 0db7ff3..9c8c82e 100644 --- a/checks/run-test.nix +++ b/checks/run-test.nix @@ -42,6 +42,7 @@ writeShellApplication { eval set -- "$args" system="${stdenv.system}" + nix_args="''${NIX_ARGS:=}" driver_args=() while [ $# -gt 0 ]; do @@ -64,6 +65,6 @@ writeShellApplication { shift # build/run the test driver, passing any remaining arguments - nix run ".#checks.$system.testing-$name.driver" -- "''${driver_args[@]}" + nix run ".#checks.$system.testing-$name.driver" "''${nix_args}" -- "''${driver_args[@]}" ''; } From 6934ac019c4d171f71a26bff68976a50e6dd8b9e Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Wed, 14 Feb 2024 17:09:49 +0100 Subject: [PATCH 3/3] fix: wip --- modules/cardano-node/instance.nix | 21 ++++++++++++--------- modules/default.nix | 23 ++++++++++++----------- tests/block-producer.nix | 19 +++++++++++-------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/modules/cardano-node/instance.nix b/modules/cardano-node/instance.nix index bc11a2d..6140542 100644 --- a/modules/cardano-node/instance.nix +++ b/modules/cardano-node/instance.nix @@ -5,11 +5,13 @@ config, lib, pkgs, + inputs, + system, ... }: let cardanoTypes = import ./types.nix {inherit lib;}; inherit (builtins) length attrNames; - inherit (lib) types mkOption mapAttrs' nameValuePair flip getBin toGNUCommandLineShell mkIf optional; + inherit (lib) types mkOption mapAttrs' nameValuePair flip getBin toGNUCommandLineShell mkIf; inherit (types) submodule; inherit (cardanoTypes) topologyType; cfg = config.cardanoNix.cardano-node; @@ -17,10 +19,11 @@ # FIXME: move all types to `types.nix`? # Options shared between "cardanoNix.cardano-node.defaults" "and cardanoNix.cardano-node.instance.$name" processOptions'.options = { - package = mkOption { - type = types.package; - package = pkgs.cardano-node; # FIXME: would we want to - }; + package = + lib.mkPackageOption pkgs + "cardano-node" { + default = inputs.cardano-node.packages.${system}.cardano-node; + }; options = mkOption { type = types.attrsOf types.str; @@ -58,12 +61,12 @@ topologyFile = mkOption { type = types.either types.str types.path; internal = true; - literalExample = '' + defaultText = lib.literalExpression '' # default implementation (for reference purpose) topologyFile = mkTopologyFile instance.topology; ''; }; - topology = { + topology = mkOption { type = topologyType; }; }; @@ -97,11 +100,11 @@ in { cardano-node = {}; } // flip mapAttrs' cfg.instances (name: instance: - nameValuePair "cardano-node-${instance.name}" { + nameValuePair "cardano-node-${name}" { after = ["network-online.target"]; wants = ["network-online.target"]; wantedBy = ["multi-user.target"]; - required = optional instance.useSnapshot "cardano-node-${instance.name}-snapshot.service"; # One shot, which should depends on downloader + # required = optional instance.useSnapshot "cardano-node-${instance.name}-snapshot.service"; # One shot, which should depends on downloader script = '' # Show commandline before execution set -x diff --git a/modules/default.nix b/modules/default.nix index 806db36..b08e9e1 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -4,23 +4,24 @@ inputs, ... }: { - flake.nixosModules = let - # Load nixos module, enhancing it's arguments with `self`, `self'`, `inputs` and `system` - getModule = module: {pkgs, ...}: { - imports = [module]; + flake.nixosModules = { + inject-args = { + pkgs, + lib, + ... + }: { _module.args = let inherit (pkgs.stdenv.hostPlatform) system; in { inherit self system inputs; - self' = config.perSystem system; + self' = lib.mkForce (config.perSystem system); }; }; - in { - globals = getModule ./globals; - cardano-block-producer = getModule ./cardano-node/producer.nix; - cardano-node-instance = getModule ./cardano-node/instance.nix; - cardano-cli = getModule ./cardano-cli; - packages = getModule ./packages.nix; + globals = ./globals; + cardano-block-producer = ./cardano-node/producer.nix; + cardano-node-instance = ./cardano-node/instance.nix; + cardano-cli = ./cardano-cli; + packages = ./packages.nix; # the default module imports all modules default = { imports = with builtins; attrValues (removeAttrs config.flake.nixosModules ["default"]); diff --git a/tests/block-producer.nix b/tests/block-producer.nix index 51cd7b2..7047d3e 100644 --- a/tests/block-producer.nix +++ b/tests/block-producer.nix @@ -15,14 +15,17 @@ writableStore = false; }; environment.systemPackages = [config.services.cardano-node.cardanoNodePackages.cardano-cli]; - cardanoNix.cardano-node.producer = { - enable = true; - relayAddrs = [ - { - address = "x.x.x.x"; - port = 3000; - } - ]; + cardanoNix.cardano-node = { + defaults = {}; + producer = { + enable = true; + relayAddrs = [ + { + address = "x.x.x.x"; + port = 3000; + } + ]; + }; }; }; };