X-Loop: help-debbugs@HIDDEN Subject: [bug#69781] [PATCH] services: Add the Guix Home Service Resent-From: Richard Sent <richard@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: , guix-patches@HIDDEN Resent-Date: Wed, 13 Mar 2024 19:00:02 +0000 Resent-Message-ID: <handler.69781.B.17103563977003 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: report 69781 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 69781 <at> debbugs.gnu.org Cc: Richard Sent <richard@HIDDEN>, andrew@HIDDEN, ( <paren@HIDDEN>, Andrew Tropin <andrew@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN> X-Debbugs-Original-To: guix-patches@HIDDEN X-Debbugs-Original-Xcc: ( <paren@HIDDEN>, Andrew Tropin <andrew@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN> Received: via spool by submit <at> debbugs.gnu.org id=B.17103563977003 (code B ref -1); Wed, 13 Mar 2024 19:00:02 +0000 Received: (at submit) by debbugs.gnu.org; 13 Mar 2024 18:59:57 +0000 Received: from localhost ([127.0.0.1]:47420 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1rkTpV-0001ot-02 for submit <at> debbugs.gnu.org; Wed, 13 Mar 2024 14:59:57 -0400 Received: from lists.gnu.org ([209.51.188.17]:56644) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <richard@HIDDEN>) id 1rkTpS-0001ok-TA for submit <at> debbugs.gnu.org; Wed, 13 Mar 2024 14:59:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <richard@HIDDEN>) id 1rkToq-0007Ys-JB for guix-patches@HIDDEN; Wed, 13 Mar 2024 14:59:17 -0400 Received: from mail-108-mta84.mxroute.com ([136.175.108.84]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <richard@HIDDEN>) id 1rkToo-0005pC-HA for guix-patches@HIDDEN; Wed, 13 Mar 2024 14:59:16 -0400 Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta84.mxroute.com (ZoneMTA) with ESMTPSA id 18e392a0e5d0003bea.001 for <guix-patches@HIDDEN> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 13 Mar 2024 18:54:01 +0000 X-Zone-Loop: a70feebf12a97cf97e9ed5b715b808ef87de3c9ba2d6 X-Originating-IP: [136.175.111.2] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=RPo7Ay/LuJbkrX3JsDHLdkL8t617dy9K63vGGHquuEE=; b=OnHRZjE3i9UCL9HOKQXKwBJqq9 BQxqMQ80SbUKQepwgX/3r0Ubtd7PljUMF3195ht9GPKS2pzyHmikI81ZE5rIRh/iOvBMoKwmhmxNA rEeniZuW0Bwof83qotBWMis72tajRXmGvmekM8fKSCZXlYvhaVhzDWdf7GO6YutrX58DiQXWSiD3c pj+nTSOdI4kgyvguWXFjR1yjvnw2Xxh5uubQ7ShFRi9mFbuDDKfoUiCucYVMu+NMABwazb1lxu0C9 9YDrISUCFcOrrLTb9lfGINKjGN4UhGvSqFvwATqol1LfpbNJwzEHdfgEFi/N2wQWVivhjrz0mvqib Ikp6QBNQ==; From: Richard Sent <richard@HIDDEN> Date: Wed, 13 Mar 2024 14:41:40 -0400 Message-ID: <05fd930c91838ce9640720ce68e3379f10154590.1710355300.git.richard@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Authenticated-Id: richard@HIDDEN Received-SPF: pass client-ip=136.175.108.84; envelope-from=richard@HIDDEN; helo=mail-108-mta84.mxroute.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -2.4 (--) This patch adds a Guix Home Service, which allows for configuring/deploying an operating-system declaration with an associated home-environment. * gnu/services/guix.scm: Add guix-home-service and guix-home-shepherd-service * gnu/home/services/shepherd.scm: Don't attempt to launch user shepherd when the system shepherd runs guix-home-<user> * doc/guix.texi: Add documentation for guix-home-service Change-Id: Ifbcc0878d934aa4abe34bb2123b5081fb432aa8e --- Hi Guix. This patch adds support for activating a home configuration as part of a Guix System configuration. It does this by creating a one-shot shepherd service that runs the home environment activation script. This patch is based on code from Andrew Tropin [1], used with permission. [2]. Given that fact I'm not 100% sure I handled the copyright headers correctly; let me know if they need changed. There was an issue where the activation script would attempt to also launch the user-level shepherd, which would fail as /run/user/<uid> would not usually exist. It was a benign issue (symlinks would still be set up), but I decided an environment variable would be the best way to avoid printing spurious warnings to the shepherd log file. I also changed the rde code from relying on term-tty1 to user-processes. I've not observed any failed activations with this change and it also allows the operating-system to run in a container, unlike term-tty1. [1] https://git.sr.ht/~abcdw/rde/tree/master/item/src/gnu/services/home.scm [2] https://lists.sr.ht/~abcdw/rde-discuss/%3C87h6j0rqmi.fsf%40freakingpenguin.com%3E doc/guix.texi | 32 ++++++++++++++++++++++++++++ gnu/home/services/shepherd.scm | 7 +++++- gnu/services/guix.scm | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 858d5751bf..5523d1a174 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -125,6 +125,7 @@ Copyright @copyright{} 2023 Graham James Addis@* Copyright @copyright{} 2023 Tomas Volf@* Copyright @copyright{} 2024 Herman Rimm@* +Copyright @copyright{} 2024 Richard Sent@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -39567,6 +39568,37 @@ Guix Services @end table @end deftp +@subsubheading Guix Home Service +The Guix Home Service allows for associating Guix @ref{Declaring the +Home Environment, home-environment} declarations with a Guix +@ref{operating-system Reference, operating-system}. + +@defvar guix-home-service-type +Service type for the Guix Home Service. Its value must be an +association list. The key of each pair is a string representing the user +to deploy the configuration under and the value is a home-environment +configuration. + +@lisp +(define my-home + (home-environment + ...)) + +(operating-system + (services (list + (service guix-home-service-type + `(("alice" ,my-home)))))) +@end lisp + +This service can be extended by other services to add additional home +environments, as in this example: + +@lisp +(simple-service 'my-extra-home home-service-type + `(("bob" ,my-extra-home)))) +@end lisp +@end defvar + @subsubheading Nar Herder The @uref{https://git.cbaines.net/guix/nar-herder/about/,Nar Herder} is a utility for managing a collection of nars. diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm index 176f4575cb..e68dea6954 100644 --- a/gnu/home/services/shepherd.scm +++ b/gnu/home/services/shepherd.scm @@ -132,7 +132,12 @@ (define (ensure-shepherd-gexp config) (format #f "/run/user/~a" (getuid))) "/shepherd/socket")) #$(reload-configuration-gexp config) - #$(launch-shepherd-gexp config))) + ;; Don't attempt to start user shepherd if the system is running the + ;; activation script. /run/user/<uid> may not have been created + ;; yet. But do otherwise so if the runtime dir does not exist an error + ;; is logged. + (unless (getenv "GUIX_SYSTEM_IS_RUNNING_HOME_ACTIVATE") + #$(launch-shepherd-gexp config)))) (define (shepherd-xdg-configuration-files config) `(("shepherd/init.scm" ,(home-shepherd-configuration-file config)))) diff --git a/gnu/services/guix.scm b/gnu/services/guix.scm index c438da531c..5f649cbb6f 100644 --- a/gnu/services/guix.scm +++ b/gnu/services/guix.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019, 2020, 2021, 2022 Christopher Baines <mail@HIDDEN> +;;; Copyright © 2024 Andrew Tropin <andrew@HIDDEN> ;;; ;;; This file is part of GNU Guix. ;;; @@ -101,6 +102,8 @@ (define-module (gnu services guix) guix-data-service-type + guix-home-service-type + nar-herder-service-type nar-herder-configuration nar-herder-configuration? @@ -686,6 +689,42 @@ (define guix-data-service-type (description "Run an instance of the Guix Data Service."))) + +;;; +;;; Guix Home Service +;;; + +(define (guix-home-shepherd-service config) + (map (lambda (x) + (let ((user (car x)) + (he (cdr x))) + (shepherd-service + (documentation "Activate Guix Home.") + (requirement '(user-processes)) + (provision (list (symbol-append 'guix-home- (string->symbol user)))) + (one-shot? #t) + (auto-start? #t) + (start #~(make-forkexec-constructor + '(#$(file-append he "/activate")) + #:user #$user + #:environment-variables + (list (string-append "HOME=" (passwd:dir (getpw #$user))) + "GUIX_SYSTEM_IS_RUNNING_HOME_ACTIVATE=t") + #:group (group:name (getgrgid (passwd:gid (getpw #$user)))))) + (stop #~(make-kill-destructor))))) + config)) + +(define guix-home-service-type + (service-type + (name 'guix-home) + (description "Setups home-environments specified in the value.") + (extensions (list (service-extension + shepherd-root-service-type + guix-home-shepherd-service))) + (compose concatenate) + (extend append) + (default-value '()))) + ;;; ;;; Nar Herder base-commit: 447e9c96259e8fa15a828de9b2dd3400e2ffafe6 -- 2.41.0
Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) Content-Type: text/plain; charset=utf-8 X-Loop: help-debbugs@HIDDEN From: help-debbugs@HIDDEN (GNU bug Tracking System) To: Richard Sent <richard@HIDDEN> Subject: bug#69781: Acknowledgement ([PATCH] services: Add the Guix Home Service) Message-ID: <handler.69781.B.17103563977003.ack <at> debbugs.gnu.org> References: <05fd930c91838ce9640720ce68e3379f10154590.1710355300.git.richard@HIDDEN> X-Gnu-PR-Message: ack 69781 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 69781 <at> debbugs.gnu.org Date: Wed, 13 Mar 2024 19:00:02 +0000 Thank you for filing a new bug report with debbugs.gnu.org. This is an automatically generated reply to let you know your message has been received. Your message is being forwarded to the package maintainers and other interested parties for their attention; they will reply in due course. As you requested using X-Debbugs-CC, your message was also forwarded to ( <paren@HIDDEN>, Andrew Tropin <andrew@HIDDEN>, Ludovic Court=C3= =A8s <ludo@HIDDEN> (after having been given a bug report number, if it did not have one). Your message has been sent to the package maintainer(s): guix-patches@HIDDEN If you wish to submit further information on this problem, please send it to 69781 <at> debbugs.gnu.org. Please do not send mail to help-debbugs@HIDDEN unless you wish to report a problem with the Bug-tracking system. --=20 69781: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D69781 GNU Bug Tracking System Contact help-debbugs@HIDDEN with problems
X-Loop: help-debbugs@HIDDEN Subject: [bug#69781] [PATCH v2] services: Add the Guix Home Service References: <05fd930c91838ce9640720ce68e3379f10154590.1710355300.git.richard@HIDDEN> In-Reply-To: <05fd930c91838ce9640720ce68e3379f10154590.1710355300.git.richard@HIDDEN> Resent-From: Richard Sent <richard@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: , guix-patches@HIDDEN Resent-Date: Thu, 21 Mar 2024 18:39:01 +0000 Resent-Message-ID: <handler.69781.B69781.171104630424705 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: followup 69781 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 69781 <at> debbugs.gnu.org Cc: ludo@HIDDEN, rustand.lars@HIDDEN, Richard Sent <richard@HIDDEN>, ( <paren@HIDDEN>, Andrew Tropin <andrew@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> X-Debbugs-Original-Xcc: ( <paren@HIDDEN>, Andrew Tropin <andrew@HIDDEN>, Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> Received: via spool by 69781-submit <at> debbugs.gnu.org id=B69781.171104630424705 (code B ref 69781); Thu, 21 Mar 2024 18:39:01 +0000 Received: (at 69781) by debbugs.gnu.org; 21 Mar 2024 18:38:24 +0000 Received: from localhost ([127.0.0.1]:51749 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1rnNJ1-0006QI-0N for submit <at> debbugs.gnu.org; Thu, 21 Mar 2024 14:38:24 -0400 Received: from mail-108-mta78.mxroute.com ([136.175.108.78]:40071) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <richard@HIDDEN>) id 1rnNIy-0006Q3-0f for 69781 <at> debbugs.gnu.org; Thu, 21 Mar 2024 14:38:21 -0400 Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta78.mxroute.com (ZoneMTA) with ESMTPSA id 18e624de1920003bea.001 for <69781 <at> debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Thu, 21 Mar 2024 18:37:34 +0000 X-Zone-Loop: 854cffd14b96ab4f6e682477e348d8c7947850a56376 X-Originating-IP: [136.175.111.2] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=qugKhG0sU7r+TpcwDRzj1J9iOD2EtYKMzzoGVHEKwik=; b=i+aYaAtzB4meNVi3osT+qopl1u m+rukTlDzTgZz1MV/zgRbygfVyD3yoLxHG0xlClfvHGyx3KGIR8gGdsFn/BE3p4UVb1gAT44iwR/v h++WPaZSWmurYuC7Laia+wflEMzrFPAuGsbijhk9TGuVbLRIgrf5DkevPQ1BsyMWgcYnZyKy8W3zM EtmDqZt3tNWMON3RteMdanFGOtCW2WpHzz0hNbJ4ZB7se8gAHL7O4tu1xSKq4Rel2B6wNM3JeSeOl MeZA6Uiq3FMzFQj7IjPcHC7M7eczsYhC7pltK8bz6Lq4eta9a5VGX/zQzVqOve6Ax7rteBdojSZ3i 8h9SxQQA==; From: Richard Sent <richard@HIDDEN> Date: Thu, 21 Mar 2024 14:36:43 -0400 Message-ID: <3394b0b51f6a5a608ebcfb7a63fdc34e52fe928e.1711046203.git.richard@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Authenticated-Id: richard@HIDDEN X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) This patch adds a Guix Home Service, which allows for configuring/deploying an operating-system declaration with an associated home-environment. * gnu/services/guix.scm: Add guix-home-service and guix-home-shepherd-service * gnu/home/services/shepherd.scm: Don't attempt to launch user shepherd when the system shepherd runs guix-home-<user> * doc/guix.texi: Add documentation for guix-home-service * gnu/tests/guix.scm: Add a test to verify guix-home-service-type is able to activate a home environment Change-Id: Ifbcc0878d934aa4abe34bb2123b5081fb432aa8e --- Resubmitting based on feedback on a similar patch that I missed earlier, https://issues.guix.gnu.org/68589. Not sure how to merge patches, but figured best to submit V2 to this issue. Sorry! doc/guix.texi | 32 +++++++++++++++ gnu/home/services/shepherd.scm | 7 +++- gnu/services/guix.scm | 38 ++++++++++++++++++ gnu/tests/guix.scm | 73 ++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 20f007b1c0..3a5f1289fa 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -125,6 +125,7 @@ Copyright @copyright{} 2023 Graham James Addis@* Copyright @copyright{} 2023 Tomas Volf@* Copyright @copyright{} 2024 Herman Rimm@* +Copyright @copyright{} 2024 Richard Sent@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -39576,6 +39577,37 @@ Guix Services @end table @end deftp +@subsubheading Guix Home Service +The Guix Home Service allows for associating Guix @ref{Declaring the +Home Environment, home-environment} declarations with a Guix +@ref{operating-system Reference, operating-system}. + +@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 +is a string representing the user to deploy the configuration under and +the value is a home-environment configuration. + +@lisp +(define my-home + (home-environment + ...)) + +(operating-system + (services (list + (service guix-home-service-type + `(("alice" ,my-home)))))) +@end lisp + +This service can be extended by other services to add additional home +environments, as in this example: + +@lisp +(simple-service 'my-extra-home home-service-type + `(("bob" ,my-extra-home)))) +@end lisp +@end defvar + @subsubheading Nar Herder The @uref{https://git.cbaines.net/guix/nar-herder/about/,Nar Herder} is a utility for managing a collection of nars. diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm index 176f4575cb..e68dea6954 100644 --- a/gnu/home/services/shepherd.scm +++ b/gnu/home/services/shepherd.scm @@ -132,7 +132,12 @@ (define (ensure-shepherd-gexp config) (format #f "/run/user/~a" (getuid))) "/shepherd/socket")) #$(reload-configuration-gexp config) - #$(launch-shepherd-gexp config))) + ;; Don't attempt to start user shepherd if the system is running the + ;; activation script. /run/user/<uid> may not have been created + ;; yet. But do otherwise so if the runtime dir does not exist an error + ;; is logged. + (unless (getenv "GUIX_SYSTEM_IS_RUNNING_HOME_ACTIVATE") + #$(launch-shepherd-gexp config)))) (define (shepherd-xdg-configuration-files config) `(("shepherd/init.scm" ,(home-shepherd-configuration-file config)))) diff --git a/gnu/services/guix.scm b/gnu/services/guix.scm index c438da531c..05ff9f1ba4 100644 --- a/gnu/services/guix.scm +++ b/gnu/services/guix.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019, 2020, 2021, 2022 Christopher Baines <mail@HIDDEN> +;;; Copyright © 2024 Andrew Tropin <andrew@HIDDEN> ;;; ;;; This file is part of GNU Guix. ;;; @@ -101,6 +102,8 @@ (define-module (gnu services guix) guix-data-service-type + guix-home-service-type + nar-herder-service-type nar-herder-configuration nar-herder-configuration? @@ -686,6 +689,41 @@ (define guix-data-service-type (description "Run an instance of the Guix Data Service."))) + +;;; +;;; Guix Home Service +;;; + +(define (guix-home-shepherd-service config) + (map (match-lambda + ((user he) + (shepherd-service + (documentation "Activate Guix Home.") + (requirement '(user-processes)) + (provision (list (symbol-append 'guix-home- (string->symbol user)))) + (one-shot? #t) + (auto-start? #t) + (start #~(make-forkexec-constructor + '(#$(file-append he "/activate")) + #:user #$user + #:environment-variables + (list (string-append "HOME=" (passwd:dir (getpw #$user))) + "GUIX_SYSTEM_IS_RUNNING_HOME_ACTIVATE=t") + #:group (group:name (getgrgid (passwd:gid (getpw #$user)))))) + (stop #~(make-kill-destructor))))) + config)) + +(define guix-home-service-type + (service-type + (name 'guix-home) + (description "Sets up Guix Home for the specified user accounts.") + (extensions (list (service-extension + shepherd-root-service-type + guix-home-shepherd-service))) + (compose concatenate) + (extend append) + (default-value '()))) + ;;; ;;; Nar Herder diff --git a/gnu/tests/guix.scm b/gnu/tests/guix.scm index 240ded4825..12ad1bf255 100644 --- a/gnu/tests/guix.scm +++ b/gnu/tests/guix.scm @@ -17,6 +17,8 @@ ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. (define-module (gnu tests guix) + #:use-module (gnu home) + #:use-module (gnu home services) #:use-module (gnu tests) #:use-module (gnu system) #:use-module (gnu system file-systems) @@ -37,6 +39,7 @@ (define-module (gnu tests guix) #:use-module (ice-9 match) #:export (%test-guix-build-coordinator %test-guix-data-service + %test-guix-home-service %test-nar-herder %test-bffe)) @@ -251,6 +254,76 @@ (define %test-guix-data-service (description "Connect to a running Guix Data Service.") (value (run-guix-data-service-test)))) + +;;; +;;; Guix Home +;;; + +(define %guix-home-service-he + (home-environment + (services + (list (simple-service 'guix-home-service-test + home-files-service-type + `(("guix-home-service-activated" + ,(plain-file "guix-home-service-activated" + "Guix Home service activated")))))))) + +(define %guix-home-service-os + (simple-operating-system + (service guix-home-service-type + `(("alice" ,%guix-home-service-he))))) + +(define (run-guix-home-service-test) + (define os + (marionette-operating-system + %guix-home-service-os + #:imported-modules '((gnu services herd)))) + + (define vm + (virtual-machine + (operating-system os) + (memory-size 1024))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (srfi srfi-64) + (gnu build marionette)) + + (define marionette + (make-marionette (list #$vm))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "guix-home-service") + + (test-assert "service started" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (match (start-service 'guix-home-alice) + (#f #f) + ;; herd returns (running #f), likely because of one shot, + ;; so consider any non-error a success. + (('service response-parts ...) #t))) + marionette)) + + (test-assert "file-exists" + (marionette-eval + '(begin + (sleep 3) ;make sure service has time to symlink files + (file-exists? "/home/alice/guix-home-service-activated")) + marionette)) + + (test-end)))) + + (gexp->derivation "guix-home-service-test" test)) + +(define %test-guix-home-service + (system-test + (name "guix-home-service") + (description "Activate a Guix home environment.") + (value (run-guix-home-service-test)))) + ;;; ;;; Nar Herder base-commit: 9b84b362963770d7a21ceb4e711a5a389db5b02d -- 2.41.0
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.