From patchwork Tue Aug 15 19:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 52855 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 155C927BBEA; Tue, 15 Aug 2023 20:46:37 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 82B8427BBE9 for ; Tue, 15 Aug 2023 20:46:36 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qVzzV-0002R5-QT; Tue, 15 Aug 2023 15:46:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qVzzQ-0002Pw-Gz for guix-patches@gnu.org; Tue, 15 Aug 2023 15:46:05 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qVzzP-0007Wr-FK; Tue, 15 Aug 2023 15:46:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qVzzN-0001mJ-VL; Tue, 15 Aug 2023 15:46:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#64746] [PATCH v2 2/3] pull: Tag commit argument with 'tag-or-commit. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 15 Aug 2023 19:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64746 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 64746@debbugs.gnu.org Cc: Maxim Cournoyer , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 64746-submit@debbugs.gnu.org id=B64746.16921287156766 (code B ref 64746); Tue, 15 Aug 2023 19:46:01 +0000 Received: (at 64746) by debbugs.gnu.org; 15 Aug 2023 19:45:15 +0000 Received: from localhost ([127.0.0.1]:36663 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVzyc-0001l2-RB for submit@debbugs.gnu.org; Tue, 15 Aug 2023 15:45:15 -0400 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]:53425) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVzyX-0001kT-Vh for 64746@debbugs.gnu.org; Tue, 15 Aug 2023 15:45:11 -0400 Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-403e7472b28so34775011cf.2 for <64746@debbugs.gnu.org>; Tue, 15 Aug 2023 12:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692128704; x=1692733504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B8hGdU4OELa28DbMUXTnepI6us/G3Bq8sQl7rzDGixY=; b=LSfcwxejybTLHs3fO+eVtO8eAVQzOvW40TX3Yon/fwzETpzDBJdvha3jLfa8FYwopB KLtj40AUexXNz6g4H/udVKqNqoxtC/IVxEzQK8tzKadJuZu5uhhuGBOUYmgubsnEHBP4 q/o++gL2E32t3zaj1KHrqlOqA0Px7J3+NXI7kLKJhpu7aI67nOgmWi3Y72FcB+BHFnpd 6lv2LUvQ2xDVVKiefeyfkqUzI/XCmoqAq1Y/TbIMlmygqgoQ8/kgqwvZ9RxOjK6YdxKy I8Si4oqY5gg1VKSZjqe9ptvchLd4/dwi/rnQr4+U3l0yI9DH8VQbnmMTj9V5CyAnJZb9 iyrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692128704; x=1692733504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B8hGdU4OELa28DbMUXTnepI6us/G3Bq8sQl7rzDGixY=; b=Vu6yuXY2NXwN+B9dX20BHgJQOdoZqhxTTTzXc9lIyVpG4dwS+pIXV1wwXZq3U+RmqK Mv5PFE+x17v2xjMhLQl25U+HqMpOhrC9ta/I0rsLPiQs5g70u7dQL3/Rgvtkje+fyAAB QAqHp3+loSaqhm1w7zMvuNoK56x/+Pna6dy84BFm5bDoaBHVyjke5jLKt3InvC0afROA TmUx+qtvR0UwlQaH4v1XcT1nI/tQFthcR6AmpP1AmkW7EJXoP2OH8gpLQVmmcn1IlSTM Ju79nRlvGtg8lMpjJ/E7j+ISiN1nZcD/niZhtGAq8Veoj/WjGxBlfpRNV5StDSe8f7za zBkQ== X-Gm-Message-State: AOJu0YyHUEjrY9JlF7OM1WH2bq/LaxnmnefE7ylqUCf4bH4hxbNFq14Z zhIdpM2AMtPJia0gXTO8AA834Vn5hEScUQ== X-Google-Smtp-Source: AGHT+IH9hSgIttU+hjCcnp32bBE9BaF0+xKwekR4glL+epVaPXiH1FHFpieUpKIjBhE/YJDmuSj21w== X-Received: by 2002:a05:622a:1482:b0:40f:ecef:cab3 with SMTP id t2-20020a05622a148200b0040fecefcab3mr17560126qtx.33.1692128704313; Tue, 15 Aug 2023 12:45:04 -0700 (PDT) Received: from localhost.localdomain (dsl-148-65.b2b2c.ca. [66.158.148.65]) by smtp.gmail.com with ESMTPSA id h11-20020ac8744b000000b00403ad6ec2e8sm3953031qtr.26.2023.08.15.12.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 12:45:03 -0700 (PDT) From: Maxim Cournoyer Date: Tue, 15 Aug 2023 15:44:08 -0400 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: <340786ccd3d40c0c8906028dc20af5ae9b0aa6b9.1692128648.git.maxim.cournoyer@gmail.com> References: <340786ccd3d40c0c8906028dc20af5ae9b0aa6b9.1692128648.git.maxim.cournoyer@gmail.com> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches For compatibility with (guix git) procedures. * guix/scripts/pull.scm (channel-list): Also accept tag-or-commit tagged refspec. --- New commit. guix/scripts/pull.scm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm index ecd264d3fa..9b78d4b5ca 100644 --- a/guix/scripts/pull.scm +++ b/guix/scripts/pull.scm @@ -166,7 +166,7 @@ (define %options (alist-delete 'repository-url result)))) (option '("commit") #t #f (lambda (opt name arg result) - (alist-cons 'ref `(commit . ,arg) result))) + (alist-cons 'ref `(tag-or-commit . ,arg) result))) (option '("branch") #t #f (lambda (opt name arg result) (alist-cons 'ref `(branch . ,arg) result))) @@ -774,7 +774,8 @@ (define (channel-list opts) (if (guix-channel? c) (let ((url (or url (channel-url c)))) (match ref - (('commit . commit) + ((or ('commit . commit) + ('tag-or-commit . commit)) (channel (inherit c) (url url) (commit commit) (branch #f))) (('branch . branch) From patchwork Tue Aug 15 19:44:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 52854 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 1AD6D27BBE9; Tue, 15 Aug 2023 20:46:33 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3518327BBE2 for ; Tue, 15 Aug 2023 20:46:25 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qVzzU-0002Qv-5h; Tue, 15 Aug 2023 15:46:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qVzzS-0002QD-1U for guix-patches@gnu.org; Tue, 15 Aug 2023 15:46:06 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qVzzR-0007X8-6d; Tue, 15 Aug 2023 15:46:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qVzzO-0001mR-CO; Tue, 15 Aug 2023 15:46:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#64746] [PATCH v2 3/3] scripts: time-machine: Error when attempting to visit too old commits. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 15 Aug 2023 19:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64746 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 64746@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer , Simon Tournier , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 64746-submit@debbugs.gnu.org id=B64746.16921287166775 (code B ref 64746); Tue, 15 Aug 2023 19:46:02 +0000 Received: (at 64746) by debbugs.gnu.org; 15 Aug 2023 19:45:16 +0000 Received: from localhost ([127.0.0.1]:36665 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVzyd-0001l5-77 for submit@debbugs.gnu.org; Tue, 15 Aug 2023 15:45:16 -0400 Received: from mail-qk1-x730.google.com ([2607:f8b0:4864:20::730]:44389) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qVzya-0001kW-8E for 64746@debbugs.gnu.org; Tue, 15 Aug 2023 15:45:13 -0400 Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-76d535567afso164127085a.1 for <64746@debbugs.gnu.org>; Tue, 15 Aug 2023 12:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692128706; x=1692733506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ke0p/pvdx3IQKPSccLx/QTYEfddANKEDXSD9F1VXXlQ=; b=E+EwBH+J25R+3EOYCh0Zt9GCBdHcvjH0dkk9ZB+DMy9j8SXZjLMIibPqFafeYG8Qc5 wCdN3UAVkn1RQbXKr6iJgqUJt9a9f51I/frNkiAb907mhyXoMG6KHfOOiwT3UZpzIDWe oymIdcM1TIvcQVd/exsBphhvXjkqxENKwh/0bWd91oFRXJ6MDKIIA7F4vuCdsAAKpLRV XuABP4BljQh6WoVmAGXtGs36ebi62/sXoMu2mqW0rFUAgdrmKjWWgvtaIilYUi7WFX4K yayTbgKbMlAoObpLnhy3ggL0HdOqblSjBAxUsGXqb8IDkm/tdSPVDprIf8sjQiF+C1uI NuNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692128706; x=1692733506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ke0p/pvdx3IQKPSccLx/QTYEfddANKEDXSD9F1VXXlQ=; b=YVUaL7BcwX5Ggd5Va75an56aRAUShe/X73c8UnQ07/YFaHnpw1f9FL+/UAHQoqeTnC 3Qf9oAPrTEX34Q7GV058rJVwQTMLmxIR+gozR0boQdFcpmDT5jrrUxEhUzfGExodFcix /uF3bmFQqnBMdTd6dd4A1omkXTbozFAEOksK7WtsttZA2QLi0NpkAPPr4MJIKLPynp0V OsbGXiCtYb1lW4oBVSwL/RQMDKLWRXsjc4MaFWCvWkXoApNEBxThm7rZnXKOmP0OEjkV yDXfGQVOMRWdps8We+Vcv1UOmd0kqyKyOx0Ah78lKQzU9u0SqZZPISpV2R6iWlmivW+s oxzA== X-Gm-Message-State: AOJu0Yxt2ksVreLPCIzcXosK8SAIteO6uvbNG5LbY/1riBPUfTw4K0eF 22xnNYz3Ujoq6w+cHOeeFplF0P22n3aTAQ== X-Google-Smtp-Source: AGHT+IGyntlK8oGlCmNYAaPGP5y4PEu/n31haEms+4+X7lIeN4OcToHvPExbTI43xk06ltmUHNo5xg== X-Received: by 2002:a05:620a:3710:b0:76c:c563:cd7e with SMTP id de16-20020a05620a371000b0076cc563cd7emr18186793qkb.61.1692128706357; Tue, 15 Aug 2023 12:45:06 -0700 (PDT) Received: from localhost.localdomain (dsl-148-65.b2b2c.ca. [66.158.148.65]) by smtp.gmail.com with ESMTPSA id h11-20020ac8744b000000b00403ad6ec2e8sm3953031qtr.26.2023.08.15.12.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 12:45:06 -0700 (PDT) From: Maxim Cournoyer Date: Tue, 15 Aug 2023 15:44:09 -0400 Message-ID: <7ce3ce800ab5dde1cdaaf272a54738be6256c1b3.1692128648.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <340786ccd3d40c0c8906028dc20af5ae9b0aa6b9.1692128648.git.maxim.cournoyer@gmail.com> References: <340786ccd3d40c0c8906028dc20af5ae9b0aa6b9.1692128648.git.maxim.cournoyer@gmail.com> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * doc/guix.texi (Invoking guix time-machine): Document limitation. * guix/inferior.scm (cached-channel-instance): New VALIDATE-CHANNELS argument. Use it to validate channels when there are no cache hit. * guix/scripts/time-machine.scm (%options): Tag the given reference with 'tag-or-commit instead of 'commit. (%oldest-possible-commit): New variable. (guix-time-machine) : New nested procedure. Pass it to the 'cached-channel-instance' call. * tests/guix-time-machine.sh: New test. * Makefile.am (SH_TESTS): Register it. Suggested-by: Simon Tournier Reviewed-by: Ludovic Courtès --- Changes in v2: - Test it - Delay validation work to inside cached-channel-instance, when there's no cache hit - Expound doc to mention possible problems and possible workarounds Makefile.am | 1 + doc/guix.texi | 14 +++++++++ guix/inferior.scm | 57 ++++++++++++++++++++--------------- guix/scripts/time-machine.scm | 38 +++++++++++++++++++++-- tests/guix-time-machine.sh | 28 +++++++++++++++++ 5 files changed, 110 insertions(+), 28 deletions(-) create mode 100644 tests/guix-time-machine.sh diff --git a/Makefile.am b/Makefile.am index 5ffcb6a12d..4228c07803 100644 --- a/Makefile.am +++ b/Makefile.am @@ -615,6 +615,7 @@ SH_TESTS = \ tests/guix-refresh.sh \ tests/guix-shell.sh \ tests/guix-shell-export-manifest.sh \ + tests/guix-time-machine.sh \ tests/guix-graph.sh \ tests/guix-describe.sh \ tests/guix-repl.sh \ diff --git a/doc/guix.texi b/doc/guix.texi index b50feed4c4..a3754b7019 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -5060,6 +5060,20 @@ Invoking guix time-machine large number of packages; the result is cached though and subsequent commands targeting the same commit are almost instantaneous. +Due to @command{guix time-machine} relying on the ``inferiors'' +mechanism (@pxref{Inferiors}), the oldest commit it can travel to is +commit @samp{6298c3ff} (``v1.0.0''), dated May 1@sup{st}, 2019, which is +the first release that included the inferiors mechanism. An error is +returned when attempting to navigate to older commits. Note that +although it should technically be possible to travel to such an old +commit, the ease to do so will largely depend on the availability of +binary substitutes. When traveling to a distant past, some packages may +not easily build from source anymore. One such example are old versions +of Python 2 which had time bombs in its test suite, in the form of +expiring SSL certificates. This particular problem can be worked around +by setting the hardware clock to a value in the past before attempting +the build. + @quotation Note The history of Guix is immutable and @command{guix time-machine} provides the exact same software as they are in a specific Guix diff --git a/guix/inferior.scm b/guix/inferior.scm index 5dfd30a6c8..fca6fb4b22 100644 --- a/guix/inferior.scm +++ b/guix/inferior.scm @@ -871,11 +871,15 @@ (define* (cached-channel-instance store #:key (authenticate? #t) (cache-directory (%inferior-cache-directory)) - (ttl (* 3600 24 30))) + (ttl (* 3600 24 30)) + validate-channels) "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. AUTHENTICATE? -determines whether CHANNELS are authenticated." +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. AUTHENTICATE? determines whether CHANNELS are authenticated. +VALIDATE-CHANNELS, if specified, must be a one argument procedure accepting a +list of channels that can be used to validate the channels; it should raise an +exception in case of problems." (define commits ;; Since computing the instances of CHANNELS is I/O-intensive, use a ;; cheaper way to get the commit list of CHANNELS. This limits overhead @@ -923,27 +927,30 @@ (define* (cached-channel-instance store (if (file-exists? cached) cached - (run-with-store store - (mlet* %store-monad ((instances - -> (latest-channel-instances store channels - #:authenticate? - authenticate?)) - (profile - (channel-instances->derivation instances))) - (mbegin %store-monad - ;; It's up to the caller to install a build handler to report - ;; what's going to be built. - (built-derivations (list profile)) - - ;; Cache if and only if AUTHENTICATE? is true. - (if authenticate? - (mbegin %store-monad - (symlink* (derivation->output-path profile) cached) - (add-indirect-root* cached) - (return cached)) - (mbegin %store-monad - (add-temp-root* (derivation->output-path profile)) - (return (derivation->output-path profile))))))))) + (begin + (when (procedure? validate-channels) + (validate-channels channels)) + (run-with-store store + (mlet* %store-monad ((instances + -> (latest-channel-instances store channels + #:authenticate? + authenticate?)) + (profile + (channel-instances->derivation instances))) + (mbegin %store-monad + ;; It's up to the caller to install a build handler to report + ;; what's going to be built. + (built-derivations (list profile)) + + ;; Cache if and only if AUTHENTICATE? is true. + (if authenticate? + (mbegin %store-monad + (symlink* (derivation->output-path profile) cached) + (add-indirect-root* cached) + (return cached)) + (mbegin %store-monad + (add-temp-root* (derivation->output-path profile)) + (return (derivation->output-path profile)))))))))) (define* (inferior-for-channels channels #:key diff --git a/guix/scripts/time-machine.scm b/guix/scripts/time-machine.scm index d7c71ef705..e4fe511382 100644 --- a/guix/scripts/time-machine.scm +++ b/guix/scripts/time-machine.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2019 Konrad Hinsen ;;; Copyright © 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2021 Simon Tournier +;;; Copyright © 2023 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -19,13 +20,15 @@ ;;; along with GNU Guix. If not, see . (define-module (guix scripts time-machine) + #:use-module (guix channels) + #:use-module (guix diagnostics) #:use-module (guix ui) #:use-module (guix scripts) #:use-module (guix inferior) #:use-module (guix store) #:use-module (guix status) #:use-module ((guix git) - #:select (with-git-error-handling)) + #:select (update-cached-checkout with-git-error-handling)) #:use-module ((guix utils) #:select (%current-system)) #:use-module ((guix scripts pull) @@ -38,9 +41,17 @@ (define-module (guix scripts time-machine) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-34) #:use-module (srfi srfi-37) + #:use-module (srfi srfi-71) #:export (guix-time-machine)) +;;; The required inferiors mechanism relied on by 'guix time-machine' was +;;; firmed up in v1.0.0; it is the oldest, safest commit that can be travelled +;;; to. +(define %oldest-possible-commit + "6298c3ffd9654d3231a6f25390b056483e8f407c") ;v1.0.0 + ;;; ;;; Command-line options. @@ -81,7 +92,7 @@ (define %options (alist-delete 'repository-url result)))) (option '("commit") #t #f (lambda (opt name arg result) - (alist-cons 'ref `(commit . ,arg) result))) + (alist-cons 'ref `(tag-or-commit . ,arg) result))) (option '("branch") #t #f (lambda (opt name arg result) (alist-cons 'ref `(branch . ,arg) result))) @@ -140,8 +151,27 @@ (define-command (guix-time-machine . args) (let* ((opts (parse-args args)) (channels (channel-list opts)) (command-line (assoc-ref opts 'exec)) + (ref (assoc-ref opts 'ref)) (substitutes? (assoc-ref opts 'substitutes?)) (authenticate? (assoc-ref opts 'authenticate-channels?))) + + (define (validate-guix-channel channels) + "Finds the Guix channel among CHANNELS, and validates that REF as +captured from the closure, a git reference specification such as a commit hash +or tag associated to CHANNEL, is valid and new enough to satisfy the 'guix +time-machine' requirements. A `formatted-message' condition is raised +otherwise." + (let* ((guix-channel (find guix-channel? channels)) + (checkout commit relation (update-cached-checkout + (channel-url guix-channel) + #:ref (or ref '()) + #:starting-commit + %oldest-possible-commit))) + (unless (memq relation '(ancestor self)) + (raise (formatted-message + (G_ "cannot travel past commit `~a' from May 1st, 2019") + (string-take %oldest-possible-commit 12)))))) + (when command-line (let* ((directory (with-store store @@ -153,6 +183,8 @@ (define-command (guix-time-machine . args) #:dry-run? #f) (set-build-options-from-command-line store opts) (cached-channel-instance store channels - #:authenticate? authenticate?))))) + #:authenticate? authenticate? + #:validate-channels + validate-guix-channel))))) (executable (string-append directory "/bin/guix"))) (apply execl (cons* executable executable command-line)))))))) diff --git a/tests/guix-time-machine.sh b/tests/guix-time-machine.sh new file mode 100644 index 0000000000..8b62ef75ea --- /dev/null +++ b/tests/guix-time-machine.sh @@ -0,0 +1,28 @@ +# GNU Guix --- Functional package management for GNU +# Copyright © 2023 Maxim Cournoyer +# +# 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 . + +# +# Test the 'guix time-machine' command-line utility. +# + +guix time-machine --version + +# Visiting a commit older than v1.0.0 fails. +! guix time-machine --commit=v0.15.0 + +exit 0