From debbugs-submit-bounces@debbugs.gnu.org Wed Sep 18 04:21:15 2019 Received: (at submit) by debbugs.gnu.org; 18 Sep 2019 08:21:15 +0000 Received: from localhost ([127.0.0.1]:53540 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iAVD9-0000D1-7t for submit@debbugs.gnu.org; Wed, 18 Sep 2019 04:21:15 -0400 Received: from lists.gnu.org ([209.51.188.17]:41203) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iAVD6-0000Cs-3f for submit@debbugs.gnu.org; Wed, 18 Sep 2019 04:21:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46513) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAVD4-0003vY-46 for guix-patches@gnu.org; Wed, 18 Sep 2019 04:21:11 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: ** X-Spam-Status: No, score=2.4 required=5.0 tests=BAYES_50,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,SPOOFED_FREEMAIL,URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAVD2-0006Zs-9u for guix-patches@gnu.org; Wed, 18 Sep 2019 04:21:10 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:44069) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAVD1-0006Yj-VE for guix-patches@gnu.org; Wed, 18 Sep 2019 04:21:08 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 49E74220BA; Wed, 18 Sep 2019 04:21:06 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Wed, 18 Sep 2019 04:21:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.net; h= from:to:subject:date:message-id:mime-version:content-type; s= fm1; bh=h3pOHLlBiQSoIBA/6QYZa3ouxkEQiuijOmKAe6cheFc=; b=c69UVc55 BcBnQu3D8ZxdUA9GbINC9bNKCK1TG06fhlesVFTCKPijiCro7nDY4humRHSU3pmj +NampjC/tCHLtwiSvM5uADWZp5vw4RnsRyS7qK6/odhjjVZ+GhBtgp3P+8xzthWT W/MKaBmJ1ILdYXXbyKxtJRcOv0n3857wLqjxLWeuwSlv2EvgD65qWkwiQvTquI+c jeFHBzx2GqX7AOZAp7ByBdQGW2Y0MRSg7/6TH0DVgYwwSCMBRuicHS3jodO54RXr bgponU/l70rJwWOmmg12qas30cW2goWEl1BPSpqZpdnVLsW4YlUIGaYfCSjQn42A x6cNUWvjBfF/xw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=h3pOHLlBiQSoIBA/6QYZa3ouxkEQi uijOmKAe6cheFc=; b=xGOTulEOVtVDhdJ7SDMiV5ad4EFu/gosxgp5ooi8bzP0D U/gHTC6hvRwBeZ68eRwF9NxVn47As9yLwvGDbsbOyOSdm92Rs2lE05G4uO1gHT3g OGwpjuKrkfnnZwWK+wV2KwQTwaohNVa5U/q+FjqQbQ4gPQtJSckXoqw3eYXlbsIf MZZcvKBJWG07syklx995SKzOLUSKEGiTqQxguX0V7oNJd8+2agaaM4ypG5ANEn1x 5lDpZo/zPotir3AwFSTiinpP9ZH9OnLiKwezxkCxsVkqBX66W0BvUfPplIQn8iXm y55wHDmO+a0MYSU9EvotFvGTSjYXXNFMHXSraQQxQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudekgddtvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkfggtgesthdtredttddttd enucfhrhhomhepmfhonhhrrgguucfjihhnshgvnhcuoehkohhnrhgrugdrhhhinhhsvghn sehfrghsthhmrghilhdrnhgvtheqnecukfhppeekvddruddvfedruddtrdegudenucfrrg hrrghmpehmrghilhhfrhhomhepkhhonhhrrggurdhhihhnshgvnhesfhgrshhtmhgrihhl rdhnvghtnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from kh-MacBookPro (lfbn-idf2-1-259-41.w82-123.abo.wanadoo.fr [82.123.10.41]) by mail.messagingengine.com (Postfix) with ESMTPA id A4E17D60062; Wed, 18 Sep 2019 04:21:05 -0400 (EDT) From: Konrad Hinsen To: guix-patches@gnu.org Subject: [PATCH] scripts: pull: Add options for generation management Date: Wed, 18 Sep 2019 09:52:18 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.29 X-Spam-Score: 0.6 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.4 (/) * guix/scripts/pull.scm (%options) Add --roll-back, --switch-generation, --delete-generations (process-generation-change): New function (guix-pull): Execute generation management operations * doc/guix.texi: Document the generation management operations --- doc/guix.texi | 47 +++++++++++++++++++++++++++++++++++++++++-- guix/scripts/pull.scm | 41 ++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 55935b3794..27b58b37e5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -3673,11 +3673,20 @@ Generation 3 Jun 13 2018 23:31:07 (current) @xref{Invoking guix describe, @command{guix describe}}, for other ways to describe the current status of Guix. -This @code{~/.config/guix/current} profile works like any other profile -created by @command{guix package} (@pxref{Invoking guix package}). That +This @code{~/.config/guix/current} profile works exactly like the profiles +created by @command{guix package} (@pxref{Invoking guix package}). That is, you can list generations, roll back to the previous generation---i.e., the previous Guix---and so on: +@example +$ guix pull --roll-back +switched from generation 3 to 2 +$ guix pull --delete-generations=1 +deleting /var/guix/profiles/per-user/charlie/current-guix-1-link +@end example + +You can also use @command{guix package} (@pxref{Invoking guix package}) +to manage the profile by naming it explicitly: @example $ guix package -p ~/.config/guix/current --roll-back switched from generation 3 to 2 @@ -3724,6 +3733,40 @@ is provided, the subset of generations that match @var{pattern}. The syntax of @var{pattern} is the same as with @code{guix package --list-generations} (@pxref{Invoking guix package}). +@item --roll-back +@cindex rolling back +@cindex undoing transactions +@cindex transactions, undoing +Roll back to the previous @dfn{generation} of @file{~/.config/guix/current}---i.e., +undo the last transaction. + +@item --switch-generation=@var{pattern} +@itemx -S @var{pattern} +@cindex generations +Switch to a particular generation defined by @var{pattern}. + +@var{pattern} may be either a generation number or a number prefixed +with ``+'' or ``-''. The latter means: move forward/backward by a +specified number of generations. For example, if you want to return to +the latest generation after @code{--roll-back}, use +@code{--switch-generation=+1}. + +@item --delete-generations[=@var{pattern}] +@itemx -d [@var{pattern}] +When @var{pattern} is omitted, delete all generations except the current +one. + +This command accepts the same patterns as @option{--list-generations}. +When @var{pattern} is specified, delete the matching generations. When +@var{pattern} specifies a duration, generations @emph{older} than the +specified duration match. For instance, @code{--delete-generations=1m} +deletes generations that are more than one month old. + +If the current generation matches, it is @emph{not} deleted. + +Note that deleting generations prevents rolling back to them. +Consequently, this command must be used with care. + @xref{Invoking guix describe}, for a way to display information about the current generation only. diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm index 54bbaddf30..a111f3616d 100644 --- a/guix/scripts/pull.scm +++ b/guix/scripts/pull.scm @@ -38,7 +38,8 @@ #:use-module (guix git) #:use-module (git) #:use-module (gnu packages) - #:use-module ((guix scripts package) #:select (build-and-use-profile)) + #:use-module ((guix scripts package) #:select (build-and-use-profile + delete-matching-generations)) #:use-module ((gnu packages base) #:select (canonical-package)) #:use-module (gnu packages guile) #:use-module ((gnu packages bootstrap) @@ -91,6 +92,14 @@ Download and deploy the latest version of Guix.\n")) (display (G_ " -l, --list-generations[=PATTERN] list generations matching PATTERN")) + (display (G_ " + --roll-back roll back to the previous generation")) + (display (G_ " + -d, --delete-generations[=PATTERN] + delete generations matching PATTERN")) + (display (G_ " + -S, --switch-generation=PATTERN + switch to a generation matching PATTERN")) (display (G_ " -p, --profile=PROFILE use PROFILE instead of ~/.config/guix/current")) (display (G_ " @@ -120,6 +129,18 @@ Download and deploy the latest version of Guix.\n")) (lambda (opt name arg result) (cons `(query list-generations ,arg) result))) + (option '("roll-back") #f #f + (lambda (opt name arg result) + (cons '(generation roll-back) + result))) + (option '(#\S "switch-generation") #t #f + (lambda (opt name arg result) + (cons `(generation switch ,arg) + result))) + (option '(#\d "delete-generations") #f #t + (lambda (opt name arg result) + (cons `(generation delete ,arg) + result))) (option '(#\N "news") #f #f (lambda (opt name arg result) (cons '(query display-news) result))) @@ -498,6 +519,22 @@ list of package changes."))))) (display-profile-news profile #:current-is-newer? #t)))) +(define (process-generation-change opts profile) + "Process a request to change the current generation (roll-back, switch, delete)." + (unless (assoc-ref opts 'dry-run?) + (match (assoc-ref opts 'generation) + (('roll-back) + (with-store store + (roll-back* store profile))) + (('switch pattern) + (let ((number (relative-generation-spec->number profile pattern))) + (if number + (switch-to-generation* profile number) + (leave (G_ "cannot switch to generation '~a'~%") pattern)))) + (('delete pattern) + (with-store store + (delete-matching-generations store profile pattern)))))) + (define (channel-list opts) "Return the list of channels to use. If OPTS specify a channel file, channels are read from there; otherwise, if ~/.config/guix/channels.scm @@ -565,6 +602,8 @@ Use '~/.config/guix/channels.scm' instead.")) (profile (or (assoc-ref opts 'profile) %current-profile))) (cond ((assoc-ref opts 'query) (process-query opts profile)) + ((assoc-ref opts 'generation) + (process-generation-change opts profile)) (else (with-store store (ensure-default-profile) -- 2.22.1