diff mbox series

[bug#69052] gnu: guix: Correct home-channels-service-type extension logic.

Message ID 20240211124505.15924-1-ngraves@ngraves.fr
State New
Headers show
Series [bug#69052] gnu: guix: Correct home-channels-service-type extension logic. | expand

Commit Message

Nicolas Graves Feb. 11, 2024, 12:44 p.m. UTC
* gnu/home/services/guix.scm
(extend-channel-list): Add function.
(home-channels-service-type)[extend]: Use extend-channel-list.

Change-Id: I587207b86216f075a54b6ed0b8fa998896bbed74
---
 gnu/home/services/guix.scm | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Nicolas Graves Feb. 11, 2024, 5:20 p.m. UTC | #1
If that's not straightforward: this patch allows the service to accept
an additional guix channel which replaces the default in this
case. Currently the default was to append, thus you could not use
another guix channel (a local guix for instance).

I've seen that a light rework is necessary. This is due to the fact that
a channel name can be both a symbol and a string, we thus need to ensure
that the (member ...) comparison is properly done if the user uses
strings instead of symbols in channel definition.
diff mbox series

Patch

diff --git a/gnu/home/services/guix.scm b/gnu/home/services/guix.scm
index 819b20b6c9..3702976496 100644
--- a/gnu/home/services/guix.scm
+++ b/gnu/home/services/guix.scm
@@ -1,5 +1,6 @@ 
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2022 Reily Siegel <mail@reilysiegel.com>
+;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -24,6 +25,16 @@  (define-module (gnu home services guix)
   #:use-module (srfi srfi-1)
   #:export (home-channels-service-type))
 
+(define (extend-channel-list default new)
+  "Prepend the channels in NEW by the channels in DEFAULT if their
+channel-name is not in NEW."
+  (fold-right
+   (lambda (channel acc)
+     (if (member (channel-name channel) (map channel-name acc))
+         acc
+         (cons channel acc)))
+   new default))
+
 (define (channels-xdg-files channels)
   `(("guix/channels.scm"
      ,(plain-file
@@ -37,7 +48,7 @@  (define home-channels-service-type
    (name 'home-channels)
    (default-value %default-channels)
    (compose concatenate)
-   (extend append)
+   (extend extend-channel-list)
    (extensions
     (list (service-extension home-xdg-configuration-files-service-type
                              channels-xdg-files)))