2023-11-19 22:16:14 +00:00
|
|
|
{ lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
rootPassword = "$y$j9T$p6OI0WN7.rSfZBOijjRdR.$xUOA2MTcB48ac.9Oc5fz8cxwLv1mMqabnn333iOzSA6";
|
2024-07-19 15:03:22 +00:00
|
|
|
sysuserPassword = "$y$j9T$3aiOV/8CADAK22OK2QT3/0$67OKd50Z4qTaZ8c/eRWHLIM.o3ujtC1.n9ysmJfv639";
|
|
|
|
newSysuserPassword = "mellow";
|
2023-11-19 22:16:14 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name = "activation-sysusers-immutable";
|
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ nikstur ];
|
|
|
|
|
|
|
|
nodes.machine = {
|
|
|
|
systemd.sysusers.enable = true;
|
|
|
|
users.mutableUsers = false;
|
|
|
|
|
2024-07-21 11:36:17 +00:00
|
|
|
|
|
|
|
# Read this password file at runtime from outside the Nix store.
|
|
|
|
environment.etc."rootpw.secret".text = rootPassword;
|
|
|
|
# Override the empty root password set by the test instrumentation.
|
|
|
|
users.users.root.hashedPasswordFile = lib.mkForce "/etc/rootpw.secret";
|
|
|
|
|
2024-07-19 15:03:22 +00:00
|
|
|
users.users.sysuser = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "wheel";
|
|
|
|
home = "/sysuser";
|
|
|
|
initialHashedPassword = sysuserPassword;
|
2023-11-19 22:16:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
specialisation.new-generation.configuration = {
|
2024-07-19 15:03:22 +00:00
|
|
|
users.users.new-sysuser = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "wheel";
|
|
|
|
home = "/new-sysuser";
|
|
|
|
initialPassword = newSysuserPassword;
|
2023-11-19 22:16:14 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
with subtest("root user has correct password"):
|
|
|
|
print(machine.succeed("getent passwd root"))
|
|
|
|
assert "${rootPassword}" in machine.succeed("getent shadow root"), "root user password is not correct"
|
|
|
|
|
2024-07-19 15:03:22 +00:00
|
|
|
with subtest("sysuser user is created"):
|
|
|
|
print(machine.succeed("getent passwd sysuser"))
|
|
|
|
assert machine.succeed("stat -c '%U' /sysuser") == "sysuser\n"
|
|
|
|
assert "${sysuserPassword}" in machine.succeed("getent shadow sysuser"), "sysuser user password is not correct"
|
2023-11-19 22:16:14 +00:00
|
|
|
|
2024-07-21 11:36:17 +00:00
|
|
|
with subtest("Fail to add new user manually"):
|
|
|
|
machine.fail("useradd manual-sysuser")
|
|
|
|
|
2023-11-19 22:16:14 +00:00
|
|
|
|
|
|
|
machine.succeed("/run/current-system/specialisation/new-generation/bin/switch-to-configuration switch")
|
|
|
|
|
|
|
|
|
2024-07-19 15:03:22 +00:00
|
|
|
with subtest("new-sysuser user is created after switching to new generation"):
|
|
|
|
print(machine.succeed("getent passwd new-sysuser"))
|
|
|
|
assert machine.succeed("stat -c '%U' /new-sysuser") == "new-sysuser\n"
|
2023-11-19 22:16:14 +00:00
|
|
|
'';
|
|
|
|
}
|