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

@ -42640,6 +42640,11 @@ of the home environment of those users and can be used to deploy
everything consistently at once, saving users the need to run
@command{guix home reconfigure} independently.
@command{guix home} can operate on the home environment configured for
current user via this service, but its effect won't last beyond the next
system activation. This can be used for quick testing and may avoid the
need of keeping a separate home configuration.
@defvar guix-home-service-type
Service type for the Guix Home service. Its value must be a list of
lists containing user and home environment pairs. The key of each pair

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)