summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Paśnikowski <marek@marekpasnikowski.pl>2026-12-01 22:13:43 +0100
committerMarek Paśnikowski <marek@marekpasnikowski.pl>2026-12-01 22:50:10 +0100
commit5b1b42e3ee88e408d0e3d7bfcb26ae9cbc23992e (patch)
tree6214e83ec795a2d9bc9acee1c18e1c033d8a3f14
parent6f5539290c9acad39d55cc31c59ba807cd32aa3d (diff)
(deployment services admin): rework bash aliases into standalone commandsHEADtestmaster
* Rename export update-commands to bash-aliases_service-record and the service to 'bash-aliases. * Drop the "guix", "guix-test", "pull-down", "reconfigure-down" and "sudo" aliases and the (deployment channels) import. * Rename "pull" to "pull-guix" and "reconfigure" to "reconfigure-system". * Bind "collect-garbage", "delete-generations" and the renamed aliases to full command lines with "sudo guix" embedded, replacing bare fragments expanded after the "guix" and "sudo" aliases. * Factor the twice-hardcoded "7d" into retention-duration_string, validated at build time with string->duration. * Replace $HOSTNAME with a ${HOSTNAME:?HOSTNAME is not set} guard and wrap the reconfigure-system and upgrade-system values in literal-string, deferring expansion from .bashrc load to invocation. * Add the upgrade-system alias, chaining pull, reconfigure, delete-generations and gc with "&&". * Add a rationale comment above each definition.
-rw-r--r--deployment/services/admin.scm79
-rw-r--r--users/id1000.scm2
-rw-r--r--users/id1001.scm2
3 files changed, 63 insertions, 20 deletions
diff --git a/deployment/services/admin.scm b/deployment/services/admin.scm
index 24103ef..b49f86f 100644
--- a/deployment/services/admin.scm
+++ b/deployment/services/admin.scm
@@ -19,23 +19,66 @@
;;; If not, see <https://www.gnu.org/licenses/>.
(define-module (deployment services admin)
- #:export (update-commands)
- #:use-module (deployment channels)
+ #:export (bash-aliases_service-record)
+ #:use-module (gnu home services)
#:use-module (gnu home services shells)
- #:use-module (gnu services))
+ #:use-module (gnu services)
+ #:use-module (guix ui))
-(define update-commands
- (simple-service
- 'update-commands
- home-bash-service-type
- (home-bash-extension
- (aliases
- `(("collect-garbage" . "gc -d 7d ")
- ("delete-generations" . "system delete-generations 7d ")
- ("guix" . ,(guix-with-channels master-channels))
- ("guix-test" . ,(guix-with-channels test-channels))
- ("pull" . " pull --fallback ")
- ("pull-down" . "pull --allow-downgrades --disable-authentication --fallback ")
- ("reconfigure" . "system reconfigure -e \"(@ (deployment system) $HOSTNAME)\" --fallback ")
- ("reconfigure-down" . "system reconfigure --allow-downgrades -e \"(@ (deployment system) $HOSTNAME)\" --fallback ")
- ("sudo" . "sudo "))))))
+;; Retention threshold shared by the two generation scopes below: the
+;; system generations and the machine-wide pruning of "guix gc -d".
+;; Fail here, at build time, on anything "guix ui" does not parse as a
+;; duration: with the argument absent, both commands fall back to
+;; unrooting every generation but the current one, so an empty value
+;; must never reach the command lines.
+(define retention-duration_string "7d")
+
+(unless (string->duration retention-duration_string)
+ (error "retention duration is not a duration string"
+ retention-duration_string))
+
+;; As root, "guix gc -d" first unroots the profile and home-environment
+;; generations of every user older than the retention duration, then
+;; collects garbage in the same invocation.
+(define collect-garbage_string
+ (string-append "sudo guix gc -d "
+ retention-duration_string))
+
+;; Unroots the system generations older than the retention duration and
+;; reinstalls the bootloader menu; the store space is reclaimed only by
+;; the garbage collection pass.
+(define system-delete-generations_string
+ (string-append "sudo guix system delete-generations "
+ retention-duration_string))
+
+;; Updates the user's guix only. The system-wide guix is deployed by CI
+;; through the channels mechanism, so this pull does not feed the
+;; reconfigure below, and it stays unprivileged by design.
+(define pull_string "guix pull --fallback")
+
+;; Wrapped in "literal-string" in the alist below, so the serializer
+;; single-quotes the whole value: the guard stays literal while .bashrc
+;; is sourced and resolves at invocation, firing only when the host
+;; name is empty, the kernel's own or one inherited from the environment.
+(define system-reconfigure_string
+ "sudo guix system reconfigure -e \"(@ (deployment system) ${HOSTNAME:?HOSTNAME is not set})\" --fallback")
+
+;; The order is causal: the generations unrooted above are reclaimed by
+;; the collection pass of "guix gc -d", so it runs last, and "&&" stops
+;; the chain before anything is unrooted or collected.
+(define upgrade_string
+ (string-append pull_string
+ " && " system-reconfigure_string
+ " && " system-delete-generations_string
+ " && " collect-garbage_string))
+
+(define bash-aliases_service-record
+ (simple-service 'bash-aliases
+ home-bash-service-type
+ (home-bash-extension
+ (aliases
+ `(("collect-garbage" . ,collect-garbage_string)
+ ("delete-generations" . ,system-delete-generations_string)
+ ("pull-guix" . ,pull_string)
+ ("reconfigure-system" . ,(literal-string system-reconfigure_string))
+ ("upgrade-system" . ,(literal-string upgrade_string)))))))
diff --git a/users/id1000.scm b/users/id1000.scm
index d21bd5d..7555a91 100644
--- a/users/id1000.scm
+++ b/users/id1000.scm
@@ -281,7 +281,7 @@
(packages (cons* gnu:packages:version-control:git
gnu:packages:disk:gparted
sovereign:systems:common-home-environment-packages))
- (services (cons* deployment:services:admin:update-commands
+ (services (cons* deployment:services:admin:bash-aliases_service-record
l-home-dbus-service
l-home-pipewire-service
l-home-shepherd-service
diff --git a/users/id1001.scm b/users/id1001.scm
index 1a76ab6..9019a66 100644
--- a/users/id1001.scm
+++ b/users/id1001.scm
@@ -44,7 +44,7 @@
"Noto")))
(let
( (l-services (list sovereign:systems:bash-configuration
- deployment:services:admin:update-commands
+ deployment:services:admin:bash-aliases_service-record
l-fontconfig)))
(gnu:home:home-environment
(packages (cons* gnu:packages:libreoffice:libreoffice