From: Maxime Devos <maximedevos@telenet.be>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 46043@debbugs.gnu.org
Subject: [bug#46043] [PATCH] Allow booting with custom shepherd package (fixed)
Date: Thu, 28 Jan 2021 09:20:00 +0100 [thread overview]
Message-ID: <74ad9bc1419a00dcf21b5e3e1370c1656f1bd740.camel@telenet.be> (raw)
In-Reply-To: <87y2germxk.fsf@gnu.org>
[-- Attachment #1.1: Type: text/plain, Size: 152 bytes --]
> Could you take a look?
Revised patch is attached.
'make check-system TESTS=basic' now succeeds, I'm now
running 'make check-system' just in case.
[-- Attachment #1.2: 0001-services-shepherd-allow-custom-shepherd-package.patch --]
[-- Type: text/x-patch, Size: 6477 bytes --]
From 1b1e49f4aad95b766126fadd4166acf5ab6fbd31 Mon Sep 17 00:00:00 2001
From: Maxime Devos <maximedevos@telenet.be>
Date: Fri, 22 Jan 2021 20:06:55 +0100
Subject: [PATCH] services: shepherd: allow custom 'shepherd' package
* gnu/services/shepherd.scm
(<shepherd-configuration>): 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.
---
doc/guix.texi | 17 ++++++++++++-
gnu/services/shepherd.scm | 53 +++++++++++++++++++++++++++++----------
2 files changed, 56 insertions(+), 14 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index 2249583e46..9d9e60aefb 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -32735,9 +32735,24 @@ The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
This is the service type that extensions target when they want to create
shepherd services (@pxref{Service Types and Services}, for an example).
-Each extension must pass a list of @code{<shepherd-service>}.
+Each extension must pass a list of @code{<shepherd-service>}. Its
+value must be a @code{shepherd-configuration}, as described below.
@end defvr
+@deftp {Data Type} shepherd-configuration
+This data type represents the Shepherd's configuration.
+
+@table @code
+@item shepherd (default: @code{shepherd})
+The Shepherd package to use.
+
+@item services (default: @code{'()})
+A list of @code{<shepherd-service>} 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..e2ec59f5aa 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -3,6 +3,7 @@
;;; Copyright © 2017 Clément Lassieur <clement@lassieur.org>
;;; Copyright © 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;;
;;; 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)
- #: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
@@ -76,7 +82,18 @@
;;; Code:
-(define (shepherd-boot-gexp services)
+(define-record-type* <shepherd-configuration>
+ shepherd-configuration make-shepherd-configuration
+ shepherd-configuration?
+ (shepherd shepherd-configuration-shepherd
+ (default shepherd)) ; package
+ (services shepherd-configuration-services
+ (default '()))) ; list of <shepherd-service>
+
+(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,10 @@
;; Start shepherd.
(execl #$(file-append shepherd "/bin/shepherd")
"shepherd" "--config"
- #$(shepherd-configuration-file services))))
+ #$(shepherd-configuration-file services shepherd)))))
+
+(define shepherd-packages
+ (compose list shepherd-configuration-shepherd))
(define shepherd-root-service-type
(service-type
@@ -103,20 +123,25 @@
;; Extending the root shepherd service (aka. PID 1) happens by
;; concatenating the list of services provided by the extensions.
(compose concatenate)
- (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)))))
+ shepherd-packages)))
+ (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.")))
(define %shepherd-root-service
- ;; The root shepherd service, aka. PID 1. Its parameter is a list of
- ;; <shepherd-service> objects.
- (service shepherd-root-service-type '()))
+ ;; The root shepherd service, aka. PID 1. Its parameter is a
+ ;; <shepherd-configuration>.
+ (service shepherd-root-service-type))
(define-syntax shepherd-service-type
(syntax-rules (description)
@@ -270,9 +295,9 @@ stored."
#~(#$name #$doc #$proc)))
(shepherd-service-actions service))))))))
-(define (scm->go file)
+(define (scm->go file shepherd)
"Compile FILE, which contains code to be loaded by shepherd's config file,
-and 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) ".scm")
@@ -294,11 +319,13 @@ and return the resulting '.go' file."
#:options '(#:local-build? #t
#:substitutable? #f)))))
-(define (shepherd-configuration-file services)
- "Return the shepherd configuration file for SERVICES."
+(define (shepherd-configuration-file services shepherd)
+ "Return the shepherd configuration file for SERVICES. SHEPHERD is used
+as shepherd package."
(assert-valid-graph services)
- (let ((files (map shepherd-service-file services)))
+ (let ((files (map shepherd-service-file services))
+ (scm->go (cute scm->go <> shepherd)))
(define config
#~(begin
(use-modules (srfi srfi-34)
--
2.30.0
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]
next prev parent reply other threads:[~2021-01-28 8:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-22 19:57 [bug#46043] [PATCH] Allow booting with custom shepherd package (fixed) Maxime Devos
2021-01-23 8:25 ` Leo Prikler
2021-01-23 15:11 ` Maxime Devos
2021-01-23 15:25 ` Leo Prikler
2021-01-25 8:48 ` Maxime Devos
2021-01-26 20:49 ` Ludovic Courtès
2021-01-27 13:24 ` Maxime Devos
2021-01-27 23:09 ` bug#46043: " Ludovic Courtès
2021-01-27 23:15 ` [bug#46043] " Ludovic Courtès
2021-01-28 8:20 ` Maxime Devos [this message]
2021-01-28 13:18 ` Ludovic Courtès
2021-01-28 16:32 ` Maxime Devos
2021-01-30 14:36 ` bug#46043: " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=74ad9bc1419a00dcf21b5e3e1370c1656f1bd740.camel@telenet.be \
--to=maximedevos@telenet.be \
--cc=46043@debbugs.gnu.org \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.