From faf6738d6462798dea6c2cc2dde84b3834b5427a Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Tue, 24 Sep 2024 12:29:54 +0200 Subject: [PATCH] refactor: move test helpers into flake (#370) * refactor: move test helpers into flake collecting projects should not deal with debugging workflows. this change makes the derivation for running CI checks slightly smaller, at the cost of having a slightly different environment for interactive tests. it should be okay as long as those differences stay tightly scoped. * formatting --- flake.nix | 34 +++++++++++++++++++++++++++++----- projects/default.nix | 18 +----------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/flake.nix b/flake.nix index 1a6efe02..13c54cfc 100644 --- a/flake.nix +++ b/flake.nix @@ -79,9 +79,11 @@ mapAttrs (_: project: mapAttrs (_: example: example.path) project.nixos.examples) rawNgiProjects ); - rawNixosModules = flattenAttrsDot (lib.foldl recursiveUpdate {} (attrValues ( - mapAttrs (_: project: project.nixos.modules) rawNgiProjects - ))); + rawNixosModules = flattenAttrsDot ( + lib.foldl recursiveUpdate {} (attrValues ( + mapAttrs (_: project: project.nixos.modules) rawNgiProjects + )) + ); nixosModules = { @@ -175,8 +177,30 @@ .options; }; in rec { + # This is omitted in `nix flake show`. legacyPackages = { - nixosTests = mapAttrs (_: project: project.nixos.tests) ngiProjects; + # Run interactive tests with: + # + # nix run .#legacyPackages.x86_64-linux.nixosTests...driverInteractive + # + nixosTests = let + nixosTest = test: let + # Amenities for interactive tests + tools = {pkgs, ...}: { + environment.systemPackages = with pkgs; [vim tmux jq]; + # Use kmscon + # to provide a slightly nicer console. + # kmscon allows zooming with [Ctrl] + [+] and [Ctrl] + [-] + services.kmscon = { + enable = true; + autologinUser = "root"; + }; + }; + debugging.interactive.nodes = mapAttrs (_: _: tools) test.nodes; + in + pkgs.nixosTest (debugging // test); + in + mapAttrs (_: project: mapAttrs (_: nixosTest) project.nixos.tests) ngiProjects; }; packages = @@ -205,7 +229,7 @@ checks = let checksForNixosTests = projectName: tests: concatMapAttrs - (testName: test: {"projects/${projectName}/nixos/tests/${testName}" = test;}) + (testName: test: {"projects/${projectName}/nixos/tests/${testName}" = pkgs.nixosTest test;}) tests; checksForNixosExamples = projectName: examples: diff --git a/projects/default.nix b/projects/default.nix index 408e54e3..bb6b0e61 100644 --- a/projects/default.nix +++ b/projects/default.nix @@ -28,27 +28,11 @@ in concatMapAttrs names (readDir baseDirectory); - nixosTest = test: let - # Amenities for interactive tests - tools = {pkgs, ...}: { - environment.systemPackages = with pkgs; [vim tmux jq]; - # Use kmscon - # to provide a slightly nicer console. - # kmscon allows zooming with [Ctrl] + [+] and [Ctrl] + [-] - services.kmscon = { - enable = true; - autologinUser = "root"; - }; - }; - debugging.interactive.nodes = mapAttrs (_: _: tools) test.nodes; - in - pkgs.nixosTest (debugging // test); - hydrate = project: { packages = project.packages or {}; nixos.modules = project.nixos.modules or {}; nixos.examples = project.nixos.examples or {}; - nixos.tests = mapAttrs (_: nixosTest) project.nixos.tests or {}; + nixos.tests = project.nixos.tests or {}; }; in mapAttrs