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:
parent
5bffebfc58
commit
f101830339
5 changed files with 87 additions and 41 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Nix build/test artifacts
|
||||
.nixos-test-history
|
||||
result*
|
||||
|
|
@ -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;
|
||||
})
|
||||
15
flake.nix
15
flake.nix
|
|
@ -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
55
tests/basic.nix
Normal 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
17
tests/lib.nix
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue