From 415e3d98d6faf5fd3d1b7b3daa2f20636e4ff822 Mon Sep 17 00:00:00 2001 From: Hilton Chain Date: Fri, 18 Apr 2025 09:54:02 +0800 Subject: [PATCH] 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 --- doc/guix.texi | 5 +++++ guix/scripts/home.scm | 31 +++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index edfb4caef85..7f796c5fc94 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -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 diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm index b4c82d275f1..55c8edcc01b 100644 --- a/guix/scripts/home.scm +++ b/guix/scripts/home.scm @@ -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)