Subject: [WIP] make guix-service-type more extendable

From: Justin Veilleux <[email-masked]>
Date: Wed, 13 Apr 2022 14:54:05 -0400

I noticed that the extension mechanism for guix-service-type don't 
expose authorized keys and substitute-urls. I want to create a service 
to easily set up new channels with their associated substitutes server, 
but I have to go through modify-services.

I realize that this change isn't trivial as it breaks some people's 
os.scm and requires updating the documentation, but I think it is a very 
low hanging fruit in terms of functionality.

Maybe there is a reason why things are the way they are, I would greatly 
appreciate comments.

Cheers.
From 229ccde84a2183d31860c9616820763ddf2ac5f1 Mon Sep 17 00:00:00 2001
From: terramorpha <[email-masked]>
Date: Mon, 11 Apr 2022 00:30:07 -0400
Subject: [PATCH] first commit

---
 gnu/services/base.scm | 50 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 5d7c69a9cd..5d779eec1a 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -17,6 +17,7 @@
 ;;; Copyright © 2021 Hui Lu <[email-masked]>
 ;;; Copyright © 2021, 2022 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2022 Guillaume Le Vaillant <[email-masked]>
+;;; Copyright © 2022 Justin Veilleux <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -187,6 +188,12 @@ (define-module (gnu services base)
             guix-configuration-extra-options
             guix-configuration-log-file
 
+            guix-extension
+            guix-extension?
+            guix-extension-authorized-keys
+            guix-extension-substitute-urls
+            guix-extension-chroot-directories
+
             guix-service-type
             guix-publish-configuration
             guix-publish-configuration?
@@ -1788,6 +1795,25 @@ (define* (references-file item #:optional (name "references"))
                                  #:references-graphs (("graph" ,item))))
       (plain-file name "()")))
 
+(define-record-type* <guix-extension>
+  guix-extension make-guix-extension
+  guix-extension?
+  (authorized-keys guix-extension-authorized-keys ;list of gexps
+                    (default '()))
+  (substitute-urls guix-extension-substitute-urls ;list of strings
+                    (default '()))
+  (chroot-directories guix-extension-chroot-directories ;list of file-like/strings
+                      (default '())))
+
+(define (guix-extension-merge a b)
+  (guix-extension
+   (authorized-keys (append (guix-extension-authorized-keys a)
+                            (guix-extension-authorized-keys b)))
+   (substitute-urls (append (guix-extension-substitute-urls a)
+                            (guix-extension-substitute-urls b)))
+   (chroot-directories (append (guix-extension-chroot-directories a)
+                               (guix-extension-chroot-directories b)))))
+
 (define guix-service-type
   (service-type
    (name 'guix)
@@ -1798,30 +1824,34 @@ (define guix-service-type
           (service-extension profile-service-type
                              (compose list guix-configuration-guix))))
 
-   ;; Extensions can specify extra directories to add to the build chroot.
-   (compose concatenate)
-   (extend (lambda (config directories)
+   ;; Extensions can specify extra directories to add to the build chroot,
+   ;; extra substitute urls and extra authorized keys
+   (compose (lambda (args) (fold guix-extension-merge (guix-extension) args)))
+   (extend (lambda (config extension)
              (guix-configuration
               (inherit config)
+              (authorized-keys (append (guix-extension-authorized-keys extension)
+                                       (guix-configuration-authorized-keys config)))
+              (substitute-urls (append (guix-extension-substitute-urls extension)
+                                       (guix-configuration-substitute-urls config)))
               (chroot-directories
-               (append (guix-configuration-chroot-directories config)
-                       directories)))))
+               (append (guix-extension-chroot-directories extension)
+                       (guix-configuration-chroot-directories config))))))
 
    (default-value (guix-configuration))
    (description
     "Run the build daemon of GNU@tie{}Guix, aka. @command{guix-daemon}.")))
 
-
 (define-record-type* <guix-publish-configuration>
   guix-publish-configuration make-guix-publish-configuration
   guix-publish-configuration?
-  (guix    guix-publish-configuration-guix        ;file-like
+  (guix    guix-publish-configuration-guix ;file-like
            (default guix))
-  (port    guix-publish-configuration-port        ;number
+  (port    guix-publish-configuration-port ;number
            (default 80))
-  (host    guix-publish-configuration-host        ;string
+  (host    guix-publish-configuration-host ;string
            (default "localhost"))
-  (advertise? guix-publish-advertise?       ;boolean
+  (advertise? guix-publish-advertise?   ;boolean
               (default #f))
   (compression       guix-publish-configuration-compression
                      (thunked)
-- 
2.34.0