GNU bug report logs - #55752
[PATCH 0/5] Add 'guix system edit' and 'guix home edit'

Previous Next

Package: guix-patches;

Reported by: Ludovic Courtès <ludo <at> gnu.org>

Date: Wed, 1 Jun 2022 15:42:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 55752 in the body.
You can then email your comments to 55752 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#55752; Package guix-patches. (Wed, 01 Jun 2022 15:42:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ludovic Courtès <ludo <at> gnu.org>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Wed, 01 Jun 2022 15:42:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: guix-patches <at> gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 0/5] Add 'guix system edit' and 'guix home edit'
Date: Wed,  1 Jun 2022 17:41:40 +0200
Hello Guix!

This is the long-overdue addition of ‘guix system edit’ and
‘guix home edit’ to edit service type definitions.

Thoughts?

Ludo’.

Ludovic Courtès (5):
  edit: Extract 'spawn-editor' procedure.
  guix system: Add 'edit' sub-command.
  home: services: Add 'lookup-home-service-types' procedure.
  guix home: Add 'edit' sub-command.
  DRAFT news: Add entry for 'guix system edit' and 'guix home edit'.

 Makefile.am                  |  5 ++-
 doc/guix.texi                | 26 ++++++++++++++
 etc/news.scm                 | 28 +++++++++++++++
 gnu/home/services.scm        | 12 +++++++
 guix/scripts/edit.scm        | 30 +++++++++-------
 guix/scripts/home.scm        |  7 +++-
 guix/scripts/home/edit.scm   | 66 ++++++++++++++++++++++++++++++++++++
 guix/scripts/system.scm      |  7 +++-
 guix/scripts/system/edit.scm | 64 ++++++++++++++++++++++++++++++++++
 po/guix/POTFILES.in          |  2 ++
 tests/home-services.scm      | 46 +++++++++++++++++++++++++
 11 files changed, 278 insertions(+), 15 deletions(-)
 create mode 100644 guix/scripts/home/edit.scm
 create mode 100644 guix/scripts/system/edit.scm
 create mode 100644 tests/home-services.scm


base-commit: fed51b26141548a5bae349a5e1d8d6f681320f4f
-- 
2.36.1





Information forwarded to guix-patches <at> gnu.org:
bug#55752; Package guix-patches. (Wed, 01 Jun 2022 15:44:02 GMT) Full text and rfc822 format available.

Message #8 received at 55752 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: 55752 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 1/5] edit: Extract 'spawn-editor' procedure.
Date: Wed,  1 Jun 2022 17:42:58 +0200
* guix/scripts/edit.scm (spawn-editor): New procedure, with code from...
(guix-edit): ... here.  Use it.
---
 guix/scripts/edit.scm | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/guix/scripts/edit.scm b/guix/scripts/edit.scm
index a2e1ffb434..8e777d1405 100644
--- a/guix/scripts/edit.scm
+++ b/guix/scripts/edit.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2015, 2016, 2019, 2020, 2021 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2015-2016, 2019-2022 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2015 Mathieu Lirzin <mthl <at> gnu.org>
 ;;; Copyright © 2020, 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
@@ -27,6 +27,7 @@ (define-module (guix scripts edit)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-37)
   #:export (%editor
+            spawn-editor
             guix-edit))
 
 (define %options
@@ -77,6 +78,21 @@ (define (location->location-specification location)
                         (location-line location)))
         (search-path* %load-path (location-file location))))
 
+(define (spawn-editor locations)
+  "Spawn (%editor) to edit the code at LOCATIONS, a list of <location>
+records, and exit."
+  (catch 'system-error
+    (lambda ()
+      (let ((file-names (append-map location->location-specification
+                                    locations)))
+        ;; Use `system' instead of `exec' in order to sanely handle
+        ;; possible command line arguments in %EDITOR.
+        (exit (system (string-join (cons (%editor) file-names))))))
+    (lambda args
+      (let ((errno (system-error-errno args)))
+        (leave (G_ "failed to launch '~a': ~a~%")
+               (%editor) (strerror errno))))))
+
 
 (define-command (guix-edit . args)
   (category packaging)
@@ -94,14 +110,4 @@ (define (parse-arguments)
       (when (null? specs)
         (leave (G_ "no packages specified, nothing to edit~%")))
 
-      (catch 'system-error
-        (lambda ()
-          (let ((file-names (append-map location->location-specification
-                                        locations)))
-            ;; Use `system' instead of `exec' in order to sanely handle
-            ;; possible command line arguments in %EDITOR.
-            (exit (system (string-join (cons (%editor) file-names))))))
-        (lambda args
-          (let ((errno (system-error-errno args)))
-            (leave (G_ "failed to launch '~a': ~a~%")
-                   (%editor) (strerror errno))))))))
+      (spawn-editor locations))))
-- 
2.36.1





