Commit 93f38af
Eric Bower
·
2026-09-01 22:05:59 -0400 EDT
parent f662a0a
feat: add desktop systemd unit files
12 files changed,
+207,
-0
1@@ -0,0 +1,13 @@
2+[Unit]
3+Description=imap notify service
4+After=network.target
5+StartLimitIntervalSec=0
6+
7+[Service]
8+Type=simple
9+Restart=always
10+RestartSec=5
11+ExecStart=/home/erock/go/bin/goimapnotify -conf /home/erock/.config/imapnotify/fastmail
12+
13+[Install]
14+WantedBy=default.target
+15,
-0
1@@ -0,0 +1,15 @@
2+[Unit]
3+Description=Dynamic output configuration for Wayland compositors
4+Documentation=man:kanshi(1)
5+PartOf=graphical-session.target
6+After=graphical-session.target
7+Requisite=graphical-session.target
8+
9+[Service]
10+Type=simple
11+ExecStart=/usr/bin/kanshi
12+Restart=always
13+RestartSec=2
14+
15+[Install]
16+WantedBy=wayland-session.target
1@@ -0,0 +1,6 @@
2+[Unit]
3+Description=mail sync service
4+After=network.target
5+
6+[Service]
7+ExecStart=/home/erock/.local/bin/mailsync
1@@ -0,0 +1,9 @@
2+[Unit]
3+Description=run mail sync
4+
5+[Timer]
6+OnCalendar=*:0/5
7+Persistent=true
8+
9+[Install]
10+WantedBy=timers.target
+14,
-0
1@@ -0,0 +1,14 @@
2+[Unit]
3+Description=Sway wallpaper daemon
4+Documentation=man:swaybg(1)
5+PartOf=graphical-session.target
6+After=graphical-session.target
7+Requisite=graphical-session.target
8+
9+[Service]
10+Type=simple
11+ExecStart=/usr/bin/swaybg -i %h/config/wallpapers/webb_telescope.png -m fill
12+Restart=on-failure
13+
14+[Install]
15+WantedBy=wayland-session.target
+14,
-0
1@@ -0,0 +1,14 @@
2+[Unit]
3+Description=Idle manager for Wayland
4+Documentation=man:swayidle(1)
5+PartOf=graphical-session.target
6+After=graphical-session.target
7+Requisite=graphical-session.target
8+
9+[Service]
10+Type=simple
11+ExecStart=/usr/bin/swayidle -w
12+Restart=on-failure
13+
14+[Install]
15+WantedBy=wayland-session.target
+10,
-0
1@@ -0,0 +1,10 @@
2+[Unit]
3+Description=Screen locker for Wayland
4+Documentation=man:swaylock(1)
5+PartOf=graphical-session.target
6+After=graphical-session.target
7+
8+[Service]
9+Type=forking
10+ExecStart=/usr/bin/swaylock
11+Restart=on-failure
1@@ -0,0 +1,10 @@
2+[Unit]
3+Description=sync calendar and contacts
4+After=network.target
5+
6+[Service]
7+Type=oneshot
8+ExecStart=/home/erock/.local/bin/uvx vdirsyncer==0.20.0 -v INFO sync
9+
10+[Install]
11+WantedBy=default.target
1@@ -0,0 +1,9 @@
2+[Unit]
3+Description=sync calendar and contacts on timer
4+
5+[Timer]
6+OnUnitInactiveSec=5min
7+OnBootSec=10s
8+
9+[Install]
10+WantedBy=timers.target
1@@ -0,0 +1,6 @@
2+[Unit]
3+Description=Wayland graphical session
4+Documentation=man:systemd.special(7)
5+BindsTo=graphical-session.target
6+Wants=graphical-session-pre.target
7+After=graphical-session-pre.target
+14,
-0
1@@ -0,0 +1,14 @@
2+[Unit]
3+Description=Day/night gamma adjustments for Wayland compositors
4+Documentation=man:wlsunset(1)
5+PartOf=graphical-session.target
6+After=graphical-session.target
7+Requisite=graphical-session.target
8+
9+[Service]
10+Type=simple
11+ExecStart=/usr/bin/wlsunset -l 42.3 -L -83.0 -t 3000
12+Restart=on-failure
13+
14+[Install]
15+WantedBy=wayland-session.target
+87,
-0
1@@ -0,0 +1,87 @@
2+#!/usr/bin/env bash
3+set -euo pipefail
4+
5+# ==============================================================================
6+# 1. Background user units -> enabled and started now
7+# ==============================================================================
8+USER_UNITS=(
9+ mailsync.timer
10+ # imapnotify.service
11+ # vdirsyncer.timer
12+)
13+
14+# ==============================================================================
15+# 2. Wayland session units -> enabled only (started with wayland-session.target)
16+# ==============================================================================
17+WAYLAND_UNITS=(
18+ kanshi.service
19+ swaybg.service
20+ swayidle.service
21+ swaylock.service
22+ wlsunset.service
23+)
24+
25+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26+DOTFILES_UNITS_DIR="$SCRIPT_DIR/dot_config/systemd/user"
27+
28+is_tracked() {
29+ local item="$1"
30+ shift
31+ for elem in "$@"; do
32+ [[ "$elem" == "$item" ]] && return 0
33+ done
34+ return 1
35+}
36+
37+case "${1:-enable}" in
38+enable|link|up)
39+ echo "==> Step 1: Reloading systemd user daemon"
40+ systemctl --user daemon-reload
41+
42+ # Auto-disable any dotfile units that were removed/commented out from the arrays
43+ echo "==> Step 2: Pruning untracked dotfile units"
44+ if [[ -d "$DOTFILES_UNITS_DIR" ]]; then
45+ for file in "$DOTFILES_UNITS_DIR"/*; do
46+ [[ -f "$file" ]] || continue
47+ unit="$(basename "$file")"
48+ [[ "$unit" == *.target ]] && continue
49+
50+ if ! is_tracked "$unit" "${USER_UNITS[@]}" "${WAYLAND_UNITS[@]}"; then
51+ if systemctl --user is-enabled "$unit" &>/dev/null; then
52+ echo " [PRUNE] $unit is enabled but not in tracked list -> disabling and stopping"
53+ systemctl --user disable --now "$unit" 2>/dev/null || true
54+ fi
55+ fi
56+ done
57+ fi
58+
59+ echo "==> Step 3: Enabling and starting user services & timers"
60+ for unit in "${USER_UNITS[@]}"; do
61+ echo " [USER] systemctl --user enable --now $unit"
62+ systemctl --user enable --now "$unit" || echo " [WARN] Failed to start $unit" >&2
63+ done
64+
65+ echo "==> Step 4: Enabling Wayland session services"
66+ for unit in "${WAYLAND_UNITS[@]}"; do
67+ echo " [WAYLAND] systemctl --user enable $unit"
68+ systemctl --user enable "$unit" 2>/dev/null || true
69+ done
70+ ;;
71+
72+disable|stop|down)
73+ echo "==> Disabling and stopping all dotfile units"
74+ for unit in "${USER_UNITS[@]}" "${WAYLAND_UNITS[@]}"; do
75+ echo " Disabling: $unit"
76+ systemctl --user disable --now "$unit" 2>/dev/null || true
77+ done
78+
79+ echo "==> Reloading systemd user daemon"
80+ systemctl --user daemon-reload
81+ systemctl --user reset-failed 2>/dev/null || true
82+ ;;
83+
84+*)
85+ echo "Usage: $0 [enable|disable]" >&2
86+ exit 1
87+ ;;
88+esac