Add HM bootstrap script and tidy installer workflow

This commit is contained in:
randogoth 2026-02-02 14:04:56 +02:00
parent dd15c09fdd
commit d1713bdc99
10 changed files with 184 additions and 43 deletions

75
scripts/hm-bootstrap.sh Normal file
View file

@ -0,0 +1,75 @@
#!/usr/bin/env bash
set -euo pipefail
# Ensure basic PATH for user units
export PATH="/run/current-system/sw/bin:${PATH:-}"
# Try to hook into the session bus if available
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && [ -S "/run/user/$(id -u)/bus" ]; then
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"
fi
# Only continue in an active, unlocked user session
if command -v loginctl >/dev/null 2>&1 && [ -n "${XDG_SESSION_ID:-}" ]; then
session_class=$(loginctl show-session "${XDG_SESSION_ID}" -p Class --value 2>/dev/null || echo "")
session_state=$(loginctl show-session "${XDG_SESSION_ID}" -p State --value 2>/dev/null || echo "")
session_locked=$(loginctl show-session "${XDG_SESSION_ID}" -p LockedHint --value 2>/dev/null || echo "yes")
if [ "${session_class}" != "user" ] || [ "${session_state}" != "active" ] || [ "${session_locked}" != "no" ]; then
exit 0
fi
fi
wait_for_notifications() {
# Wait briefly for GNOME Shell notifications to come up and the session to be unlocked.
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] || ! command -v gdbus >/dev/null 2>&1; then
return 1
fi
# Do not notify in greeter sessions.
if [ "${XDG_SESSION_CLASS:-}" != "user" ]; then
return 1
fi
# If loginctl is available, wait until this session is unlocked and class=user (not greeter).
if command -v loginctl >/dev/null 2>&1 && [ -n "${XDG_SESSION_ID:-}" ]; then
for _ in 1 2 3 4 5 6 7; do
session_class=$(loginctl show-session "${XDG_SESSION_ID}" -p Class --value 2>/dev/null || echo "")
locked=$(loginctl show-session "${XDG_SESSION_ID}" -p LockedHint --value 2>/dev/null || echo "yes")
if [ "${session_class}" = "user" ] && [ "${locked}" = "no" ]; then
break
fi
sleep 2
done
fi
for _ in 1 2 3 4 5 6 7; do
if gdbus introspect --session \
--dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications >/dev/null 2>&1; then
return 0
fi
sleep 2
done
return 1
}
notify() {
local title="$1"
shift || true
if command -v notify-send >/dev/null 2>&1 && wait_for_notifications; then
notify-send --app-name="Bootstrap" --urgency=critical --expire-time=0 "$title" "$@" >/dev/null 2>&1 || true
fi
}
notify "System setup running" "Please wait until setup completes."
trap 'notify "System setup finished" "You may continue using the system."' EXIT
mkdir -p "$HOME/.config/home-manager"
for f in flake.nix home.nix; do
if [ -f "/etc/skel/.config/home-manager/$f" ] && [ ! -e "$HOME/.config/home-manager/$f" ]; then
cp "/etc/skel/.config/home-manager/$f" "$HOME/.config/home-manager/$f"
fi
done
home-manager switch --flake "$HOME/.config/home-manager#admin"
touch "$HOME/.config/home-manager/.hm_bootstrap_done"