[PATCH] gnu: guix: Correct home-channels-service-type extension logic.

  • Open
  • quality assurance status badge
Details
2 participants
  • Ludovic Courtès
  • Nicolas Graves
Owner
unassigned
Submitted by
Nicolas Graves
Severity
normal
N
N
Nicolas Graves wrote on 11 Feb 13:44 +0100
(address . guix-patches@gnu.org)(address . ngraves@ngraves.fr)
20240211124505.15924-1-ngraves@ngraves.fr
* 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(-)

Toggle diff (39 lines)
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)))
--
2.41.0
N
N
Nicolas Graves wrote on 11 Feb 18:20 +0100
Light rework needed
(address . 69052@debbugs.gnu.org)
87a5o6hq8m.fsf@ngraves.fr
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.

--
Best regards,
Nicolas Graves
N
N
Nicolas Graves wrote on 25 Feb 07:09 +0100
[PATCH v2] gnu: guix: Correct home-channels-service-type extension logic.
(address . 69052@debbugs.gnu.org)(address . ngraves@ngraves.fr)
20240225060917.12152-1-ngraves@ngraves.fr
* 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(-)

Toggle diff (47 lines)
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)))
--
2.41.0
L
L
Ludovic Courtès wrote on 2 Mar 16:19 +0100
(name . Nicolas Graves)(address . ngraves@ngraves.fr)(address . 69052@debbugs.gnu.org)
87a5ngek4o.fsf@gnu.org
Hi,

Nicolas Graves <ngraves@ngraves.fr> skribis:

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

[...]

Toggle quote (5 lines)
> +(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.

Toggle quote (10 lines)
> +(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))

[...]

Toggle quote (2 lines)
> + (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’.
L
L
Ludovic Courtès wrote on 29 Mar 23:16 +0100
control message for bug #69052
(address . control@debbugs.gnu.org)
87v854fzv3.fsf@gnu.org
tags 69052 + moreinfo
quit
N
N
Nicolas Graves wrote on 14 Apr 01:33 +0200
[PATCH v3] gnu: guix: Correct home-channels-service-type extension logic.
(address . 69052@debbugs.gnu.org)
20240413233315.14875-1-ngraves@ngraves.fr
* 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 | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

Toggle diff (35 lines)
diff --git a/gnu/home/services/guix.scm b/gnu/home/services/guix.scm
index 819b20b6c9..d31d3126bb 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,12 @@ (define-module (gnu home services guix)
#:use-module (srfi srfi-1)
#:export (home-channels-service-type))
+(define (extend-channel-list initial new)
+ (delete-duplicates
+ (append initial new)
+ (lambda (channel1 channel2)
+ (eq? (channel-name channel1) (channel-name channel2)))))
+
(define (channels-xdg-files channels)
`(("guix/channels.scm"
,(plain-file
@@ -37,7 +44,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)))
--
2.41.0
?