2024-02-12 22:35:55 +00:00
|
|
|
{ pkgs, ... }:
|
|
|
|
|
|
|
|
{
|
|
|
|
name = "standalone-flake-basics";
|
|
|
|
meta.maintainers = [ pkgs.lib.maintainers.rycee ];
|
|
|
|
|
|
|
|
nodes.machine = { ... }: {
|
|
|
|
imports = [ "${pkgs.path}/nixos/modules/installer/cd-dvd/channel.nix" ];
|
2024-07-07 21:13:28 +00:00
|
|
|
virtualisation.memorySize = 3072;
|
2024-03-02 19:00:29 +00:00
|
|
|
nix = {
|
|
|
|
registry.home-manager.to = {
|
|
|
|
type = "path";
|
|
|
|
path = ../../..;
|
|
|
|
};
|
|
|
|
settings.extra-experimental-features = [ "nix-command" "flakes" ];
|
|
|
|
};
|
|
|
|
users.users.alice = {
|
|
|
|
isNormalUser = true;
|
|
|
|
description = "Alice Foobar";
|
|
|
|
password = "foobar";
|
|
|
|
uid = 1000;
|
|
|
|
};
|
2024-02-12 22:35:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
start_all()
|
|
|
|
machine.wait_for_unit("network-online.target")
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
|
2024-03-02 19:00:29 +00:00
|
|
|
def login_as_alice():
|
|
|
|
machine.wait_until_tty_matches("1", "login: ")
|
|
|
|
machine.send_chars("alice\n")
|
|
|
|
machine.wait_until_tty_matches("1", "Password: ")
|
|
|
|
machine.send_chars("foobar\n")
|
|
|
|
machine.wait_until_tty_matches("1", "alice\@machine")
|
2024-02-12 22:35:55 +00:00
|
|
|
|
2024-03-02 19:00:29 +00:00
|
|
|
def logout_alice():
|
|
|
|
machine.send_chars("exit\n")
|
2024-02-12 22:35:55 +00:00
|
|
|
|
2024-03-02 19:00:29 +00:00
|
|
|
def alice_cmd(cmd):
|
|
|
|
return f"su -l alice --shell /bin/sh -c $'export XDG_RUNTIME_DIR=/run/user/$UID ; {cmd}'"
|
2024-02-12 22:35:55 +00:00
|
|
|
|
2024-03-02 19:00:29 +00:00
|
|
|
def succeed_as_alice(cmd):
|
|
|
|
return machine.succeed(alice_cmd(cmd))
|
|
|
|
|
|
|
|
def fail_as_alice(cmd):
|
|
|
|
return machine.fail(alice_cmd(cmd))
|
|
|
|
|
|
|
|
# Create a persistent login so that Alice has a systemd session.
|
|
|
|
login_as_alice()
|
|
|
|
|
|
|
|
with subtest("Home Manager installation"):
|
|
|
|
succeed_as_alice("nix run home-manager -- init --home-manager-url home-manager --nixpkgs-url nixpkgs --switch")
|
2024-02-12 22:35:55 +00:00
|
|
|
|
|
|
|
actual = machine.succeed("ls /home/alice/.config/home-manager")
|
|
|
|
expected = "flake.lock\nflake.nix\nhome.nix\n"
|
|
|
|
assert actual == expected, \
|
|
|
|
f"unexpected content of /home/alice/.config/home-manager: {actual}"
|
|
|
|
|
|
|
|
machine.succeed("diff -u ${
|
|
|
|
./alice-home-init.nix
|
|
|
|
} /home/alice/.config/home-manager/home.nix")
|
|
|
|
machine.succeed("diff -u ${
|
|
|
|
./alice-flake-init.nix
|
|
|
|
} /home/alice/.config/home-manager/flake.nix")
|
|
|
|
|
|
|
|
# The default configuration creates this link on activation.
|
|
|
|
machine.succeed("test -L /home/alice/.cache/.keep")
|
|
|
|
|
|
|
|
with subtest("GC root and profile"):
|
|
|
|
# There should be a GC root and Home Manager profile and they should point
|
|
|
|
# to the same path in the Nix store.
|
|
|
|
gcroot = "/home/alice/.local/state/home-manager/gcroots/current-home"
|
|
|
|
gcrootTarget = machine.succeed(f"readlink {gcroot}")
|
|
|
|
|
|
|
|
profile = "/home/alice/.local/state/nix/profiles"
|
|
|
|
profileTarget = machine.succeed(f"readlink {profile}/home-manager")
|
|
|
|
profile1Target = machine.succeed(f"readlink {profile}/{profileTarget}")
|
|
|
|
|
|
|
|
assert gcrootTarget == profile1Target, \
|
|
|
|
f"expected GC root and profile to point to same, but pointed to {gcrootTarget} and {profile1Target}"
|
|
|
|
|
|
|
|
with subtest("Home Manager switch"):
|
2024-03-02 19:00:29 +00:00
|
|
|
fail_as_alice("hello")
|
|
|
|
|
|
|
|
succeed_as_alice("cp ${
|
2024-02-12 22:35:55 +00:00
|
|
|
./alice-home-next.nix
|
|
|
|
} /home/alice/.config/home-manager/home.nix")
|
|
|
|
|
2024-03-02 19:00:29 +00:00
|
|
|
actual = succeed_as_alice("home-manager switch")
|
2024-07-07 21:13:28 +00:00
|
|
|
expected = "Starting units: pueued.service"
|
2024-03-02 19:00:29 +00:00
|
|
|
assert expected in actual, \
|
|
|
|
f"expected home-manager switch to contain {expected}, but got {actual}"
|
|
|
|
|
|
|
|
succeed_as_alice("hello")
|
2024-02-12 22:35:55 +00:00
|
|
|
|
2024-03-02 19:00:29 +00:00
|
|
|
actual = succeed_as_alice("echo $EDITOR").strip()
|
2024-02-12 22:35:55 +00:00
|
|
|
assert "emacs" == actual, \
|
|
|
|
f"expected $EDITOR to contain emacs, but found {actual}"
|
|
|
|
|
2024-03-02 19:00:29 +00:00
|
|
|
actual = machine.succeed("systemctl --user -M alice@.host status pueued.service")
|
|
|
|
expected = "running"
|
|
|
|
assert expected in actual, \
|
|
|
|
f"expected systemctl status pueued status to contain {expected}, but got {actual}"
|
|
|
|
|
|
|
|
actual = succeed_as_alice("pueue status")
|
|
|
|
expected = "running"
|
|
|
|
assert expected in actual, \
|
|
|
|
f"expected pueue status to contain {expected}, but got {actual}"
|
|
|
|
|
2024-02-12 22:35:55 +00:00
|
|
|
with subtest("Home Manager generations"):
|
2024-03-02 19:00:29 +00:00
|
|
|
actual = succeed_as_alice("home-manager generations")
|
2024-02-12 22:35:55 +00:00
|
|
|
expected = ": id 1 ->"
|
|
|
|
assert expected in actual, \
|
|
|
|
f"expected generations to contain {expected}, but found {actual}"
|
|
|
|
|
|
|
|
with subtest("Home Manager uninstallation"):
|
2024-03-02 19:00:29 +00:00
|
|
|
succeed_as_alice("yes | home-manager uninstall -L")
|
2024-02-12 22:35:55 +00:00
|
|
|
|
2024-03-02 19:00:29 +00:00
|
|
|
fail_as_alice("hello")
|
2024-02-12 22:35:55 +00:00
|
|
|
machine.succeed("test ! -e /home/alice/.cache/.keep")
|
|
|
|
|
2024-03-02 19:00:29 +00:00
|
|
|
# TODO: Fix uninstall to fully remove the share directory.
|
2024-02-12 22:35:55 +00:00
|
|
|
machine.succeed("test ! -e /home/alice/.local/share/home-manager/gcroots")
|
|
|
|
machine.succeed("test ! -e /home/alice/.local/state/home-manager")
|
|
|
|
machine.succeed("test ! -e /home/alice/.local/state/nix/profiles/home-manager")
|
2024-03-02 19:00:29 +00:00
|
|
|
|
|
|
|
logout_alice()
|
2024-02-12 22:35:55 +00:00
|
|
|
'';
|
|
|
|
}
|