-
Notifications
You must be signed in to change notification settings - Fork 8
add basic cardano-node module #45
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
Changes from all commits
1982c1b
83d8f74
f35cc13
c0d02bc
6e3d03a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| {inputs, ...}: { | ||
| imports = [ | ||
| ./testing.nix | ||
| ./nixosTests.nix | ||
| ./licenses.nix | ||
| ]; | ||
| perSystem = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| lib, | ||
| inputs, | ||
| config, | ||
| withSystem, | ||
| ... | ||
| }: let | ||
| inherit (lib) mkOption types mapAttrs' nameValuePair; | ||
|
|
@@ -14,31 +15,53 @@ in { | |
| pkgs, | ||
| ... | ||
| }: let | ||
| cfg = config.cardanoNix; | ||
| cfg = config.nixosTests; | ||
| in { | ||
| options.cardanoNix = { | ||
| options.nixosTests = { | ||
| tests = mkOption { | ||
| description = "NixOS tests as modules."; | ||
| type = types.lazyAttrsOf (types.submodule ({config, ...}: { | ||
| options = { | ||
| name = mkOption { | ||
| description = "The name of the test."; | ||
| type = types.str; | ||
| default = config._module.args.name; | ||
| internal = true; | ||
| }; | ||
| systems = mkOption { | ||
| description = "The systems to run the tests on."; | ||
| type = types.listOf types.str; | ||
| default = ["x86_64-linux"]; | ||
| }; | ||
| module = mkOption { | ||
| description = "The test module. Required."; | ||
| type = types.deferredModule; | ||
| }; | ||
| documentation = mkOption { | ||
| description = "Wether to generate documentation for the testnixos configuraion. False by default to speed up builds."; | ||
| type = types.bool; | ||
| default = false; | ||
| }; | ||
| specialArgs = mkOption { | ||
| description = "The specialArgs to pass to the test node."; | ||
| type = types.attrsOf types.anything; | ||
| default = {}; | ||
| }; | ||
| impure = mkOption { | ||
| description = "Wether the test requires internet access and should be run as an effect instead of a nix build."; | ||
| type = types.bool; | ||
| default = false; | ||
| }; | ||
| check = mkOption { | ||
| description = "The test derivation composed with _mkCheckFromTest from the module."; | ||
| type = types.package; | ||
| default = cfg._mkCheckFromTest config; | ||
| }; | ||
| checkEffect = mkOption { | ||
| description = "The test hercules-ci-effect composed with _mkEffectFromTest from the module."; | ||
| type = types.package; | ||
| default = cfg._mkEffectFromTest config; | ||
| }; | ||
| }; | ||
| })); | ||
| }; | ||
|
|
@@ -59,16 +82,17 @@ in { | |
| (cfg._nixosLib.runTest { | ||
| hostPkgs = pkgs; | ||
|
|
||
| # false by default, it speeds up evaluation by skipping docs generation | ||
| defaults.documentation.enable = test.documentation; | ||
|
|
||
| node = { | ||
| inherit (test) specialArgs; | ||
| }; | ||
|
|
||
| # import all of our flake nixos modules by default | ||
| defaults.imports = [ | ||
| # import all of our flake nixos modules by default | ||
| nixosModules.default | ||
| # fix missing pkgs.system in tests | ||
| {nixpkgs.overlays = [(_: _: {inherit system;})];} | ||
| ]; | ||
|
|
||
| # import the test module | ||
|
|
@@ -77,14 +101,26 @@ in { | |
| .config | ||
| .result; | ||
| }; | ||
| _mkEffectFromTest = mkOption { | ||
| type = types.functionTo types.package; | ||
| internal = true; | ||
| default = test: | ||
| withSystem system ({hci-effects, ...}: | ||
| hci-effects.modularEffect { | ||
| mounts."/dev/kvm" = "kvm"; | ||
| effectScript = '' | ||
| ${test.check.driver}/bin/nixos-test-driver | ||
| ''; | ||
| }); | ||
| }; | ||
| }; | ||
|
|
||
| config = { | ||
| checks = | ||
| mapAttrs' | ||
| (name: test: nameValuePair "testing-${test.name}" (cfg._mkCheckFromTest test)) | ||
| (name: test: nameValuePair "nixosTests-${test.name}" test.check) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the end you kept a prefix for checks which are tests!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes but i named it the same as the module :) |
||
| (lib.filterAttrs | ||
| (_: v: lib.elem system v.systems) | ||
| (_: v: lib.elem system v.systems && !v.impure) | ||
| cfg.tests); | ||
|
|
||
| apps.run-test.program = lib.getExe cfg.runTestScript; | ||
|
|
@@ -99,4 +135,11 @@ in { | |
| ]; | ||
| }; | ||
| }; | ||
|
|
||
| herculesCI.onPush.default.outputs.effects = | ||
| mapAttrs' | ||
| (name: test: nameValuePair "nixosTests-${test.name}" test.checkEffect) | ||
| (lib.filterAttrs | ||
| (_: v: lib.elem config.defaultEffectSystem v.systems && v.impure) | ||
| (config.perSystem config.defaultEffectSystem).nixosTests.tests); | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| config, | ||
| lib, | ||
| ... | ||
| }: let | ||
| cfg = config.cardanoNix.cardano-node; | ||
| in { | ||
| options.cardanoNix.cardano-node = { | ||
| enable = lib.mkEnableOption "cardano-node service"; | ||
| }; | ||
|
|
||
| config = lib.mkIf cfg.enable { | ||
| environment.variables = { | ||
| CARDANO_NODE_SOCKET_PATH = config.services.cardano-node.socketPath 0; | ||
| }; | ||
|
|
||
| services.cardano-node = { | ||
| enable = true; | ||
| hostAddr = "0.0.0.0"; | ||
|
|
||
| environment = config.cardanoNix.globals.network; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So do we want to keep
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, in fact, we may want to move the options one level up under cardanoNix |
||
| }; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,19 @@ | ||
| { | ||
| cardanoNix.tests = { | ||
| dummy = { | ||
| systems = ["x86_64-linux"]; | ||
| nixosTests.tests.cardano-cli.module = { | ||
| name = "cardano-cli-test"; | ||
|
|
||
| module = { | ||
| name = "cli-test"; | ||
|
|
||
| nodes = { | ||
| machine = { | ||
| virtualisation = { | ||
| cores = 2; | ||
| memorySize = 1024; | ||
| writableStore = true; | ||
| }; | ||
| cardanoNix.cardano-cli.enable = true; | ||
| }; | ||
| nodes = { | ||
| machine = { | ||
| virtualisation = { | ||
| cores = 2; | ||
| memorySize = 1024; | ||
| }; | ||
|
|
||
| # TODO `git` will be replaced by `cardano-cli` (milestone 2) | ||
| testScript = '' | ||
| machine.succeed("git --version") | ||
| ''; | ||
| cardanoNix.cardano-cli.enable = true; | ||
| }; | ||
| }; | ||
|
|
||
| testScript = '' | ||
| machine.succeed("cardano-cli --version") | ||
| ''; | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| nixosTests.tests.cardano-node = { | ||
| impure = true; | ||
| module = { | ||
| name = "cardano-node-test"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can drop
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| nodes = { | ||
| machine = {pkgs, ...}: { | ||
| virtualisation = { | ||
| cores = 1; | ||
| memorySize = 1024; | ||
| }; | ||
| cardanoNix = { | ||
| globals.network = "preview"; | ||
| cardano-cli.enable = true; | ||
| cardano-node = { | ||
| enable = true; | ||
| }; | ||
| }; | ||
|
|
||
| environment.systemPackages = with pkgs; [jq bc]; | ||
| }; | ||
| }; | ||
|
|
||
| testScript = '' | ||
| machine.wait_for_unit("cardano-node") | ||
| machine.wait_until_succeeds("""[[ $(echo "$(cardano-cli query tip --testnet-magic 2 | jq '.syncProgress' --raw-output) > 0.01" | bc) == "1" ]]""") | ||
| ''; | ||
| }; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| perSystem = _: { | ||
| imports = [ | ||
| ./cardano-cli.nix | ||
| ./cardano-node.nix | ||
| ]; | ||
| }; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still wondering why in tests there is not
pkgs.system...