unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: Felix Lechner via Bug reports for GNU Guix <bug-guix@gnu.org>
To: 64106@debbugs.gnu.org
Cc: "Josselin Poiret" <dev@jpoiret.xyz>,
	"Bruno Victal" <mirai@makinata.eu>, "Brian Cully" <bjc@spork.org>,
	"Ludovic Courtès" <ludo@gnu.org>,
	pelzflorian <pelzflorian@pelzflorian.de>,
	"Jelle Licht" <jlicht@fsfe.org>,
	"David Wilson" <david@daviwil.com>,
	"Felix Lechner" <felix.lechner@lease-up.com>
Subject: bug#64106: [PATCH] In modify-services, delete multiple services with one stanza. (Closes: #63921, #64106)
Date: Mon, 26 Jun 2023 12:22:17 -0700	[thread overview]
Message-ID: <85c8a4ded1532e8fe480d17a91d9a2e93554df11.1687807313.git.felix.lechner@lease-up.com> (raw)
In-Reply-To: <f10daa64-f097-4d2b-8078-ab36fc84069d@app.fastmail.com>

With this commit, modify-services will delete all instances of the services
that match the indicated service-type. At the same time, it will also raise
errors for misconfigurations.

The patch was motivated by Brian Cully's statements about the difficult
tradeoff here. [1]

Using the changes respectfully submitted there, modify-services will extract
the "delete" clauses from the clause-alist via code inspired by SRFI-1's
lset-difference. It applies those deletions first, before then passing the
remaining clauses (and the remaining services) on to apply-clauses.

It is possible that apply-clauses can also be simplified since the "delete"
case is now gone, but I remain unsure about how to do that.

This commit was lightly tested on a production machine.

The author owes a deep debt of gratitude to Zipheir from the IRC channel
Libera:#scheme for their expert help in understanding the problem and in
coming up with an elegant solution.

Similarly, Bruno Victal (aka mirai) provided major encouragment with his
participation in the same conversation.

Thank you to both of you!

[1] https://issues.guix.gnu.org/64106#4

* gnu/services.scm: In modify-services, delete multiple services with one
stanza. (Closes: #63921, #64106)
---
 gnu/services.scm | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/gnu/services.scm b/gnu/services.scm
index 109e050a23..f3772ad6b9 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -46,6 +46,7 @@ (define-module (gnu services)
   #:use-module (gnu packages hurd)
   #:use-module (gnu system setuid)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-8)
   #:use-module (srfi srfi-9)
   #:use-module (srfi srfi-9 gnu)
   #:use-module (srfi srfi-26)
@@ -305,8 +306,7 @@ (define-syntax clause-alist
 is the source location information."
     ((_ (delete kind) rest ...)
      (cons (list kind
-                 (lambda (service)
-                   #f)
+                 #f
                  (current-source-location))
            (clause-alist rest ...)))
     ((_ (kind param => exp ...) rest ...)
@@ -320,6 +320,16 @@ (define-syntax clause-alist
     ((_)
      '())))
 
+(define (clause-kind clause)
+  (match clause
+    ((kind _ _)
+     kind)))
+
+(define (clause-proc clause)
+  (match clause
+    ((_ proc _)
+     proc)))
+
 (define (apply-clauses clauses services)
   "Apply CLAUSES, an alist as returned by 'clause-alist', to SERVICES, a list
 of services.  Use each clause at most once; raise an error if a clause was not
@@ -393,7 +403,29 @@ (define-syntax modify-services
 all the MINGETTY-SERVICE-TYPE instances, and it deletes instances of the
 UDEV-SERVICE-TYPE."
     ((_ services clauses ...)
-     (apply-clauses (clause-alist clauses ...) services))))
+     (receive (others deletes) (partition clause-proc (clause-alist clauses ...))
+       (let ((reduced-services (remove (lambda (service)
+                                         (find (lambda (clause)
+                                                 (eq? (clause-kind clause)
+                                                      (service-kind service)))
+                                               deletes))
+                                       services))
+             (deletes-not-found (remove (lambda (clause)
+                                          (find (lambda (service)
+                                                  (eq? (clause-kind clause)
+                                                       (service-kind service)))
+                                                services))
+                                        deletes)))
+         (for-each (lambda (clause)
+                     (raise (make-compound-condition
+                             (condition
+                              (&error-location
+                               (location (current-source-location))))
+                             (formatted-message
+                              (G_ "modify-services: cannot delete '~a'; not present in service list")
+                              (service-type-name (clause-kind clause))))))
+                   deletes-not-found)
+         (apply-clauses others reduced-services))))))
 
 \f
 ;;;

base-commit: 269cfe341f242c2b5f37774cb9b1e17d9aa68e2c
-- 
2.40.1





  parent reply	other threads:[~2023-06-26 19:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16 12:52 bug#64106: `modify-services` no longer affects multiple instances of the same service David Wilson
2023-06-17 15:51 ` Josselin Poiret via Bug reports for GNU Guix
2023-06-19  7:34   ` Ludovic Courtès
2023-06-21 18:10     ` Brian Cully via Bug reports for GNU Guix
2023-07-07 14:11       ` Ludovic Courtès
2023-07-18 12:28         ` Brian Cully via Bug reports for GNU Guix
2023-06-26 19:22 ` Felix Lechner via Bug reports for GNU Guix [this message]
2023-07-17 17:02 ` bug#64106: [PATCH] gnu: services: Revert to deleting and updating all matching services Brian Cully via Bug reports for GNU Guix
2023-09-01  3:49   ` bug#65184: (modify-services … (delete …)) should delete all matching service types Maxim Cournoyer
2023-09-01  4:00     ` bug#64106: " Felix Lechner via Bug reports for GNU Guix

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=85c8a4ded1532e8fe480d17a91d9a2e93554df11.1687807313.git.felix.lechner@lease-up.com \
    --to=bug-guix@gnu.org \
    --cc=64106@debbugs.gnu.org \
    --cc=bjc@spork.org \
    --cc=david@daviwil.com \
    --cc=dev@jpoiret.xyz \
    --cc=felix.lechner@lease-up.com \
    --cc=jlicht@fsfe.org \
    --cc=ludo@gnu.org \
    --cc=mirai@makinata.eu \
    --cc=pelzflorian@pelzflorian.de \
    /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).