home-manager/tests/integration/nixos/basics.nix
Robert Helgesson 4aa9eb327d
WIP home-manager: avoid profile management during activation
This commit deprecates profile management from the activation script.
The profile management is instead the responsibility of the driving
software, for example, the `home-manager` tool in the case of
standalone installs.

The legacy behavior is still available for backwards compatibility but
may be removed in the future.

The new behavior resolves (or moves us closer to resolving) a number
of long standing open issues:

- `home-manager switch --rollback`, which performs a rollback to the
  previous Home Manager generation before activating. While it was
  previously possible to accomplish this by activating an old
  generation, it did always create a new profile generation.

  This option has been implemented as part of this commit.

- `home-manager switch --test`, which activates the configuration but
  does not create a new profile generation.

  This option has _not_ been implemented here since it relies on the
  current configuration being activated on login, which we do not
  currently do.

- When using the "Home Manager as a NixOS module" installation method
  we previously created an odd `home-manager` per-user "shadow
  profile" for the user. This is no longer necessary.

  This has been implemented as part of this commit.

Fixes #3450
2024-06-22 15:15:55 +02:00

99 lines
2.9 KiB
Nix

{ pkgs, ... }:
{
name = "nixos-basics";
meta.maintainers = [ pkgs.lib.maintainers.rycee ];
nodes.machine = { ... }: {
imports = [ ../../../nixos ]; # Import the HM NixOS module.
system.stateVersion = "24.05";
users.users.alice = {
isNormalUser = true;
description = "Alice Foobar";
password = "foobar";
uid = 1000;
};
home-manager = {
enableLegacyProfileManagement = false;
users.alice = { ... }: {
home.stateVersion = "24.05";
home.file.test.text = "testfile";
# Enable a light-weight systemd service.
services.pueue.enable = true;
# We focus on sd-switch since that hopefully will become the default in
# the future.
systemd.user.startServices = "sd-switch";
};
};
};
testScript = ''
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")
def logout_alice():
machine.send_chars("exit\n")
def alice_cmd(cmd):
return f"su -l alice --shell /bin/sh -c $'export XDG_RUNTIME_DIR=/run/user/$UID ; {cmd}'"
def succeed_as_alice(cmd):
return machine.succeed(alice_cmd(cmd))
def fail_as_alice(cmd):
return machine.fail(alice_cmd(cmd))
start_all()
machine.wait_for_unit("home-manager-alice.service")
with subtest("Home Manager file"):
# The file should be linked with the expected content.
path = "/home/alice/test"
machine.succeed(f"test -L {path}")
actual = machine.succeed(f"cat {path}")
expected = "testfile"
assert actual == expected, f"expected {path} to contain {expected}, but got {actual}"
with subtest("Pueue service"):
login_as_alice()
actual = succeed_as_alice("pueue status")
expected = "running"
assert expected in actual, f"expected pueue status to contain {expected}, but got {actual}"
# Shut down pueue, then run the activation again. Afterwards, the service
# should be running.
machine.succeed("systemctl --user -M alice@.host stop pueued.service")
fail_as_alice("pueue status")
machine.systemctl("restart home-manager-alice.service")
machine.wait_for_unit("home-manager-alice.service")
actual = succeed_as_alice("pueue status")
expected = "running"
assert expected in actual, f"expected pueue status to contain {expected}, but got {actual}"
logout_alice()
with subtest("no GC root and profile"):
# There should be no GC root and Home Manager profile since we are not
# using legacy profile management.
hmState = "/home/alice/.local/state/home-manager"
machine.succeed(f"test ! -e {hmState}")
hmProfile = "/home/alice/.local/state/nix/profiles/home-manager"
machine.succeed(f"test ! -e {hmProfile}")
'';
}