From patchwork Thu Jan 28 16:32:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: M X-Patchwork-Id: 26703 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 7030F27BC1D; Thu, 28 Jan 2021 16:33:24 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id A293727BC1C for ; Thu, 28 Jan 2021 16:33:23 +0000 (GMT) Received: from localhost ([::1]:33826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5AEU-0006Ph-LW for patchwork@mira.cbaines.net; Thu, 28 Jan 2021 11:33:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5AEB-0006J6-9W for guix-patches@gnu.org; Thu, 28 Jan 2021 11:33:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:38168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l5AEB-00088C-1U for guix-patches@gnu.org; Thu, 28 Jan 2021 11:33:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l5AEA-0003qa-Uy for guix-patches@gnu.org; Thu, 28 Jan 2021 11:33: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: Thu, 28 Jan 2021 16:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46043 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 46043-submit@debbugs.gnu.org id=B46043.161185154014733 (code B ref 46043); Thu, 28 Jan 2021 16:33:02 +0000 Received: (at 46043) by debbugs.gnu.org; 28 Jan 2021 16:32:20 +0000 Received: from localhost ([127.0.0.1]:49713 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l5ADU-0003pZ-7o for submit@debbugs.gnu.org; Thu, 28 Jan 2021 11:32:20 -0500 Received: from andre.telenet-ops.be ([195.130.132.53]:46008) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l5ADP-0003pN-Fu for 46043@debbugs.gnu.org; Thu, 28 Jan 2021 11:32:16 -0500 Received: from ptr-bvsjgyjmffd7q9timvx.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by andre.telenet-ops.be with bizsmtp id NGYD2400D0mfAB401GYD3M; Thu, 28 Jan 2021 17:32:13 +0100 Message-ID: <8a034285f33c9eb70a5c1ba928dd24b224cdc326.camel@telenet.be> From: Maxime Devos Date: Thu, 28 Jan 2021 17:32:08 +0100 In-Reply-To: <87y2gdp5d2.fsf@gnu.org> References: <874kj8bv8w.fsf@telenet.be> <97fca7da3cf4fd0ff5aa554bc3ec95431f85e530.camel@telenet.be> <875z3jzami.fsf_-_@gnu.org> <87y2germxk.fsf@gnu.org> <74ad9bc1419a00dcf21b5e3e1370c1656f1bd740.camel@telenet.be> <87y2gdp5d2.fsf@gnu.org> User-Agent: Evolution 3.34.2 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1611851533; bh=GoBsb6RGp3tHHEgLwd9ghCBVZkg59h4s61hqC+oWeK0=; h=Subject:From:Reply-To:To:Cc:Date:In-Reply-To:References; b=ja/UNnxfvQA/t1G50P6yHcC0dyeTPCYiAl9tLXl2S0snCYTf+mWc5xqLO95dhwIfl 7xsSliWpi6Oclya2ELVkp80cLYeVoMRm3L2XdAZjUpQMiwrKXYM9mI7PUIyzCLNDm0 zF4iEEb9MyqwIEGsMaQRfYGsIJwgNKlwfBdxDc67YyyK3T+bV2B2ZlEP4za0XJi3Zw ucVuGyoBau7dKDZRJZFwwVDs+bLT/yJfDrsvoWFoSqsvN0PdTHr/pxieG0B4k/INoV JPfWFkW/nZQnKrG6ucC96LpalUQyWJhJ72dBsw0y/8IhbWHTT8wXBqfbGES7s7/ZRa IwNj403EwTebg== 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: , Reply-To: 46043@debbugs.gnu.org Cc: 46043@debbugs.gnu.org Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches > I think that’s the same as before (there are no changes to > gnu/system.scm). :-) This time for real :-) From 085708344c4a9d7f819a399e666e2bab2ae7a54d 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. * gnu/system.scm (operating-system-shepherd-service-names): Use the new record. * doc/guix.texi (Shepherd Services). Document it. --- doc/guix.texi | 17 ++++++++++++- gnu/services/shepherd.scm | 53 +++++++++++++++++++++++++++++---------- gnu/system.scm | 10 +++++--- 3 files changed, 62 insertions(+), 18 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{}. +Each extension must pass a list of @code{}. 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{} 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 ;;; Copyright © 2018 Carlo Zancanaro ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen +;;; Copyright © 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) - #: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 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,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 - ;; objects. - (service shepherd-root-service-type '())) + ;; The root shepherd service, aka. PID 1. Its parameter is a + ;; . + (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) diff --git a/gnu/system.scm b/gnu/system.scm index 90ad368664..5bf2a85272 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -12,6 +12,7 @@ ;;; Copyright © 2020 Maxim Cournoyer ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2020 Efraim Flashner +;;; Copyright © 2021 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -1134,10 +1135,11 @@ we're running in the final root." (define (operating-system-shepherd-service-names os) "Return the list of Shepherd service names for OS." (append-map shepherd-service-provision - (service-value - (fold-services (operating-system-services os) - #:target-type - shepherd-root-service-type)))) + (shepherd-configuration-services + (service-value + (fold-services (operating-system-services os) + #:target-type + shepherd-root-service-type))))) (define* (operating-system-derivation os) "Return a derivation that builds OS." -- 2.30.0