[bug#77288,v3,1/8] self: Install systemd ‘.service’ files.

Message ID f5c3502260ed44c753ce41f5607f8e81b91a5d25.1745005408.git.ludo@gnu.org
State New
Headers
Series Rootless guix-daemon on Guix System |

Commit Message

Ludovic Courtès April 18, 2025, 7:46 p.m. UTC
  This is consistent with the ‘guix’ package and will prove helpful when
people want to replace /etc/systemd/system/guix*.service with newer
versions thereof.

* guix/self.scm (parameterized-file): New procedure, based on…
(selinux-policy): … this. Use ‘parameterized-file’.
(systemd-file): New procedure.
(miscellaneous-files): Add systemd files.

Change-Id: Ia489a955347cf648a86000cc1265769d66c3f0e8
---
 guix/self.scm | 42 ++++++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 10 deletions(-)
  

Patch

diff --git a/guix/self.scm b/guix/self.scm
index 28239d53f5..2a99765359 100644
--- a/guix/self.scm
+++ b/guix/self.scm
@@ -1,5 +1,5 @@ 
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2017-2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2017-2023, 2025 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
 ;;; Copyright © 2023 Janneke Nieuwenhuizen <janneke@gnu.org>
 ;;; Copyright © 2024 gemmaro <gemmaro.dev@gmail.com>
@@ -666,24 +666,40 @@  (define* (guix-command modules
                 ;; Use a 'guile' variant that doesn't complain about locales.
                 #:guile (quiet-guile guile)))
 
-(define (selinux-policy source daemon)
-  "Return the SELinux policy file taken from SOURCE and adjusted to refer to
-DAEMON and to the current configuration variables."
+(define (parameterized-file source daemon file name)
+  "Return FILE taken from SOURCE (typically a '.in' file) and adjusted to
+refer to DAEMON and to the current configuration variables."
   (define build
     (with-imported-modules '((guix build utils))
       #~(begin
           (use-modules (guix build utils))
 
-          (copy-file #+(file-append* source "/etc/guix-daemon.cil.in")
-                     "guix-daemon.cil")
-          (substitute* "guix-daemon.cil"
+          (fluid-set! %default-port-encoding "UTF-8")
+          (copy-file #+(file-append* source file) #$name)
+          (substitute* #$name
             (("@guix_sysconfdir@") #$%sysconfdir)
             (("@guix_localstatedir@") #$%localstatedir)
+            (("@localstatedir@") #$%localstatedir)
             (("@storedir@") #$%storedir)
-            (("@prefix@") #$daemon))
-          (copy-file "guix-daemon.cil" #$output))))
+            (("@prefix@") #$daemon)
+            (("@GUIX_SUBSTITUTE_URLS@")
+             #$(string-join %default-substitute-urls)))
+          (copy-file #$name #$output))))
 
-  (computed-file "guix-daemon.cil" build))
+  (computed-file name build))
+
+(define (selinux-policy source daemon)
+  "Return the SELinux policy file taken from SOURCE and adjusted to refer to
+DAEMON and to the current configuration variables."
+  (parameterized-file source daemon
+                      "etc/guix-daemon.cil.in"
+                      "guix-daemon.cil"))
+
+(define (systemd-file source daemon file)
+  "Return the given systemd file from SOURCE parameterized for DAEMON."
+  (parameterized-file source daemon
+                      (string-append "etc/" file ".in")
+                      file))
 
 (define (miscellaneous-files source daemon)
   "Return data files taken from SOURCE."
@@ -698,6 +714,12 @@  (define (miscellaneous-files source daemon)
                    ,(file-append* source "/etc/completion/fish/guix.fish"))
                   ("share/selinux/guix-daemon.cil"
                    ,(selinux-policy source daemon))
+                  ,@(map (lambda (file)
+                           `(,(string-append "lib/systemd/system/" file)
+                             ,(systemd-file source daemon file)))
+                         '("guix-gc.service"
+                           "guix-publish.service"
+                           "guix-daemon.service"))
                   ("share/guix/berlin.guix.gnu.org.pub"
                    ,(file-append* source
                                   "/etc/substitutes/berlin.guix.gnu.org.pub"))