1
Fork 0
mirror of https://github.com/RGBCube/hjem synced 2025-10-14 21:52:22 +00:00
hjem/tests/linker.nix
2025-06-13 22:13:08 -04:00

73 lines
2.2 KiB
Nix

let
userHome = "/home/alice";
in
(import ./lib) {
name = "hjem-linker";
nodes = {
node1 = {
self,
pkgs,
inputs,
...
}: {
imports = [self.nixosModules.hjem];
system.switch.enable = true;
users.groups.alice = {};
users.users.alice = {
isNormalUser = true;
home = userHome;
password = "";
};
hjem = {
linker = inputs.smfh.packages.${pkgs.system}.default;
users = {
alice = {
enable = true;
};
};
};
specialisation = {
fileGetsLinked.configuration = {
hjem.users.alice.files.".config/foo".text = "Hello world!";
};
fileGetsOverwritten.configuration = {
hjem.users.alice.files.".config/foo" = {
text = "Hello new world!";
clobber = true;
};
};
};
};
};
testScript = {nodes, ...}: let
baseSystem = nodes.node1.system.build.toplevel;
specialisations = "${baseSystem}/specialisation";
in ''
node1.succeed("loginctl enable-linger alice")
with subtest("Activation service runs correctly"):
node1.succeed("${baseSystem}/bin/switch-to-configuration test")
node1.succeed("systemctl show servicename --property=Result --value | grep -q '^success$'")
with subtest("Manifest gets created"):
node1.succeed("${baseSystem}/bin/switch-to-configuration test")
node1.succeed("[ -f /var/lib/hjem/manifest-alice.json ]")
with subtest("File gets linked"):
node1.succeed("${specialisations}/fileGetsLinked/bin/switch-to-configuration test")
node1.succeed("test -L ${userHome}/.config/foo")
node1.succeed("grep \"Hello world!\" ${userHome}/.config/foo")
with subtest("File gets overwritten when changed"):
node1.succeed("${specialisations}/fileGetsLinked/bin/switch-to-configuration test")
node1.succeed("${specialisations}/fileGetsOverwritten/bin/switch-to-configuration test")
node1.succeed("test -L ${userHome}/.config/foo")
node1.succeed("grep \"Hello new world!\" ${userHome}/.config/foo")
'';
}