unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Antero Mejr via Guix-patches via <guix-patches@gnu.org>
To: 49610@debbugs.gnu.org
Cc: ludo@gnu.org
Subject: [bug#49610] [PATCH v3] services: guix: Add channels field.
Date: Thu, 25 May 2023 20:12:16 +0000	[thread overview]
Message-ID: <20230525201216.16870-1-antero@mailbox.org> (raw)
In-Reply-To: <20210717205819.380-1-brice@waegenei.re>

* doc/guix.texi (Channels): Specify that '/etc/guix/channels.scm'
contains channels configuration.
(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.
---
Updated v3 patch.
Changed the channels field to accept a file-like object instead of an
S-expression. I think this is more flexible because it lets users
specify a local-file rather than just an sexp.

I think this will be a unexpected/breaking change for Guix System users. If they
have /etc/guix/channels.scm customized manually, on their next 'guix system
reconfigure', it will move that file and use the channels field, unless they
modify guix-configuration.  Maybe this change should have a NEWS entry?

 doc/guix.texi         | 17 +++++++++++++++--
 gnu/services/base.scm | 44 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 31dc33fb97..d0367ab8c5 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -5397,8 +5397,8 @@ $ wget -O - \
 Guix and its package collection are updated by running @command{guix pull}
 (@pxref{Invoking guix pull}).  By default @command{guix pull} downloads and
 deploys Guix itself from the official GNU@tie{}Guix repository.  This can be
-customized by defining @dfn{channels} in the
-@file{~/.config/guix/channels.scm} file.  A channel specifies a URL and branch
+customized by defining @dfn{channels} in the @file{/etc/guix/channels.scm} and
+@file{~/.config/guix/channels.scm} files.  A channel specifies a URL and branch
 of a Git repository to be deployed, and @command{guix pull} can be instructed
 to pull from one or more channels.  In other words, channels can be used
 to @emph{customize} and to @emph{extend} Guix, as we will see below.
@@ -18858,6 +18858,19 @@ few seconds when enough entropy is available and is only done once; you
 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.
 
+@item @code{channels} (default: @code{%default-channels-file})
+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}.
+
+@quotation Note
+When reconfiguring a system, the existing @file{/etc/guix/channels.scm}
+file is backed up as @file{/etc/guix/channels.scm.bak} if it was
+determined to be a manually modified file.  This is to facilitate
+migration from earlier versions, which allowed for in-place
+modifications to @file{/etc/guix/channels.scm}.
+@end quotation
+
 @item @code{max-silent-time} (default: @code{0})
 @itemx @code{timeout} (default: @code{0})
 The number of seconds of silence and the number of seconds of activity,
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index c5b06b57e8..e61bf6eac7 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -80,6 +80,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)
   #:use-module (guix gexp)
   #:use-module (guix records)
   #:use-module (guix modules)
