scripts: home: Support extracting home-environment from Guix System declaration.

* guix/scripts/home.scm (process-action): Handle operating-system declaration
and extract home environment for current user.
* doc/guix.texi (Guix Services)[Guix Home Service]: Document it.

Change-Id: I995f79c2549e6edc76322542d0422159e0b79996
Reviewed-by: Maxim Cournoyer <maxim.cournoyer@gmail>
This commit is contained in:
Hilton Chain 2025-04-18 09:54:02 +08:00
parent 12467f2c91
commit 415e3d98d6
No known key found for this signature in database
GPG key ID: ACC66D09CA528292
2 changed files with 32 additions and 4 deletions

View file

@ -35,6 +35,8 @@
shepherd-service-requirement)
#:autoload (guix modules) (source-module-closure)
#:autoload (gnu build linux-container) (call-with-container %namespaces)
#:use-module ((gnu system) #:select (operating-system?
operating-system-user-services))
#:autoload (gnu system linux-container) (eval/container)
#:autoload (gnu system file-systems) (file-system-mapping
file-system-mapping-source
@ -478,10 +480,31 @@ ACTION must be one of the sub-commands that takes a home environment
declaration as an argument (a file name.) OPTS is the raw alist of options
resulting from command-line parsing."
(define (ensure-home-environment file-or-exp obj)
(unless (home-environment? obj)
(leave (G_ "'~a' does not return a home environment~%")
file-or-exp))
obj)
(let* ((username
(or (getenv "USER")
(passwd:name (getpwnam (getuid)))))
(os-home-env-config
(and (operating-system? obj)
(and=> (find (lambda (%service)
(eq? (service-type-name (service-kind %service))
'guix-home))
(operating-system-user-services obj))
service-value)))
(os-home-env
(and os-home-env-config
(and=> (find (lambda (home-env-config)
(string=? (first home-env-config) username))
os-home-env-config)
second)))
(home-env
(or os-home-env obj)))
(unless (home-environment? home-env)
(if (operating-system? obj)
(leave (G_ "'~a' does not contain a home environment for user '~a'~%")
file-or-exp username)
(leave (G_ "'~a' does not return a home environment~%")
file-or-exp)))
home-env))
(let* ((file (match args
(() #f)