From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id iAKaDVMuC2DLMwAA0tVLHw (envelope-from ) for ; Fri, 22 Jan 2021 19:58:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 6S5eCVMuC2AfOQAAbx9fmQ (envelope-from ) for ; Fri, 22 Jan 2021 19:58:11 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A0BE0940105 for ; Fri, 22 Jan 2021 19:58:10 +0000 (UTC) Received: from localhost ([::1]:33188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l32ZN-0008Ef-Hw for larch@yhetil.org; Fri, 22 Jan 2021 14:58:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l32ZG-0008ER-Cn for guix-patches@gnu.org; Fri, 22 Jan 2021 14:58:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:49847) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l32ZG-0007FG-5i for guix-patches@gnu.org; Fri, 22 Jan 2021 14:58:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l32ZG-00062c-3s for guix-patches@gnu.org; Fri, 22 Jan 2021 14:58:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#46043] [PATCH] Allow booting with custom shepherd package (fixed) Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 22 Jan 2021 19:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 46043 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 46043@debbugs.gnu.org, maximedevos@telenet.be X-Debbugs-Original-To: , Received: via spool by submit@debbugs.gnu.org id=B.161134543523165 (code B ref -1); Fri, 22 Jan 2021 19:58:01 +0000 Received: (at submit) by debbugs.gnu.org; 22 Jan 2021 19:57:15 +0000 Received: from localhost ([127.0.0.1]:33160 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l32YV-00061Z-3x for submit@debbugs.gnu.org; Fri, 22 Jan 2021 14:57:15 -0500 Received: from lists.gnu.org ([209.51.188.17]:55524) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l32YT-00061R-5H for submit@debbugs.gnu.org; Fri, 22 Jan 2021 14:57:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l32YS-0008BC-Sv for guix-patches@gnu.org; Fri, 22 Jan 2021 14:57:12 -0500 Received: from michel.telenet-ops.be ([2a02:1800:110:4::f00:18]:47700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l32YP-0006nC-8p for guix-patches@gnu.org; Fri, 22 Jan 2021 14:57:12 -0500 Received: from butterfly ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by michel.telenet-ops.be with bizsmtp id Kvx4240090mfAB406vx4Wl; Fri, 22 Jan 2021 20:57:04 +0100 From: Maxime Devos Date: Fri, 22 Jan 2021 20:57:03 +0100 Message-ID: <874kj8bv8w.fsf@telenet.be> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Received-SPF: pass client-ip=2a02:1800:110:4::f00:18; envelope-from=maximedevos@telenet.be; helo=michel.telenet-ops.be X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -4.35 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: A0BE0940105 X-Spam-Score: -4.35 X-Migadu-Scanner: scn1.migadu.com X-TUID: rRl1t2o6qr8M --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain [previous e-mail was bogus. ggrr emacs, why can't I open e-mail I was composing and saved with C-x C-f and continue later, even if I set mml-mode] Hi Guix, If I didn't miss anything, this patch allows for booting with a non-standard shepherd package, which may be useful for using features from a not-yet released shepherd (presuming you've packaged the custom shepherd first :)). I'll send a follow-up e-mail to confirm/disconfirm whether this works well. Maxime --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-services-shepherd-allow-custom-shepherd-package.patch Content-Transfer-Encoding: quoted-printable Content-Description: the patch From=20e4f6743a5502eb6c878ee2c3bf7f7153f8006e01 Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Fri, 22 Jan 2021 20:06:55 +0100 Subject: [PATCH] services: shepherd: allow custom 'shepherd' package * gnu/services/shepherd.scm (): New record. (shepherd-boot-gexp, shepherd-root-service-type): Use it. (scm->go, shepherd-configuration-file): Allow passing custom shepherd package. * doc/guix.texi (Shepherd Services). Document it. =2D-- doc/guix.texi | 17 +++++++++++++- gnu/services/shepherd.scm | 48 +++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index a765b3792e..344ffcfea5 100644 =2D-- a/doc/guix.texi +++ b/doc/guix.texi @@ -32707,9 +32707,24 @@ The service type for the Shepherd ``root service''= ---i.e., PID@tie{}1. =20 This is the service type that extensions target when they want to create shepherd services (@pxref{Service Types and Services}, for an example). =2DEach extension must pass a list of @code{}. +Each extension must pass a list of @code{}. Its +value must be a @code{shepherd-configuration}, as described below: @end defvr =20 +@deftp {Data Type} shepherd-configuration +This data type represents shepherd's configuration. + +@table @code +@item shepherd (default: @code{shepherd}) +The shepherd package to use. + +@item services (default: @code{'()}) +A list of @code{} to start. +You should probably use the service extension +mechanism instead (@pxref{Shepherd Services}). +@end table +@end deftp + @defvr {Scheme Variable} %shepherd-root-service This service represents PID@tie{}1. @end defvr diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm index d2f9776288..748b19957a 100644 =2D-- a/gnu/services/shepherd.scm +++ b/gnu/services/shepherd.scm @@ -3,6 +3,7 @@ ;;; Copyright =C2=A9 2017 Cl=C3=A9ment Lassieur ;;; Copyright =C2=A9 2018 Carlo Zancanaro ;;; Copyright =C2=A9 2020 Jan (janneke) Nieuwenhuizen +;;; Copyright =C2=A9 2021 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -36,7 +37,12 @@ #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) =2D #:export (shepherd-root-service-type + #:export (shepherd-configuration + shepherd-configuration? + shepherd-configuration-shepherd + shepherd-configuration-services + + shepherd-root-service-type %shepherd-root-service shepherd-service-type =20 @@ -76,7 +82,18 @@ ;;; Code: =20 =20 =2D(define (shepherd-boot-gexp services) +(define-record-type* + shepherd-configuration make-shepherd-configuration + shepherd-configuration? + (shepherd shepherd-configuration-shepherd + (default shepherd)) ; package + (services shepherd-configuration-services + (default '()))) ; list of + +(define (shepherd-boot-gexp config) + "Return a gexp starting the shepherd service." + (let ((shepherd (shepherd-configuration-shepherd config)) + (services (shepherd-configuration-services config))) #~(begin ;; Keep track of the booted system. (false-if-exception (delete-file "/run/booted-system")) @@ -95,7 +112,7 @@ ;; Start shepherd. (execl #$(file-append shepherd "/bin/shepherd") "shepherd" "--config" =2D #$(shepherd-configuration-file services)))) + #$(shepherd-configuration-file services #:shepherd shepherd))= ))) =20 (define shepherd-root-service-type (service-type @@ -103,20 +120,25 @@ ;; Extending the root shepherd service (aka. PID 1) happens by ;; concatenating the list of services provided by the extensions. (compose concatenate) =2D (extend append) + (extend (lambda (config extra-services) + (shepherd-configuration + (inherit config) + (services (append (shepherd-configuration-services config) + extra-services))))) (extensions (list (service-extension boot-service-type shepherd-boot-gexp) (service-extension profile-service-type (const (list shepherd))))) + (default-value (shepherd-configuration)) (description "Run the GNU Shepherd as PID 1---i.e., the operating system's first process. The Shepherd takes care of managing services such as daemons by ensuring they are started and stopped in the right order."))) =20 (define %shepherd-root-service =2D ;; The root shepherd service, aka. PID 1. Its parameter is a list of =2D ;; objects. =2D (service shepherd-root-service-type '())) + ;; The root shepherd service, aka. PID 1. Its parameter is a + ;; . + (service shepherd-root-service-type)) =20 (define-syntax shepherd-service-type (syntax-rules (description) @@ -270,9 +292,9 @@ stored." #~(#$name #$doc #$proc))) (shepherd-service-actions service)))))))) =20 =2D(define (scm->go file) +(define* (scm->go file #:key (shepherd shepherd)) "Compile FILE, which contains code to be loaded by shepherd's config fil= e, =2Dand return the resulting '.go' file." +and return the resulting '.go' file. SHEPHERD is used as shepherd package." (let-system (system target) (with-extensions (list shepherd) (computed-file (string-append (basename (scheme-file-name file) ".sc= m") @@ -294,11 +316,13 @@ and return the resulting '.go' file." #:options '(#:local-build? #t #:substitutable? #f))))) =20 =2D(define (shepherd-configuration-file services) =2D "Return the shepherd configuration file for SERVICES." +(define* (shepherd-configuration-file services #:key (shepherd shepherd)) + "Return the shepherd configuration file for SERVICES. SHEPHERD is used +as shepherd package." (assert-valid-graph services) =20 =2D (let ((files (map shepherd-service-file services))) + (let ((files (map shepherd-service-file services)) + (scm->go (cute scm->go <> #:shepherd shepherd))) (define config #~(begin (use-modules (srfi srfi-34) =2D-=20 2.30.0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iI0EARYIADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYAsuDxccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7pEoAQCi2xSw+zmejpU63T4XnH7zQEGW QsK9g0L+HYya36gGWgEAgGHjYcFmfwGTE/HbYh4Eavy5/BHExcWOFEtJA6/fFgg= =CCaY -----END PGP SIGNATURE----- --==-=-=--