Skip to content

Commit

Permalink
flake: groundwork for VM tests
Browse files Browse the repository at this point in the history
Removes basic check packages in favor of proper VM testing infrastructure.
  • Loading branch information
NotAShelf committed Dec 22, 2024
1 parent 5bffebf commit ec90c6e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 41 deletions.
38 changes: 0 additions & 38 deletions checks/default.nix

This file was deleted.

15 changes: 12 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
self,
nixpkgs,
...
} @ inputs: {
}: let
forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux"];
in {
nixosModules = {
hjem = ./modules/nixos.nix;
default = self.nixosModules.hjem;
};

checks = import ./checks {inherit inputs;};
checks = forAllSystems (system: let
checkArgs = {
inherit self;
pkgs = nixpkgs.legacyPackages.${system};
};
in {
hjem-basic = import ./tests/basic.nix checkArgs;
});

formatter = nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux"] (system: nixpkgs.legacyPackages.${system}.alejandra);
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);
};
}
38 changes: 38 additions & 0 deletions tests/basic.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
let
userHome = "/home/alice";
in
(import ./lib.nix) {
name = "hjem-basic";
nodes = {
machine = {
self,
pkgs,
...
}: {
imports = [self.nixosModules.hjem];

users.groups.alice = {};
users.users.alice = {
isNormalUser = true;
home = userHome;
};

homes = {
alice = {
directory = userHome;
files.".config/foo".text = "Hello world!";
packages = [pkgs.hello];
};
};
};
};

testScript = ''
# Start all machines
start_all()
# wait for our service to start
machine.wait_for_unit("systemd-tmpfiles-setup.service")
output = machine.succeed("ls ${userHome}/.config/foo")
'';
}
17 changes: 17 additions & 0 deletions tests/lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The first argument to this function is the test module itself
test: {
pkgs,
self,
}: let
inherit (pkgs) lib;
nixos-lib = import (pkgs.path + "/nixos/lib") {};
in
(nixos-lib.runTest {
hostPkgs = pkgs;
defaults.documentation.enable = lib.mkDefault false;

node.specialArgs = {inherit self;};
imports = [test];
})
.config
.result

0 comments on commit ec90c6e

Please sign in to comment.