From patchwork Fri Nov 8 14:13:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konrad Hinsen X-Patchwork-Id: 16052 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 50F04176E8; Fri, 8 Nov 2019 14:14:43 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id B4C79176B9 for ; Fri, 8 Nov 2019 14:14:42 +0000 (GMT) Received: from localhost ([::1]:55014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT529-0002WY-4S for patchwork@mira.cbaines.net; Fri, 08 Nov 2019 09:14:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35771) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT51Y-000227-Md for guix-patches@gnu.org; Fri, 08 Nov 2019 09:14:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iT51W-0007ao-Iq for guix-patches@gnu.org; Fri, 08 Nov 2019 09:14:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:36259) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iT51W-0007ac-8g for guix-patches@gnu.org; Fri, 08 Nov 2019 09:14:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iT51W-0000bh-2P for guix-patches@gnu.org; Fri, 08 Nov 2019 09:14:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#37978] [PATCH 1/2] guix: new command "guix time-machine" In-Reply-To: Resent-From: Konrad Hinsen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 08 Nov 2019 14:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37978 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 37978@debbugs.gnu.org Received: via spool by 37978-submit@debbugs.gnu.org id=B37978.15732224382317 (code B ref 37978); Fri, 08 Nov 2019 14:14:02 +0000 Received: (at 37978) by debbugs.gnu.org; 8 Nov 2019 14:13:58 +0000 Received: from localhost ([127.0.0.1]:45080 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iT51R-0000bI-Gw for submit@debbugs.gnu.org; Fri, 08 Nov 2019 09:13:58 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:45179) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iT51P-0000b1-GQ for 37978@debbugs.gnu.org; Fri, 08 Nov 2019 09:13:56 -0500 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 3934520E54 for <37978@debbugs.gnu.org>; Fri, 8 Nov 2019 09:13:50 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 08 Nov 2019 09:13:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.net; h= from:to:subject:references:date:message-id:mime-version :content-type:content-transfer-encoding; s=fm1; bh=xocAY2LR08VvX nEXTFF1YJ3RiGNs+9GZCL8RTuj4k5Y=; b=mthMIy9Iqp6og0+hhJh376O3ooi/x ntwvJww3q/wwgj00YQfaq/A3PWAU/hyHVCUyV8+Q5s7RJ+4kgevpYtUXqKhpVPqc rdcmZYtQIqj168crWj7Ig6Y+S9RYaw2cC9mQEN/W9mnmPaXfUZXvwEfots8SSoTw h7piEaBXvHokFmlebdgHCxgLBfAbtk4Mz7pkJi/Xjd3lFSIgTdxyjsuHJhCRRx7w eWrhkLjJTSN/zQ1fWimhHL63dI+z0P3dFIDkS4+bMF2TJ+yryncFiQjjtWccSdFm le5D1vL2+o8eotmZwZbZ7KbK5I6ZSOIxSk9cbfFXH4SFe3xv5cX+aJegA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=xocAY2LR08VvXnEXTFF1YJ3RiGNs+9GZCL8RTuj4k5Y=; b=sgP8q8ZA z1Qx8hwqa6poH1qkTxBy6sjeXysfzztUs+0dHg2PJU70XPV8mJOvBId13ikVLsx5 8RL1pZ0aBqDwjxqc17BE+5nLl8YXhcCo5EXkCU2pzTBiqUcXX65LVL40xPg+yoA5 4b8MmlymKR6G9SNJ9sxiMKJ5pd2uG9vElC9R/Sk14zF7EYZ0suFREhxEa7mx5GEs QoPudNK1F1LAoyulmhSixnxJS4g5nxz+Zwz04Gvv/xePnAKhRMf5yxExZ5bKNICL FdJGAtC/7jI4C7vx5mkYhFNt5ll7E8fvRgaKQGfkwLnc5ccala+1nsRR3Bz4ab0Y R1qgSv6aLFzx3g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedruddvuddgieefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufhffkfggtgfgsehtqhertd dttdejnecuhfhrohhmpefmohhnrhgrugcujfhinhhsvghnuceokhhonhhrrggurdhhihhn shgvnhesfhgrshhtmhgrihhlrdhnvghtqeenucffohhmrghinhepghhnuhdrohhrghenuc fkphepudelhedrvddvuddrtddrvddtieenucfrrghrrghmpehmrghilhhfrhhomhepkhho nhhrrggurdhhihhnshgvnhesfhgrshhtmhgrihhlrdhnvghtnecuvehluhhsthgvrhfuih iivgeptd X-ME-Proxy: Received: from KHs-MacBook.local (soleil-ext.synchrotron-soleil.fr [195.221.0.206]) by mail.messagingengine.com (Postfix) with ESMTPA id 5719A8005C for <37978@debbugs.gnu.org>; Fri, 8 Nov 2019 09:13:49 -0500 (EST) From: Konrad Hinsen References: <87y2wt3ycb.fsf@gnu.org> Date: Fri, 08 Nov 2019 15:13:48 +0100 Message-ID: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/scripts/time-machine.scm: New file. * Makefile.am: (MODULES): Add it. * guix/scripts/pull.scm: Export function channel-list. * guix/inferior.scm: New function cached-guix-filetree-for-channels. * doc/guix.texi: Document "guix time-machine" --- Makefile.am | 1 + doc/guix.texi | 59 +++++++++++++++++++- guix/inferior.scm | 38 +++++++++---- guix/scripts/pull.scm | 1 + guix/scripts/time-machine.scm | 102 ++++++++++++++++++++++++++++++++++ 5 files changed, 187 insertions(+), 14 deletions(-) create mode 100644 guix/scripts/time-machine.scm diff --git a/Makefile.am b/Makefile.am index b1f33946c5..b3f03d44c8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -278,6 +278,7 @@ MODULES = \ guix/scripts/container.scm \ guix/scripts/container/exec.scm \ guix/scripts/deploy.scm \ + guix/scripts/time-machine.scm \ guix.scm \ $(GNU_SYSTEM_MODULES) diff --git a/doc/guix.texi b/doc/guix.texi index 3b8e5935bb..3d4192cab2 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -197,6 +197,7 @@ Package Management * Invoking guix gc:: Running the garbage collector. * Invoking guix pull:: Fetching the latest Guix and distribution. * Channels:: Customizing the package collection. +* Invoking guix time-machine:: Running an older revision of Guix. * Inferiors:: Interacting with another revision of Guix. * Invoking guix describe:: Display information about your Guix revision. * Invoking guix archive:: Exporting and importing store files. @@ -2548,6 +2549,7 @@ guix install emacs-guix * Invoking guix gc:: Running the garbage collector. * Invoking guix pull:: Fetching the latest Guix and distribution. * Channels:: Customizing the package collection. +* Invoking guix time-machine:: Running an older revision of Guix. * Inferiors:: Interacting with another revision of Guix. * Invoking guix describe:: Display information about your Guix revision. * Invoking guix archive:: Exporting and importing store files. @@ -4150,7 +4152,10 @@ say, on another machine, by providing a channel specification in @end lisp The @command{guix describe --format=channels} command can even generate this -list of channels directly (@pxref{Invoking guix describe}). +list of channels directly (@pxref{Invoking guix describe}). The resulting +file can be used with the -C options of @command{guix pull} +(@pxref{Invoking guix pull}) or @command{guix time-machine} +(@pxref{Invoking guix time-machine}). At this point the two machines run the @emph{exact same Guix}, with access to the @emph{exact same packages}. The output of @command{guix build gimp} on @@ -4164,6 +4169,57 @@ artifacts with very fine grain, and to reproduce software environments at will---some sort of ``meta reproducibility'' capabilities, if you will. @xref{Inferiors}, for another way to take advantage of these super powers. +@node Invoking guix time-machine +@section Invoking @command{guix time-machine} + +@cindex @command{guix time-machine} +@cindex pinning, channels +@cindex replicating Guix +@cindex reproducibility, of Guix + +The @command{guix time-machine} command provides access to other +revisions of Guix, for example to install older versions of packages, +or to reproduce a computation in an identical environment. The revision +of Guix to be used is defined by a commit or by a channel +description file created by @command{guix describe} +(@pxref{Invoking guix describe}). + +The general syntax is: + +@example +guix time-machine @var{options}@dots{} -- @var{command} @var {arg}@dots{} +@end example + +where @var{command} and @var{arg}@dots{} are passed unmodified to the +@command{guix} command if the specified revision. The @var{options} that define +this revision are the same as for @command{guix pull} (@pxref{Invoking guix pull}): + +@table @code +@item --url=@var{url} +@itemx --commit=@var{commit} +@itemx --branch=@var{branch} +Use the @code{guix} channel from the specified @var{url}, at the +given @var{commit} (a valid Git commit ID represented as a hexadecimal +string), or @var{branch}. + +@item --channels=@var{file} +@itemx -C @var{file} +Read the list of channels from @var{file}. @var{file} must contain +Scheme code that evaluates to a list of channel objects. +@xref{Channels} for more information. +@end table + +As for @command{guix pull}, the absence of any options means that the +the latest commit on the master branch will be used. The command + +@example +guix time-machine -- build hello +@end example + +will thus build the package @code{hello} as defined in the master branch, +which is in general a newer revison of Guix than you have installed. +Time travel works in both directions! + @node Inferiors @section Inferiors @@ -10582,7 +10638,6 @@ ClientPID: 19419 ClientCommand: cuirass --cache-directory /var/cache/cuirass @dots{} @end example - @node System Configuration @chapter System Configuration diff --git a/guix/inferior.scm b/guix/inferior.scm index b8e2f21f42..cb80bb43d5 100644 --- a/guix/inferior.scm +++ b/guix/inferior.scm @@ -89,6 +89,7 @@ gexp->derivation-in-inferior %inferior-cache-directory + cached-guix-filetree-for-channels inferior-for-channels)) ;;; Commentary: @@ -635,16 +636,13 @@ failing when GUIX is too old and lacks the 'guix repl' command." (make-parameter (string-append (cache-directory #:ensure? #f) "/inferiors"))) -(define* (inferior-for-channels channels - #:key - (cache-directory (%inferior-cache-directory)) - (ttl (* 3600 24 30))) - "Return an inferior for CHANNELS, a list of channels. Use the cache at -CACHE-DIRECTORY, where entries can be reclaimed after TTL seconds. This -procedure opens a new connection to the build daemon. - -This is a convenience procedure that people may use in manifests passed to -'guix package -m', for instance." +(define* (cached-guix-filetree-for-channels channels + #:key + (cache-directory (%inferior-cache-directory)) + (ttl (* 3600 24 30))) + "Return a directory containing a guix filetree defined by CHANNELS, a list of channels. +The directory is a subdirectory of CACHE-DIRECTORY, where entries can be reclaimed after TTL seconds. +This procedure opens a new connection to the build daemon." (with-store store (let () (define instances @@ -680,7 +678,7 @@ This is a convenience procedure that people may use in manifests passed to (file-expiration-time ttl)) (if (file-exists? cached) - (open-inferior cached) + cached (run-with-store store (mlet %store-monad ((profile (channel-instances->derivation instances))) @@ -689,4 +687,20 @@ This is a convenience procedure that people may use in manifests passed to (built-derivations (list profile)) (symlink* (derivation->output-path profile) cached) (add-indirect-root* cached) - (return (open-inferior cached))))))))) + (return cached)))))))) + +(define* (inferior-for-channels channels + #:key + (cache-directory (%inferior-cache-directory)) + (ttl (* 3600 24 30))) + "Return an inferior for CHANNELS, a list of channels. Use the cache at +CACHE-DIRECTORY, where entries can be reclaimed after TTL seconds. This +procedure opens a new connection to the build daemon. + +This is a convenience procedure that people may use in manifests passed to +'guix package -m', for instance." + (define cached + (cached-guix-filetree-for-channels channels + #:cache-directory cache-directory + #:ttl ttl)) + (open-inferior cached)) diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm index 92aac6066e..d6173a6acb 100644 --- a/guix/scripts/pull.scm +++ b/guix/scripts/pull.scm @@ -56,6 +56,7 @@ #:use-module (ice-9 vlist) #:use-module (ice-9 format) #:export (display-profile-content + channel-list guix-pull)) diff --git a/guix/scripts/time-machine.scm b/guix/scripts/time-machine.scm new file mode 100644 index 0000000000..bc7ae573a3 --- /dev/null +++ b/guix/scripts/time-machine.scm @@ -0,0 +1,102 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Konrad Hinsen +;;; +;;; 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 . + +(define-module (guix scripts time-machine) + #:use-module (guix ui) + #:use-module (guix scripts) + #:use-module (guix inferior) + #:use-module (guix channels) + #:use-module ((guix scripts pull) #:select (channel-list)) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-11) + #:use-module (srfi srfi-26) + #:use-module (srfi srfi-37) + #:export (guix-time-machine)) + + +;;; +;;; Command-line options. +;;; + +(define (show-help) + (display (G_ "Usage: guix time-machine [OPTION] -- COMMAND ARGS... +Execute COMMAND ARGS... in an older version of Guix.\n")) + (display (G_ " + -C, --channels=FILE deploy the channels defined in FILE")) + (display (G_ " + --url=URL use the Git repository at URL")) + (display (G_ " + --commit=COMMIT use the specified COMMIT")) + (display (G_ " + --branch=BRANCH use the tip of the specified BRANCH")) + (display (G_ " + -h, --help display this help and exit")) + (display (G_ " + -V, --version display version information and exit")) + (newline) + (show-bug-report-information)) + +(define %options + ;; Specifications of the command-line options. + (list (option '(#\C "channels") #t #f + (lambda (opt name arg result) + (alist-cons 'channel-file arg result))) + (option '("url") #t #f + (lambda (opt name arg result) + (alist-cons 'repository-url arg + (alist-delete 'repository-url result)))) + (option '("commit") #t #f + (lambda (opt name arg result) + (alist-cons 'ref `(commit . ,arg) result))) + (option '("branch") #t #f + (lambda (opt name arg result) + (alist-cons 'ref `(branch . ,arg) result))) + (option '(#\h "help") #f #f + (lambda args + (show-help) + (exit 0))) + (option '(#\V "version") #f #f + (lambda args + (show-version-and-exit "guix time-machine"))))) + +(define (parse-args args) + "Parse the list of command line arguments ARGS." + ;; The '--' token is used to separate the command to run from the rest of + ;; the operands. + (let-values (((args command) (break (cut string=? "--" <>) args))) + (let ((opts (parse-command-line args %options '(()) #:build-options? #f))) + (match command + (() opts) + (("--") opts) + (("--" command ...) (alist-cons 'exec command opts)))))) + + +;;; +;;; Entry point. +;;; + +(define (guix-time-machine . args) + (with-error-handling + (let* ((opts (parse-args args)) + (channels (channel-list opts)) + (command-line (assoc-ref opts 'exec))) + (when command-line + (let* ((directory (cached-guix-filetree-for-channels channels)) + (executable (string-append directory "/bin/guix"))) + (apply execl (cons* executable executable command-line)))))))