refactor: init hello-world module with unit tests (eval)

This commit is contained in:
Johannes Kirschbauer
2025-04-21 16:09:56 +02:00
parent b791656694
commit ec99aea8f7
6 changed files with 49 additions and 58 deletions

View File

@@ -1,5 +1,5 @@
{ {
imports = [ imports = [
./zerotier-redux/flake-module.nix ./hello-world/flake-module.nix
]; ];
} }

View File

@@ -0,0 +1,8 @@
{ packages }:
{ ... }:
{
_class = "clan.service";
manifest.name = "clan-core/hello-word";
roles.peer = { };
}

View File

@@ -0,0 +1,37 @@
{
self,
inputs,
lib,
...
}:
let
module = lib.modules.importApply ./default.nix {
inherit (self) packages;
};
in
{
clan.inventory.modules = {
hello-world = module;
};
perSystem =
{ ... }:
let
# Module that contains the tests
# This module adds:
# - legacyPackages.<system>.eval-tests-hello-world
# - checks.<system>.eval-tests-hello-world
unit-test-module = (
self.clanLib.test.flakeModules.makeEvalChecks {
inherit module;
inherit self inputs;
testName = "hello-world";
tests = ./tests/eval-tests.nix;
# Optional arguments passed to the test
testArgs = { };
}
);
in
{
imports = [ unit-test-module ];
};
}

View File

@@ -18,12 +18,12 @@ let
}; };
# Register the module for the test # Register the module for the test
inventory.modules.zerotier-redux = module; inventory.modules.hello-world = module;
# Use the module in the test # Use the module in the test
inventory.instances = { inventory.instances = {
"zero" = { "hello" = {
module.name = "zerotier-redux"; module.name = "hello-world";
roles.peer.machines.jon = { }; roles.peer.machines.jon = { };
}; };

View File

@@ -1,13 +0,0 @@
{ packages }:
{ ... }:
{
_class = "clan.service";
manifest.name = "clan-core/zerotier";
# TODO: Migrate the behavior from nixosModules/clanCore/zerotier
# Expose a flag, to disable the clanCore/zerotier module if this module is used
# To ensure conflict free behavior
roles.moon = { };
roles.peer = { };
roles.controller = { };
}

View File

@@ -1,41 +0,0 @@
{
self,
lib,
inputs,
...
}:
let
inputOverrides = builtins.concatStringsSep " " (
builtins.map (input: " --override-input ${input} ${inputs.${input}}") (builtins.attrNames inputs)
);
module = lib.modules.importApply ./default.nix {
inherit (self) packages;
};
in
{
clan.inventory.modules = {
zerotier-redux = module;
};
perSystem =
{ system, pkgs, ... }:
{
legacyPackages.eval-tests-zerotier-redux = import ./tests/eval-tests.nix {
inherit lib module;
inherit (self) clanLib;
};
checks = {
"eval-tests-zerotier-redux" = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
export HOME="$(realpath .)"
nix-unit --eval-store "$HOME" \
--extra-experimental-features flakes \
--show-trace \
${inputOverrides} \
--flake ${self}#legacyPackages.${system}.eval-tests-zerotier-redux
touch $out
'';
};
};
}