Information forwarded to guix-patches <at> gnu.org:
bug#55752; Package guix-patches. (Wed, 01 Jun 2022 15:44:02 GMT) Full text and rfc822 format available.

Message #11 received at 55752 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: 55752 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 3/5] home: services: Add 'lookup-home-service-types' procedure.
Date: Wed,  1 Jun 2022 17:43:00 +0200
* gnu/home/services.scm (lookup-home-service-types): New procedure.
* tests/home-services.scm: New file.
* Makefile.am (SCM_TESTS): Add it.
---
 Makefile.am             |  1 +
 gnu/home/services.scm   | 12 +++++++++++
 tests/home-services.scm | 46 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+)
 create mode 100644 tests/home-services.scm

diff --git a/Makefile.am b/Makefile.am
index f585d00b86..89bc03c9a2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -497,6 +497,7 @@ SCM_TESTS =					\
   tests/gremlin.scm				\
   tests/hackage.scm				\
   tests/home-import.scm				\
+  tests/home-services.scm			\
   tests/http-client.scm				\
   tests/import-git.scm				\
   tests/import-github.scm			\
diff --git a/gnu/home/services.scm b/gnu/home/services.scm
index 8284a4f3fc..5ee3357792 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -33,6 +33,7 @@ (define-module (gnu home services)
   #:use-module (guix modules)
   #:use-module (srfi srfi-1)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 vlist)
 
   #:export (home-service-type
             home-profile-service-type
@@ -50,6 +51,7 @@ (define-module (gnu home services)
             xdg-data-files-directory
 
             fold-home-service-types
+            lookup-home-service-types
             home-provenance
 
             %initialize-gettext)
@@ -605,3 +607,13 @@ (define (all-home-service-modules)
 
 (define* (fold-home-service-types proc seed)
   (fold-service-types proc seed (all-home-service-modules)))
+
+(define lookup-home-service-types
+  (let ((table
+         (delay (fold-home-service-types (lambda (type result)
+                                           (vhash-consq (service-type-name type)
+                                                        type result))
+                                         vlist-null))))
+    (lambda (name)
+      "Return the list of services with the given NAME (a symbol)."
+      (vhash-foldq* cons '() name (force table)))))
diff --git a/tests/home-services.scm b/tests/home-services.scm
new file mode 100644
index 0000000000..e13733cabd
--- /dev/null
+++ b/tests/home-services.scm
@@ -0,0 +1,46 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 Ludovic Courtès <ludo <at> gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (test-home-services)
+  #:use-module (gnu services)
+  #:use-module (gnu home services)
+  #:use-module (guix diagnostics)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-64)
+  #:use-module (ice-9 match))
+
+(test-begin "home-services")
+
+(test-assert "fold-home-service-types"
+  (match (fold-home-service-types cons '())
+    (() #f)
+    (lst (and (every service-type? lst)
+              (every (lambda (type)
+                       (let ((location (service-type-location type)))
+                         (string-contains (location-file location)
+                                          "gnu/home")))
+                     lst)))))
+
+(test-eq "lookup-service-types"
+  home-files-service-type
+  (and (null? (lookup-home-service-types 'does-not-exist-at-all))
+       (match (lookup-home-service-types 'home-files)
+         ((one) one)
+         (x x))))
+
+(test-end)
-- 
2.36.1





Information forwarded to guix-patches <at> gnu.org:
bug#55752; Package guix-patches. (Wed, 01 Jun 2022 15:44:02 GMT) Full text and rfc822 format available.

Message #14 received at 55752 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: 55752 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 5/5] DRAFT news: Add entry for 'guix system edit' and 'guix
 home edit'.
Date: Wed,  1 Jun 2022 17:43:02 +0200
DRAFT: Add correct commit ID before pushing.

* etc/news.scm: Add entry.
---
 etc/news.scm | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/etc/news.scm b/etc/news.scm
index a74ca94b8a..70ef607911 100644
--- a/etc/news.scm
+++ b/etc/news.scm
@@ -25,6 +25,34 @@
 (channel-news
  (version 0)
 
+ (entry (commit "XXX")
+        (title
+         (en "New @command{edit} sub-commands for services")
+         (fr "Nouvelles commandes @command{edit} pour les services"))
+        (body
+         (en "The new @command{guix system edit} and @command{guix home edit} commands
+allow you to view or edit service types defined for Guix System or Guix Home.
+For example, here is how you would open the definition of the OpenSSH system
+service:
+
+@example
+guix system edit openssh
+@end example
+
+Run @command{info \"(guix) Invoking guix system\"} or @command{info \"(guix)
+Invoking guix home\"} for more info.")
+         (fr "Les nouvelles commandes @command{guix system edit} et
+@command{guix home edit} permettent de visualiser ou d'éditer les types de
+services définis pour Guix System ou Guix Home.  Par exemple, voici comment
+ouvrir la définition du service système OpenSSH :
+
+@example
+guix system edit openssh
+@end example
+
+Lancer @command{info \"(guix.fr) Invoquer guix system\"} ou @command{info
+\"(guix.fr) Invoquer guix home\"} pour plus d'informations.")))
+
  (entry (commit "903c82583e1cec4c9ff09d5895c5cc646c37b661")
         (title
          (en "New @command{guix import elm} command")
-- 
2.36.1





Information forwarded to guix-patches <at> gnu.org:
bug#55752; Package guix-patches. (Wed, 01 Jun 2022 15:44:03 GMT) Full text and rfc822 format available.

Message #17 received at 55752 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: 55752 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 4/5] guix home: Add 'edit' sub-command.
Date: Wed,  1 Jun 2022 17:43:01 +0200
* guix/scripts/home/edit.scm: New file.
* Makefile.am (MODULES): Add it.
* guix/scripts/home.scm (show-help): Add "edit".
(process-command): Handle it.
(guix-home): Add it.
* po/guix/POTFILES.in: Add 'guix/scripts/home/edit.scm'.
* doc/guix.texi (Invoking guix home): Document it.
---
 Makefile.am                |  1 +
 doc/guix.texi              | 13 ++++++++
 guix/scripts/home.scm      |  7 +++-
 guix/scripts/home/edit.scm | 66 ++++++++++++++++++++++++++++++++++++++
 po/guix/POTFILES.in        |  1 +
 5 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 guix/scripts/home/edit.scm

diff --git a/Makefile.am b/Makefile.am
index 89bc03c9a2..e8d4b7ef8a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -312,6 +312,7 @@ MODULES =					\
   guix/scripts/system/reconfigure.scm		\
   guix/scripts/system/search.scm		\
   guix/scripts/home.scm			\
+  guix/scripts/home/edit.scm			\
   guix/scripts/home/import.scm			\
   guix/scripts/lint.scm				\
   guix/scripts/challenge.scm			\
diff --git a/doc/guix.texi b/doc/guix.texi
index ecd99084ef..f85eaacdfa 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -39466,6 +39466,19 @@ guix home container config.scm -- herd status
 The command to run in the container must come after @code{--} (double
 hyphen).
 
+@cindex service type definition, editing
+@cindex editing, service type definition
+@item edit
+Edit or view the definition of the given Home service types.
+
+For example, the command below opens your editor, as specified by the
+@env{EDITOR} environment variable, on the definition of the
+@code{home-mcron} service type:
+
+@example
+guix home edit home-mcron
+@end example
+
 @item reconfigure
 Build the home environment described in @var{file}, and switch to it.
 Switching means that the activation script will be evaluated and (in
diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm
index f43bf865a7..0f5c3388a1 100644
--- a/guix/scripts/home.scm
+++ b/guix/scripts/home.scm
@@ -60,6 +60,7 @@ (define-module (guix scripts home)
   #:autoload   (guix scripts pull) (channel-commit-hyperlink)
   #:autoload   (guix scripts system) (service-node-type
                                       shepherd-service-node-type)
+  #:autoload   (guix scripts home edit) (guix-home-edit)
   #:autoload   (guix scripts home import) (import-manifest)
   #:use-module ((guix status) #:select (with-status-verbosity))
   #:use-module ((guix build utils) #:select (mkdir-p))
@@ -93,6 +94,8 @@ (define (show-help)
   (newline)
   (display (G_ "\
    search             search for existing service types\n"))
+  (display (G_ "\
+   edit               edit the definition of an existing service type\n"))
   (display (G_ "
    container          run the home environment configuration in a container\n"))
   (display (G_ "\
@@ -539,6 +542,8 @@ (define-syntax-rule (with-store* store exp ...)
     ;; an home environment file.
     ((search)
      (apply search args))
+    ((edit)
+     (apply guix-home-edit args))
     ((import)
      (let* ((profiles (delete-duplicates
                        (match (filter-map (match-lambda
@@ -611,7 +616,7 @@ (define (parse-sub-command arg result)
               extension-graph shepherd-graph
               list-generations describe
               delete-generations roll-back
-              switch-generation search
+              switch-generation search edit
               import container)
              (alist-cons 'action action result))
             (else (leave (G_ "~a: unknown action~%") action))))))
diff --git a/guix/scripts/home/edit.scm b/guix/scripts/home/edit.scm
new file mode 100644
index 0000000000..a6c05675b3
--- /dev/null
+++ b/guix/scripts/home/edit.scm
@@ -0,0 +1,66 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 Ludovic Courtès <ludo <at> gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix scripts home edit)
+  #:use-module (guix diagnostics)
+  #:use-module (guix i18n)
+  #:use-module (guix ui)
+  #:autoload   (guix utils) (string-closest)
+  #:use-module (gnu services)
+  #:use-module (gnu home services)
+  #:use-module (srfi srfi-1)
+  #:use-module (ice-9 match)
+  #:autoload   (guix scripts edit) (spawn-editor)
+  #:export (guix-home-edit))
+
+(define (service-type-not-found type)
+  "Report an error about @var{type} not being found and exit."
+  (report-error (G_ "~a: no such service type~%") type)
+
+  (let* ((type      (symbol->string type))
+         (available (fold-home-service-types (lambda (type lst)
+                                               (cons (symbol->string
+                                                      (service-type-name type))
+                                                     lst))
+                                             '()))
+         (closest   (string-closest type available)))
+    (unless (or (not closest) (string=? closest type))
+      (display-hint (format #f (G_ "Did you mean @code{~a}?~%")
+                            closest))))
+
+  (exit 1))
+
+
+(define (guix-home-edit . args)
+  (when (null? args)
+    (leave (G_ "no service types specified, nothing to edit~%")))
+
+  (with-error-handling
+    (let* ((types (append-map (lambda (type)
+                                (let ((type (string->symbol type)))
+                                  (match (lookup-home-service-types type)
+                                    (() (service-type-not-found type))
+                                    ((one) (list one))
+                                    (lst
+                                     (warning (N_ "~a: ~a matching service type~%"
+                                                  "~a: ~a matching service types~%"
+                                                  (length lst))
+                                              type (length lst))
+                                     lst))))
+                              args)))
+      (spawn-editor (filter-map service-type-location types)))))
diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in
index 5ad3c9f0a8..6b8bd92bb7 100644
--- a/po/guix/POTFILES.in
+++ b/po/guix/POTFILES.in
@@ -125,6 +125,7 @@ guix/scripts/archive.scm
 guix/scripts/build.scm
 guix/scripts/discover.scm
 guix/scripts/environment.scm
+guix/scripts/home/edit.scm
 guix/scripts/home/import.scm
 guix/scripts/home.scm
 guix/scripts/time-machine.scm
-- 
2.36.1





Information forwarded to guix-patches <at> gnu.org:
bug#55752; Package guix-patches. (Wed, 01 Jun 2022 15:44:03 GMT) Full text and rfc822 format available.

Message #20 received at 55752 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: 55752 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 2/5] guix system: Add 'edit' sub-command.
Date: Wed,  1 Jun 2022 17:42:59 +0200
* guix/scripts/system/edit.scm: New file.
* Makefile.am (MODULES): Add it.
* guix/scripts/system.scm (show-help): Mention "edit".
(actions): Add it.
(process-command): Handle it.
* doc/guix.texi (Invoking guix system): Document it.
* po/guix/POTFILES.in: Add guix/scripts/system/edit.scm.
---
 Makefile.am                  |  3 +-
 doc/guix.texi                | 13 ++++++++
 guix/scripts/system.scm      |  7 +++-
 guix/scripts/system/edit.scm | 64 ++++++++++++++++++++++++++++++++++++
 po/guix/POTFILES.in          |  1 +
 5 files changed, 86 insertions(+), 2 deletions(-)
 create mode 100644 guix/scripts/system/edit.scm

diff --git a/Makefile.am b/Makefile.am
index 968bde8131..f585d00b86 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -308,8 +308,9 @@ MODULES =					\
   guix/scripts/describe.scm			\
   guix/scripts/style.scm			\
   guix/scripts/system.scm			\
-  guix/scripts/system/search.scm		\
+  guix/scripts/system/edit.scm			\
   guix/scripts/system/reconfigure.scm		\
+  guix/scripts/system/search.scm		\
   guix/scripts/home.scm			\
   guix/scripts/home/import.scm			\
   guix/scripts/lint.scm				\
diff --git a/doc/guix.texi b/doc/guix.texi
index 88e009fe7c..ecd99084ef 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -36617,6 +36617,19 @@ As for @command{guix package --search}, the result is written in
 @code{recutils} format, which makes it easy to filter the output
 (@pxref{Top, GNU recutils databases,, recutils, GNU recutils manual}).
 
+@cindex service type definition, editing
+@cindex editing, service type definition
+@item edit
+Edit or view the definition of the given service types.
+
+For example, the command below opens your editor, as specified by the
+@env{EDITOR} environment variable, on the definition of the
+@code{openssh} service type:
+
+@example
+guix system edit openssh
+@end example
+
 @item reconfigure
 Build the operating system described in @var{file}, activate it, and
 switch to it <at> footnote{This action (and the related actions
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index eaa245eb44..261a1d226d 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -944,6 +944,8 @@ (define (show-help)
   (newline)
   (display (G_ "\
    search           search for existing service types\n"))
+  (display (G_ "\
+   edit             edit the definition of an existing service type\n"))
   (display (G_ "\
    reconfigure      switch to a new operating system configuration\n"))
   (display (G_ "\
@@ -1172,7 +1174,8 @@ (define actions '("build" "container" "vm" "vm-image" "image" "disk-image"
                   "extension-graph" "shepherd-graph"
                   "list-generations" "describe"
                   "delete-generations" "roll-back"
-                  "switch-generation" "search" "docker-image"))
+                  "switch-generation" "search" "edit"
+                  "docker-image"))
 
 (define (process-action action args opts)
   "Process ACTION, a sub-command, with the arguments are listed in ARGS.
@@ -1340,6 +1343,8 @@ (define-syntax-rule (with-store* store exp ...)
         (display-system-generation generation))))
     ((search)
      (apply (resolve-subcommand "search") args))
+    ((edit)
+     (apply (resolve-subcommand "edit") args))
     ;; The following commands need to use the store, but they do not need an
     ;; operating system configuration file.
     ((delete-generations)
diff --git a/guix/scripts/system/edit.scm b/guix/scripts/system/edit.scm
new file mode 100644
index 0000000000..d966ee0aaa
--- /dev/null
+++ b/guix/scripts/system/edit.scm
@@ -0,0 +1,64 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 Ludovic Courtès <ludo <at> gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix scripts system edit)
+  #:use-module (guix diagnostics)
+  #:use-module (guix i18n)
+  #:use-module (guix ui)
+  #:autoload   (guix utils) (string-closest)
+  #:use-module (gnu services)
+  #:use-module (srfi srfi-1)
+  #:use-module (ice-9 match)
+  #:autoload   (guix scripts edit) (spawn-editor)
+  #:export (guix-system-edit))
+
+(define (service-type-not-found type)
+  "Report an error about @var{type} not being found and exit."
+  (report-error (G_ "~a: no such service type~%") type)
+
+  (let* ((type      (symbol->string type))
+         (available (fold-service-types (lambda (type lst)
+                                          (cons (symbol->string
+                                                 (service-type-name type))
+                                                lst))
+                                        '()))
+         (closest   (string-closest type available)))
+    (unless (or (not closest) (string=? closest type))
+      (display-hint (format #f (G_ "Did you mean @code{~a}?~%")
+                            closest))))
+
+  (exit 1))
+
+
+(define (guix-system-edit . args)
+  (when (null? args)
+    (leave (G_ "no service types specified, nothing to edit~%")))
+
+  (let* ((types (append-map (lambda (type)
+                              (let ((type (string->symbol type)))
+                                (match (lookup-service-types type)
+                                  (() (service-type-not-found type))
+                                  ((one) (list one))
+                                  (lst
+                                   (warning (N_ "~a: ~a matching service type~%"
+                                                "~a: ~a matching service types~%"
+                                                (length lst))
+                                            type (length lst))
+                                   lst))))
+                            args)))
+    (spawn-editor (filter-map service-type-location types))))
diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in
index 49a8edfef3..5ad3c9f0a8 100644
--- a/po/guix/POTFILES.in
+++ b/po/guix/POTFILES.in
@@ -87,6 +87,7 @@ guix/scripts/pull.scm
 guix/scripts/substitute.scm
 guix/scripts/authenticate.scm
 guix/scripts/system.scm
+guix/scripts/system/edit.scm
 guix/scripts/system/search.scm
 guix/scripts/lint.scm
 guix/scripts/publish.scm
-- 
2.36.1





Information forwarded to guix-patches <at> gnu.org:
bug#55752; Package guix-patches. (Thu, 02 Jun 2022 11:42:02 GMT) Full text and rfc822 format available.

Message #23 received at 55752 <at> debbugs.gnu.org (full text, mbox):

From: Maxime Devos <maximedevos <at> telenet.be>
To: Ludovic Courtès <ludo <at> gnu.org>, 55752 <at> debbugs.gnu.org
Subject: Re: [bug#55752] [PATCH 5/5] DRAFT news: Add entry for 'guix system
 edit' and 'guix home edit'.
Date: Thu, 02 Jun 2022 13:41:26 +0200
[Message part 1 (text/plain, inline)]
Ludovic Courtès schreef op wo 01-06-2022 om 17:43 [+0200]:
> + (entry (commit "XXX")
> +        (title
> +         (en "New @command{edit} sub-commands for services")
> +         (fr "Nouvelles commandes @command{edit} pour les services"))

(nl "Nieuwe deelopdracht @command{edit} voor diensten)
(body
  ;; TODO: pas verwijzingen naar de handleiding aan wanneer ze vertaald is
  (nl "Met de nieuwe bewerkingen @command{guix system edit} en
@command{guix home edit} kan je dienstsoorten van Guix System en Guix
Home bekijken en bewerken.  Je kan bijvoorbeeld de definitie van de
systeemdienst OpenSSH als volgt openen:

@example
guix system edit openssh
@end example.

Voer @command{info \"(guix) Invoking guix system\"} of @command{info
\"(guix)Invoking guix home\"} uit voor meer informatie.")


[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#55752; Package guix-patches. (Thu, 02 Jun 2022 13:27:02 GMT) Full text and rfc822 format available.

Message #26 received at 55752 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Maxime Devos <maximedevos <at> telenet.be>
Cc: 55752 <at> debbugs.gnu.org
Subject: Re: [bug#55752] [PATCH 5/5] DRAFT news: Add entry for 'guix system
 edit' and 'guix home edit'.
Date: Thu, 02 Jun 2022 15:26:06 +0200
Goeden dag!

Maxime Devos <maximedevos <at> telenet.be> skribis:

> Ludovic Courtès schreef op wo 01-06-2022 om 17:43 [+0200]:
>> + (entry (commit "XXX")
>> +        (title
>> +         (en "New @command{edit} sub-commands for services")
>> +         (fr "Nouvelles commandes @command{edit} pour les services"))
>
> (nl "Nieuwe deelopdracht @command{edit} voor diensten)
> (body
>   ;; TODO: pas verwijzingen naar de handleiding aan wanneer ze vertaald is
>   (nl "Met de nieuwe bewerkingen @command{guix system edit} en
> @command{guix home edit} kan je dienstsoorten van Guix System en Guix
> Home bekijken en bewerken.  Je kan bijvoorbeeld de definitie van de
> systeemdienst OpenSSH als volgt openen:
>
> @example
> guix system edit openssh
> @end example.
>
> Voer @command{info \"(guix) Invoking guix system\"} of @command{info
> \"(guix)Invoking guix home\"} uit voor meer informatie.")

Thanks, I’ll add it before pushing!

Ludo’.




Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Sat, 04 Jun 2022 10:11:02 GMT) Full text and rfc822 format available.

Notification sent to Ludovic Courtès <ludo <at> gnu.org>:
bug acknowledged by developer. (Sat, 04 Jun 2022 10:11:02 GMT) Full text and rfc822 format available.

Message #31 received at 55752-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Maxime Devos <maximedevos <at> telenet.be>
Cc: 55752-done <at> debbugs.gnu.org
Subject: Re: bug#55752: [PATCH 0/5] Add 'guix system edit' and 'guix home edit'
Date: Sat, 04 Jun 2022 12:10:27 +0200
Pushed as ac826aef9c1527a9237ef31b7dadd814384e057b, thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 02 Jul 2022 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 270 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.