Nix and sway-home
Nothing on this page has been run on a machine built by this book yet.
The rest of the desktop is user’s, installed by user. user has
no SSH key and no sudo, so get a shell as user from your admin
session – a full login, with user’s own systemd user manager and
session bus:
sudo machinectl shell user@
Not sudo -iu user: that gives a shell without a session bus, and
Home Manager’s step that writes GNOME settings (dark mode, here) then
starts a D-Bus daemon of its own from Nix, which looks for its
configuration in /etc/dbus-1/ – where NixOS keeps it and Arch does
not – and fails. Logged in at tuigreet, user has a bus already.
Then clone sway-home and let Home Manager install it:
sway-home’s support for non-NixOS hosts – GPU drivers, nm-applet
only where NetworkManager runs, a working hm-install – is on its
arch branch until it is merged. Until then, clone with --branch arch.
git clone https://github.com/EnigmaCurry/sway-home ~/git/vendor/enigmacurry/sway-home cd ~/git/vendor/enigmacurry/sway-home just hm-install
hm-install asks for the name and email address to put in git’s
configuration, then builds the Home Manager configuration in
home-manager/ and switches to it: the packages land in the Nix
store, and ~/.config, ~/bin, ~/.bashrc and the rest become links
into it. Dotfiles already in the way are renamed to *.backup. The
first run downloads a great deal; later ones only what changed.
From then on, as user:
| Command | What it does |
|---|---|
hm-switch |
Apply changes after editing sway-home |
hm-pull |
Pull the latest sway-home |
hm-update |
Move nixpkgs and Home Manager forward (then hm-switch) |
hm-generations |
List previous versions of the environment |
hm-rollback |
Go back to the previous one |
Programs from Nix are updated the Nix way, not by pacman: admin upgrade moves sway, greetd and the rest of the system forward, while
firefox, foot, emacs and everything else in sway-home move when its
flake.lock does – hm-update then hm-switch, or hm-pull to
take the lock sway-home’s repository has. Each switch is a new
generation, so hm-rollback undoes one.
sway-home’s own HOME_MANAGER.md describes the rest. This is the
user’s half of the “two halves” in the chapter introduction: admin
keeps the system in step with ~admin/arch, and Home Manager keeps
user’s environment in step with sway-home, each with its own
history and its own way back.
GPU drivers for programs from Nix
Programs from Nix are linked against Nix’s own copy of Mesa, which
cannot load the drivers Arch installed: without help, firefox and
anything else that draws with OpenGL or Vulkan falls back to the CPU.
Home Manager’s answer for non-NixOS systems is
targets.genericLinux, which sway-home turns on outside NixOS: it
builds the GPU drivers from Nix, to match, and asks for one command
to be run as root to link them into place as /run/opengl-driver.
user has no sudo, so admin runs it, from user’s profile:
sudo /home/user/.nix-profile/bin/non-nixos-gpu-setup
It installs a link in /etc/tmpfiles.d, so that the drivers are linked
again at every boot. Run it once more whenever hm-switch says the
drivers changed. The link points into the Nix store and moves with
every update, so setup seeds 90-ignore.sh with a line that has
aconfmgr leave it alone. (A host repo seeded before that needs the
line added: IgnorePath '/etc/tmpfiles.d/non-nixos-gpu.conf'.)
Log in
Log out of the user shell, and at the machine itself, log in as
user at tuigreet. It starts sway, with sway-home’s configuration.
Networking
This machine does not run NetworkManager – it uses systemd-networkd
and iwd, as the install set up – so sway-home leaves out nm-applet,
the NetworkManager tray icon: it installs it only where
NetworkManager.service exists. For WiFi, iwctl does the same job
from a terminal. If you would rather have NetworkManager, the host
page shows how to switch the host repo over to it; run hm-switch
afterwards and the applet comes back.