1
Fork 0
mirror of https://github.com/RGBCube/hjem synced 2026-01-20 12:11:09 +00:00

flake: groundwork for VM tests

Removes basic check packages in favor of proper VM testing infrastructure.
This commit is contained in:
NotAShelf 2024-12-22 15:49:14 +03:00
parent 5bffebfc58
commit f101830339
No known key found for this signature in database
GPG key ID: EED98D11B85A2819
5 changed files with 87 additions and 41 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
# Nix build/test artifacts
.nixos-test-history
result*

View file

@ -1,38 +0,0 @@
{inputs, ...}: let
inherit (inputs) self nixpkgs;
systems = ["x86_64-linux" "aarch64-linux"];
forEachSystem = inputs.nixpkgs.lib.genAttrs systems;
in
forEachSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
baseSystem = nixpkgs.lib.nixosSystem {
modules = [
({modulesPath, ...}: {
imports = [
# Minimal profile
"${modulesPath}/profiles/minimal.nix"
# Hjem NixOS module
self.nixosModules.hjem
];
boot.loader.grub.enable = false;
fileSystems."/".device = "nodev";
nixpkgs.hostPlatform = system;
system.stateVersion = "24.11";
# Hjem setup
users.groups.alice = {};
users.users.alice.isNormalUser = true;
homes = {
alice = {
files.".config/foo".text = "Hello world!";
packages = [pkgs.hello];
};
};
})
];
};
in {
default = baseSystem.config.system.build.toplevel;
})

View file

@ -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);
};
}

55
tests/basic.nix Normal file
View file

@ -0,0 +1,55 @@
let
userHome = "/home/alice";
in
(import ./lib.nix) {
name = "hjem-basic";
nodes = {
node1 = {
self,
pkgs,
...
}: {
imports = [self.nixosModules.hjem];
users.groups.alice = {};
users.users.alice = {
isNormalUser = true;
home = userHome;
password = "";
};
homes = {
alice = {
enable = true;
packages = [pkgs.hello];
files.".config/foo" = {
text = "Hello world!";
};
};
};
# Also test systemd-tmpfiles internally
systemd.user.tmpfiles = {
rules = [
"d %h/user_tmpfiles_created"
];
users.alice.rules = [
"d %h/only_alice"
];
};
};
};
testScript = ''
machine.succeed("loginctl enable-linger alice")
machine.wait_until_succeeds("systemctl --user --machine=alice@ is-active systemd-tmpfiles-setup.service")
# Test file created by Hjem
machine.succeed("[ -L ~alice/.config/foo ]")
# Test regular files, created by systemd-tmpfiles
machine.succeed("[ -d ~alice/user_tmpfiles_created ]")
machine.succeed("[ -d ~alice/only_alice ]")
'';
}

17
tests/lib.nix Normal file
View file

@ -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