@@ -93,6 +94,7 @@ (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
@@ -207,6 +209,7 @@ (define-module (gnu services base)
             guix-configuration-use-substitutes?
             guix-configuration-substitute-urls
             guix-configuration-generate-substitute-key?
+            guix-configuration-channels
             guix-configuration-extra-options
             guix-configuration-log-file
             guix-configuration-environment
@@ -1739,6 +1742,39 @@ (define acl-file #$%acl-file)
         ;; 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 (lambda (channel)
+                                       (if (channel? channel)
+                                           (channel->code channel)
+                                           channel))
+                                     %default-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))
+
+        ;; If channels.scm already exists, move it out of the way. Create a
+        ;; backup if it's a regular file: it's likely that the user
+        ;; manually defined it.
+        (if (file-exists? "/etc/guix/channels.scm")
+            (if (and (symbolic-link? "/etc/guix/channels.scm")
+                     (store-file-name? (readlink "/etc/guix/channels.scm")))
+                (delete-file "/etc/guix/channels.scm")
+                (rename-file "/etc/guix/channels.scm"
+                             "/etc/guix/channels.scm.bak"))
+            (mkdir-p "/etc/guix"))
+
+        ;; Installed the declared channels.
+        (symlink #+channels-file "/etc/guix/channels.scm"))))
+
 (define %default-authorized-guix-keys
   ;; List of authorized substitute keys.
   (list (file-append guix "/share/guix/berlin.guix.gnu.org.pub")
@@ -1763,6 +1799,8 @@ (define-record-type* <guix-configuration>
                     (default %default-substitute-urls))
   (generate-substitute-key? guix-configuration-generate-substitute-key?
                             (default #t))         ;Boolean
+  (channels         guix-configuration-channels ;file-like
+                    (default %default-channels-file))
   (chroot-directories guix-configuration-chroot-directories ;list of file-like/strings
                       (default '()))
   (max-silent-time  guix-configuration-max-silent-time ;integer
@@ -1949,7 +1987,7 @@ (define (guix-accounts config)
 (define (guix-activation config)
   "Return the activation gexp for CONFIG."
   (match-record config <guix-configuration>
-    (guix generate-substitute-key? authorize-key? authorized-keys)
+    (guix generate-substitute-key? authorize-key? authorized-keys channels)
     #~(begin
         ;; Assume that the store has BUILD-GROUP as its group.  We could
         ;; otherwise call 'chown' here, but the problem is that on a COW overlayfs,
@@ -1963,7 +2001,9 @@ (define (guix-activation config)
 
         #$(if authorize-key?
               (substitute-key-authorization authorized-keys guix)
-              #~#f))))
+              #~#f)
+
+        #$(install-channels-file channels))))
 
 (define-record-type* <guix-extension>
   guix-extension make-guix-extension
-- 
2.39.2





  parent reply	other threads:[~2023-05-25 20:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-17 20:58 [bug#49610] [PATCH 0/2] Add channels field to guix-configuration Brice Waegeneire
2021-07-17 21:04 ` [bug#49610] [PATCH 1/2] services: guix: Use "match-record" in activation Brice Waegeneire
2021-07-21 21:47   ` [bug#49610] [PATCH 0/2] Add channels field to guix-configuration Ludovic Courtès
2021-08-04  4:42     ` Brice Waegeneire
2021-07-17 21:04 ` [bug#49610] [PATCH 2/2] services: guix: Add channels field Brice Waegeneire
2021-07-21 21:53   ` [bug#49610] [PATCH 0/2] Add channels field to guix-configuration Ludovic Courtès
2021-09-01 21:16     ` Ludovic Courtès
2021-12-21 21:00     ` [bug#49610] [PATCH v2] sevices: guix: Add channels field Brice Waegeneire
2022-01-03 11:32       ` Ludovic Courtès
2023-05-25 20:12 ` Antero Mejr via Guix-patches via [this message]
2023-05-26 10:40   ` [bug#49610] [PATCH v3] services: " Simon Tournier
2023-05-26 16:29     ` Antero Mejr via Guix-patches via
2023-05-26 16:26 ` [bug#49610] [PATCH v4 1/2] " Antero Mejr via Guix-patches via
2023-05-26 16:26   ` [bug#49610] [PATCH v4 2/2] doc: guix.texi: Clarify wording in Channels section Antero Mejr via Guix-patches via
2024-03-22 10:45     ` Ludovic Courtès
2024-03-22 10:44   ` [bug#49610] [PATCH v4 1/2] services: guix: Add channels field Ludovic Courtès
2024-03-24 10:24 ` [bug#49610] [PATCH 0/2] Add channels field to guix-configuration Franz Geffke
2024-04-04  8:03   ` Simon Tournier
2024-04-09  8:44     ` Franz Geffke

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

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230525201216.16870-1-antero@mailbox.org \
    --to=guix-patches@gnu.org \
    --cc=49610@debbugs.gnu.org \
    --cc=antero@mailbox.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 public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).