Subject: Re: [bug#49610] [PATCH v4 1/2] services: guix: Add channels field.

From: Ludovic Courtès <[email-masked]>
Date: Fri, 22 Mar 2024 11:44:14 +0100

Hi Antero,

Antero Mejr <[email-masked]> skribis:

> * doc/guix.texi (Base Services): Document
> 'guix-configuration-channels' field.
> * gnu/services/base.scm (install-channels-file): New procedure.
> (%default-channels-file): New variable.
> (guix-configuration): Add channels field.
> (guix-activation): Use 'install-channels-file' procedure.

Rebased and finally applied!

However, I took the liberty to make the changes below.  Essentially,
‘channels’ is now a list of channel (as the name suggests) rather than a
file-like.  It’s a tradeoff: on one hand it’s less expressive (that
prevents users from sticking arbitrary Scheme code in there), but OTOH
it’s easier to use.

If that is deemed too rigid, we can revisit that and either allow for
file-like objects or for gexps, or add a separate ‘channels-file’ field.

Pushed as 883e69cdfd226c8f40b6e3b76ce0740b59857de6.

Thanks!

Ludo’.

diff --git a/doc/guix.texi b/doc/guix.texi
index 5c974f2ea4..e419b8d1a4 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -4727,7 +4727,9 @@ Invoking guix pull
 is passed;
 @item
 the system-wide @file{/etc/guix/channels.scm} file, unless @option{-q}
-is passed;
+is passed (on Guix System, this file can be declared in the operating
+system configuration, @pxref{guix-configuration-channels,
+@code{channels} field of @code{guix-configuration}});
 @item
 the built-in default channels specified in the @code{%default-channels}
 variable.
@@ -19806,10 +19808,11 @@ Base Services
 might want to turn it off for instance in a virtual machine that does
 not need it and where the extra boot time is a problem.
 
+@anchor{guix-configuration-channels}
 @item @code{channels} (default: @code{%default-channels})
-File-like object containing a list of channels to be used by
-@command{guix pull}, by default.  The file-like object is symlinked to
-@file{/etc/guix/channels.scm}.
+List of channels to be specified in @file{/etc/guix/channels.scm}, which
+is what @command{guix pull} uses by default (@pxref{Invoking guix
+pull}).
 
 @quotation Note
 When reconfiguring a system, the existing @file{/etc/guix/channels.scm}
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index dcd66b8064..cd61df718e 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -83,7 +83,7 @@ (define-module (gnu services base)
   #:use-module ((gnu build file-systems)
                 #:select (mount-flags->bit-mask
                           swap-space->flags-bit-mask))
-  #:use-module (guix channels)
+  #:autoload   (guix channels) (%default-channels channel->code)
   #:use-module (guix gexp)
   #:use-module (guix records)
   #:use-module (guix modules)
@@ -98,7 +98,6 @@ (define-module (gnu services base)
   #:use-module (srfi srfi-35)
   #:use-module (ice-9 match)
   #:use-module (ice-9 format)
-  #:use-module (ice-9 pretty-print)
   #:re-export (user-processes-service-type        ;backwards compatibility
                %default-substitute-urls)
   #:export (fstab-service-type
@@ -1743,17 +1742,13 @@ (define (substitute-key-authorization keys guix)
         ;; Installed the declared ACL.
         (symlink #+default-acl acl-file))))
 
-(define %default-channels-file
-  ;; File-like object containing the default list of channels.
-  (plain-file "channels.scm"
-              (with-output-to-string
-                (lambda _
-                  (pretty-print (map channel->code %default-channels))))))
+(define (install-channels-file channels)
+  "Return a gexp with code to install CHANNELS, a list of channels, in
+/etc/guix/channels.scm."
+  (define channels-file
+    (scheme-file "channels.scm"
+                 `(list ,@(map channel->code channels))))
 
-;; FIXME: Should this gexp be built before boot, like
-;; substitute-key-authorization does?
-(define (install-channels-file channels-file)
-  "Return a gexp with code to install CHANNELS-FILE, a file-like object."
   (with-imported-modules '((guix build utils))
     #~(begin
         (use-modules (guix build utils))
@@ -1828,7 +1823,7 @@ (define-record-type* <guix-configuration>
   (generate-substitute-key? guix-configuration-generate-substitute-key?
                             (default #t))         ;Boolean
   (channels         guix-configuration-channels ;file-like
-                    (default %default-channels-file))
+                    (default %default-channels))
   (chroot-directories guix-configuration-chroot-directories ;list of file-like/strings
                       (default '()))
   (max-silent-time  guix-configuration-max-silent-time ;integer
@@ -2040,7 +2035,7 @@ (define (guix-activation config)
               #~#f)
 
         ;; ... and /etc/guix/channels.scm...
-        #$(install-channels-file channels)
+        #$(and channels (install-channels-file channels))
 
         ;; ... and /etc/guix/machines.scm.
         #$(if (guix-build-machines config)