Explain user-systemd noise instead of only repeating it

Home Manager's reloadSystemd reports the whole user manager before it
reloads anything, so one failed distro unit (xdg-desktop-portal* on a
host with no display, dbus-activated by an agent CLI) makes every
switch look broken. It starts none of those units.

dot doctor now prints the user session state, the failed units with a
reset-failed hint (--fix runs it), restart-looping units, and the units
in ~/.config/systemd/user that no home-manager generation owns. README
gains 'What belongs in dotfiles': the four gated units this repo
declares, the pi-workers file that is tracked but wired by hand, and
why portal and root units must stay out.

tests/doctor-systemd.sh covers the report and the --fix path.
This commit is contained in:
Ziad Arafat committed 2026-12-02 12:08:29 -07:00
1 parent 7ca1845213
commit acb8191f13
3 files changed
+144 -2

No files matched your search

+47
View File
@@ -295,6 +295,53 @@ Apps that write their own settings (Claude Code, pi, Vesktop, Konsole profiles,
- **Defguard VPN** (home lab, `vpn.godemperordoge.org`): the desktop client is repackaged from the official `.deb` in `pkgs/defguard-client.nix`, so it runs natively on SteamOS (no WebKitGTK 4.1 there). `dot system` installs its root service (`config/defguard/defguard-service.service`, group `defguard`, a `resolvconf` → `resolvectl` shim where needed). Setup tokens are single-use and expire in 24 h, so Bitwarden holds a Defguard **API token** instead: create one in Defguard (your profile → *API tokens*) once, `dot secrets set DEFGUARD_API_TOKEN`, then on each new machine run `dot defguard` from home or over the VPN. It mints a fresh token and writes `~/.local/share/net.defguard/provisioning.json`, and the app sets itself up on its next start; you only sign in with Doge Home Lab.
- **Sounds:** `dot sounds` extracts Portal 2 sounds from your local Steam install (game assets stay out of git) into `~/.local/share/sounds/portal2`. Mapping: `config/sounds/portal2.json`.
## What belongs in dotfiles (and what does not)
`home-manager switch` links files and reloads the **user** systemd manager. It does
not own everything that manager runs, so anything it reports about units may be
about the host, not about this repository.
| Declared here (`systemd.user.*`) | Where | Profile | Why it belongs |
|---|---|---|---|
| `handoff`, `handoff-probe` + timer | `home/agents.nix` | all | ship `bin/handoff`/`bin/free-agent` from this repo |
| `fix-container-desktop-files` (path + oneshot) | `home/gui/apps.nix` | gui only | runs this repo's launcher rewriter |
| `konsole-daynight`, `daynight-hooks` | `home/gui/daynight.nix` | gui only | wrap the `konsole_daynight` flake input |
| `notification-sounds` | `home/gui/sounds.nix` | gui only | plays the sound theme `dot sounds` builds |
| `pi-workers` | `config/systemd/user/` | linked by hand | **not** installed by home-manager; wire it with `home.file` or drop it |
Everything else under `~/.config/systemd/user` on a machine (edge metrics, relays,
study timers) is a hand-written one-off. `dot doctor` lists those separately.
Two classes of unit must stay **out** of dotfiles:
- **Desktop-session units** the distro or the desktop environment owns, above all
`xdg-desktop-portal*`. Nix cannot know whether a session has a display, the
distro already defines them in `/usr/lib/systemd/user`, and shadowing them breaks
the desktop. Dotfiles' job on those is at most to mask them on headless hosts.
- **Root/system units** (netbird, Defguard, podman). `dot system` puts those in
`/etc`; they are not user-manager state and cannot be switched per profile.
### "The user systemd session is degraded"
Home Manager's `reloadSystemd` step asks `systemctl --user is-system-running`
*before* reloading and prints every failed unit. It starts none of them and cannot
clear them, so the same two lines reappear on every `dot switch` until the state is
reset. On a headless machine the usual cause is a portal unit: something asks D-Bus
for `org.freedesktop.portal.Desktop` (an agent CLI with notification support, an
Electron app), systemd starts the distro's `xdg-desktop-portal-gtk`, that process
has no display, and it times out into a failed state.
```bash
dot doctor # session state, failed units, restart loops, unmanaged units
dot doctor --fix # reset-failed the units it found (the session stops looking degraded)
systemctl --user mask xdg-desktop-portal xdg-desktop-portal-gtk # headless: stop the retries
```
`warning: unknown setting 'eval-cores'` / `'lazy-trees'` during activation is the
same kind of noise: those keys are Determinate Nix settings in `/etc/nix/nix.conf`,
while this repo pins `nix.package = pkgs.nix` (upstream) so the same flake works on
SteamOS and in containers. The warnings are harmless.
## Custom Pokémon rules
Reusable rules live in [`config/pokefetch`](config/pokefetch/README.md), including the Arceus holiday/weather preset and the Lugia day/night example. Add future presets there and enable one from your machine-local settings.
+47 -2
View File
@@ -824,8 +824,52 @@ cmd_update() {
cmd_apps
}
# Home Manager's reloadSystemd step reports the state of the *whole* user manager
# before it reloads anything, so one failed third-party unit (a portal service on a
# display-less host) makes every switch print a wall of warnings. It never starts
# those units, and it cannot clear them. Diagnose them here, on demand.
systemd_user_report() {
local fix="${1:-0}" state units oneline flapping u portals=() unmanaged=() path real
has_systemd || return 0
state="$(systemctl --user is-system-running 2>/dev/null || true)"
printf 'user systemd: %s\n' "${state:-unknown}"
units="$(systemctl --user --no-pager --no-legend --plain --state=failed list-units 2>/dev/null | awk 'NF{print $1}')"
if [ -n "${units// /}" ]; then
oneline="$(echo $units)"
warn "failed user units (Home Manager repeats these on every switch):"
printf ' %s\n' $units
for u in $units; do case "$u" in xdg-desktop-portal*) portals+=("$u");; esac; done
if [ "$fix" = 1 ]; then
# shellcheck disable=SC2086
systemctl --user reset-failed $units 2>/dev/null && ok "cleared failed state: $oneline"
else
printf ' clear the state: systemctl --user reset-failed %s\n' "$oneline"
fi
[ ${#portals[@]} -eq 0 ] || printf ' no display here: any app asking D-Bus for org.freedesktop.portal.Desktop starts\n %s, which cannot open a display and times out. Masking stops the\n retries: systemctl --user mask %s\n' "$(echo "${portals[*]}")" "$(echo "${portals[*]}")"
fi
flapping="$(systemctl --user --no-pager --no-legend --plain --state=activating list-units 2>/dev/null | awk '$4 == "auto-restart" {print $1}')"
[ -z "${flapping// /}" ] || { warn "restart-looping user units (each retry writes to the journal):"; printf ' %s\n' $flapping; printf ' inspect: systemctl --user status <unit> / stop: systemctl --user stop <unit>\n'; }
# Units in ~/.config/systemd/user that no home-manager generation owns. Tracked
# files wired by hand, and one-off units written straight into the home.
for path in "$HOME/.config/systemd/user"/*.service "$HOME/.config/systemd/user"/*.timer; do
[ -e "$path" ] || continue
real="$(readlink -f "$path" 2>/dev/null || true)"
case "$real" in
/nix/store/*) continue ;;
"$DOTFILES_DIR"/*) unmanaged+=("$(basename "$path") [git, wired by hand]") ;;
*) unmanaged+=("$(basename "$path") [not in dotfiles]") ;;
esac
done
if [ ${#unmanaged[@]} -gt 0 ]; then
warn "user units outside home-manager (neither 'dot switch' nor git clean-up covers these):"
printf ' %s\n' "${unmanaged[@]}"
printf ' move the ones you want to keep into home/<module>.nix (systemd.user.services) and delete the file\n'
fi
}
cmd_doctor() {
local p; p="$(profile)"
local p fix=0; [ "${1:-}" = --fix ] && fix=1
p="$(profile)"
printf 'os=%s profile=%s container=%s systemd=%s\n' "$(os_id)" "$p" "$(in_container && echo yes || echo no)" "$(has_systemd && echo yes || echo no)"
chk() { if eval "$2" >/dev/null 2>&1; then ok "$1"; else warn "$1 — $3"; fi; }
# Diagnose interrupted installs and disabled features independently, without
@@ -877,6 +921,7 @@ cmd_doctor() {
chk "day/night daemons (XDG autostart)" "pgrep -f daynight-hooks" "log in to Plasma"
fi
fi
systemd_user_report "$fix"
}
cmd_bootstrap() {
@@ -918,7 +963,7 @@ dot — portable dev environment
dot wallpapers [--push] sort wallpapers into light/dark (or clone them)
dot sounds [build|test|notify] Portal 2 sound theme: build it, play every sound, or fire a test notification
dot boxes create distroboxes from distrobox.ini
dot doctor check what's installed
dot doctor [--fix] check what's installed; --fix clears failed user units
EOF
}
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# dot doctor's user-systemd report: it must explain, not just repeat, the units
# Home Manager prints at switch time.
set -euo pipefail
cd "$(dirname "$0")/.."
fixture="$(mktemp -d)"
trap 'rm -rf "$fixture"' EXIT
export HOME="$fixture/home"
mkdir -p "$HOME/.config/dotfiles" "$HOME/.config/systemd/user" "$fixture/repo"
DOTFILES_DIR="$fixture/repo"
export DOTFILES_DIR
source <(sed '$d' bin/dot)
STATE_DIR="$HOME/.config/dotfiles"
has_systemd() { return 0; }
profile() { echo headless; }
reset_calls="$fixture/reset.log"
: >"$reset_calls"
systemctl() {
case "$*" in
"--user is-system-running") echo degraded ;;
*"--state=failed list-units"*)
printf 'xdg-desktop-portal-gtk.service loaded failed failed Portal service (GTK)\n'
printf 'xdg-desktop-portal.service loaded failed failed Portal service\n' ;;
*"--state=activating list-units"*)
printf 'relay.service loaded activating auto-restart Temporary relay\n' ;;
*reset-failed*) printf '%s\n' "${*: -2}" >>"$reset_calls" ;;
esac
}
# A unit tracked in git but wired by hand, and one that lives only in the home.
printf '[Unit]\nDescription=x\n' >"$DOTFILES_DIR/pi-workers.service"
ln -s "$DOTFILES_DIR/pi-workers.service" "$HOME/.config/systemd/user/pi-workers.service"
printf '[Unit]\nDescription=y\n' >"$HOME/.config/systemd/user/edge-metrics.service"
out="$(systemd_user_report 0)"
grep -q 'user systemd: degraded' <<<"$out" || { echo "FAIL: session state missing"; exit 1; }
grep -q 'systemctl --user reset-failed xdg-desktop-portal-gtk.service xdg-desktop-portal.service' <<<"$out" \
|| { echo "FAIL: reset hint missing or wrapped"; echo "$out"; exit 1; }
grep -q 'no display here' <<<"$out" || { echo "FAIL: portal explanation missing"; exit 1; }
grep -q 'relay.service' <<<"$out" || { echo "FAIL: restart loop not reported"; exit 1; }
grep -q 'pi-workers.service \[git, wired by hand\]' <<<"$out" || { echo "FAIL: tracked-by-hand unit not reported"; exit 1; }
grep -q 'edge-metrics.service \[not in dotfiles\]' <<<"$out" || { echo "FAIL: unmanaged unit not reported"; exit 1; }
[ -s "$reset_calls" ] && { echo "FAIL: --fix not requested but reset-failed was called"; exit 1; }
systemd_user_report 1 >/dev/null
grep -q 'xdg-desktop-portal.service' "$reset_calls" || { echo "FAIL: --fix did not reset the failed units"; exit 1; }
echo "ok dot doctor systemd report"