Subject: [bug#72928] [PATCH v2] time-machine: Print profile path if no command is given.

From: Tomas Volf <[email-masked]>
Date: Sun, 6 Oct 2024 15:23:07 +0200

Instead of warning, print the profile path of the cached-channel-instance.

* guix/scripts/time-machine.scm (guix-time-machine)[not command-line]: Print
the profile directory.
(show-help): Adjust usage message.
* doc/guix.texi (Invoking guix time-machine): Document it.

Change-Id: Id2c1ded514e6c5af45af9008ad1ef91beb509177
---
Adjust usage message and document the new behavior.

 doc/guix.texi                 |  5 ++++
 guix/scripts/time-machine.scm | 44 ++++++++++++++++++-----------------
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 52e36e4354..72871316c8 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -4762,6 +4762,11 @@ Invoking guix time-machine
 their dependencies, and these are controlled by the standard build
 options (@pxref{Common Build Options}).

+If @command{guix time-machine} is executed without any command, it
+prints the path to the guix profile that would be used to execute the
+command.  This is sometimes useful if you need to get store path for the
+profile, e.g. when you want to @command{guix copy} it.
+
 @node Inferiors
 @section Inferiors

diff --git a/guix/scripts/time-machine.scm b/guix/scripts/time-machine.scm
index d9ce85df84..21145239d4 100644
--- a/guix/scripts/time-machine.scm
+++ b/guix/scripts/time-machine.scm
@@ -52,8 +52,10 @@ (define-module (guix scripts time-machine)
 ;;;

 (define (show-help)
-  (display (G_ "Usage: guix time-machine [OPTION] -- COMMAND ARGS...
-Execute COMMAND ARGS... in an older version of Guix.\n"))
+  (display (G_ "Usage: guix time-machine [OPTION] [-- COMMAND ARGS...]
+Execute COMMAND ARGS... in an older version of Guix.
+
+If COMMAND is not provided, print path to the time-machine profile.\n"))
   (display (G_ "
   -C, --channels=FILE    deploy the channels defined in FILE"))
   (display (G_ "
@@ -179,22 +181,22 @@ (define-command (guix-time-machine . args)
             (ref          (assoc-ref opts 'ref))
             (substitutes?  (assoc-ref opts 'substitutes?))
             (authenticate? (assoc-ref opts 'authenticate-channels?)))
-       (if command-line
-           (let* ((directory
-                   (with-store store
-                     (with-status-verbosity (assoc-ref opts 'verbosity)
-                       (with-build-handler (build-notifier #:use-substitutes?
-                                                           substitutes?
-                                                           #:verbosity
-                                                           (assoc-ref opts 'verbosity)
-                                                           #:dry-run? #f)
-                         (set-build-options-from-command-line store opts)
-                         (cached-channel-instance store channels
-                                                  #:authenticate? authenticate?
-                                                  #:reference-channels
-                                                  %reference-channels
-                                                  #:validate-channels
-                                                  validate-guix-channel)))))
-                  (executable (string-append directory "/bin/guix")))
-             (apply execl (cons* executable executable command-line)))
-           (warning (G_ "no command specified; nothing to do~%")))))))
+       (let* ((directory
+               (with-store store
+                 (with-status-verbosity (assoc-ref opts 'verbosity)
+                   (with-build-handler (build-notifier #:use-substitutes?
+                                                       substitutes?
+                                                       #:verbosity
+                                                       (assoc-ref opts 'verbosity)
+                                                       #:dry-run? #f)
+                     (set-build-options-from-command-line store opts)
+                     (cached-channel-instance store channels
+                                              #:authenticate? authenticate?
+                                              #:reference-channels
+                                              %reference-channels
+                                              #:validate-channels
+                                              validate-guix-channel)))))
+              (executable (string-append directory "/bin/guix")))
+         (if command-line
+             (apply execl (cons* executable executable command-line))
+             (format #t "~a\n" directory)))))))

base-commit: a873666d3bf716a5ae29275efaa000eaf6d1e2a8
--
2.46.0