diff mbox series

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

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

Commit Message

Nicolas Graves Feb. 25, 2024, 6:09 a.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 | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

Ludovic Courtès March 2, 2024, 3:19 p.m. UTC | #1
Hi,

Nicolas Graves <ngraves@ngraves.fr> skribis:

> * gnu/home/services/guix.scm
> (extend-channel-list): Add function.
> (home-channels-service-type)[extend]: Use extend-channel-list.
>
> Change-Id: I587207b86216f075a54b6ed0b8fa998896bbed74

[...]

> +(define (channel-name-symbol channel)
> +  (match (channel-name channel)
> +    ((? symbol? name) name)
> +    ((? string? name) (string->symbol name))))

‘channel-name’ always returns a symbol so this procedure can be removed.

> +(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-symbol acc))
> +         acc
> +         (cons channel acc)))
> +   new default))

[...]

> +   (extend extend-channel-list)

I believe it’s equivalent to:

  (define (extend-channel-list initial new)
    (delete-duplicates
     (append initial new)
     (lambda (channel1 channel2)
       (eq? (channel-name channel1) (channel-name channel2)))))

… which is somewhat clearer IMO.

Could you send an updated patch?

Ludo’.
diff mbox series

Patch

diff --git a/gnu/home/services/guix.scm b/gnu/home/services/guix.scm
index 819b20b6c9..1b33fc2865 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.
 ;;;
@@ -22,8 +23,24 @@  (define-module (gnu home services guix)
   #:use-module (guix gexp)
   #:use-module (ice-9 pretty-print)
   #:use-module (srfi srfi-1)
+  #:use-module (ice-9 match)
   #:export (home-channels-service-type))
 
+(define (channel-name-symbol channel)
+  (match (channel-name channel)
+    ((? symbol? name) name)
+    ((? string? name) (string->symbol name))))
+
+(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-symbol acc))
+         acc
+         (cons channel acc)))
+   new default))
+
 (define (channels-xdg-files channels)
   `(("guix/channels.scm"
      ,(plain-file
@@ -37,7 +54,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)))