From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: [PATCH] guix package: Export generation procedures. Date: Sat, 04 Oct 2014 21:59:06 +0400 Message-ID: <87wq8fk979.fsf_-_@gmail.com> References: <87k3719v7p.fsf@gmail.com> <87r419fa50.fsf@gnu.org> <87fvho9fqm.fsf@gmail.com> <87a97taixl.fsf@gmail.com> <87sil2rbly.fsf@gnu.org> <87tx5idn7f.fsf_-_@gmail.com> <87egwlkcy1.fsf@gnu.org> <87ppg5el2i.fsf@gmail.com> <87d2c5h4if.fsf@gnu.org> <87lhqsev1d.fsf@gmail.com> <877g2c74xh.fsf@gnu.org> <87ha1gds3w.fsf@gmail.com> <8761hsmxkl.fsf@gnu.org> <87zjf4d1mh.fsf@gmail.com> <87mwb0b3fq.fsf@gnu.org> <87ha17ctyv.fsf_-_@gmail.com> <87ppfs6gxk.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XaTbv-0005Z5-ED for guix-devel@gnu.org; Sat, 04 Oct 2014 13:59:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XaTbr-0003m4-10 for guix-devel@gnu.org; Sat, 04 Oct 2014 13:59:15 -0400 In-Reply-To: <87ppfs6gxk.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Fri, 22 Aug 2014 10:56:39 +0200") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s (2014-08-22 12:56 +0400) wrote: > Alex Kost skribis: > >> Also I would like to add support for deleting generations (to >> "guix.el"), so I think it would be good to export =E2=80=98delete-genera= tion=E2=80=99 >> from "scripts/package.scm". WDYT? > > Yes, that makes sense, one could use it from the *Guix Generation List* > buffer. What about the attached patch? Some comments and questions: - I added 'store' argument to the exported procedures, however it is used only in one particular case: when we need to create an empty profile (i.e. to call =E2=80=98link-to-empty-profile=E2=80=99). Is there= a way to avoid using 'store' argument there or is it fine to leave it like this? - I actually need only =E2=80=98delete-generations=E2=80=99 procedure for E= macs UI, but I think other procedures are also worth to be exported or not? - Perhaps there is a better place for those functions than (guix scripts package)? - (Not related to this patch, but still =E2=80=A6) Currently with =E2=80= =9Croll-back=E2=80=9D, we can only switch to the previous generation. What about adding a possibility to switch to any generation? So that we could use something like this: guix package --switch-generation=3D7 Also such functionality can be added to Emacs UI: for example pressing "C" on a generation in *Guix Generation List* will make this generation the current one. So =E2=80=98roll-back=E2=80=99 procedure may become a special case of the =E2=80=98switch-generation=E2=80=99 one. WDYT? --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-guix-package-Export-generation-procedures.patch Content-Transfer-Encoding: quoted-printable >From c50d1674d3be699198afb649a2a9932ca44c89bc Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Sat, 4 Oct 2014 20:45:35 +0400 Subject: [PATCH] guix package: Export generation procedures. * guix/scripts/package.scm: Export 'roll-back', 'delete-generation', 'delete-generations'. (link-to-empty-profile, roll-back): Add 'store' argument. (delete-generations): New procedure. (guix-package): Adjust accordingly. [delete-generation]: Move to the top level. Add 'store' and 'profile' arguments. [display-and-delete]: Move to 'delete-generation'. --- guix/scripts/package.scm | 75 +++++++++++++++++++++++++++-----------------= ---- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 7cd9516..fc9c37b 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -2,6 +2,7 @@ ;;; Copyright =C2=A9 2012, 2013, 2014 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2013 Nikita Karetnikov ;;; Copyright =C2=A9 2013 Mark H Weaver +;;; Copyright =C2=A9 2014 Alex Kost ;;; ;;; This file is part of GNU Guix. ;;; @@ -43,6 +44,9 @@ #:use-module (gnu packages guile) #:use-module ((gnu packages bootstrap) #:select (%bootstrap-guile)) #:export (specification->package+output + roll-back + delete-generation + delete-generations guix-package)) =20 (define %store @@ -80,12 +84,12 @@ return PROFILE unchanged. The goal is to treat '-p ~/.= guix-profile' as if %current-profile profile)) =20 -(define (link-to-empty-profile generation) +(define (link-to-empty-profile store generation) "Link GENERATION, a string, to the empty profile." - (let* ((drv (run-with-store (%store) + (let* ((drv (run-with-store store (profile-derivation (manifest '())))) (prof (derivation->output-path drv "out"))) - (when (not (build-derivations (%store) (list drv))) + (when (not (build-derivations store (list drv))) (leave (_ "failed to build the empty profile~%"))) =20 (switch-symlinks generation prof))) @@ -99,7 +103,7 @@ return PROFILE unchanged. The goal is to treat '-p ~/.g= uix-profile' as if number previous-number) (switch-symlinks profile previous-generation))) =20 -(define (roll-back profile) +(define (roll-back store profile) "Roll back to the previous generation of PROFILE." (let* ((number (generation-number profile)) (previous-number (previous-generation-number profile number)) @@ -112,11 +116,39 @@ return PROFILE unchanged. The goal is to treat '-p ~= /.guix-profile' as if (_ "nothing to do: already at the empty profile~%"))) ((or (zero? previous-number) ; going to emptine= ss (not (file-exists? previous-generation))) - (link-to-empty-profile previous-generation) + (link-to-empty-profile store previous-generation) (switch-to-previous-generation profile)) (else (switch-to-previous-generation profile))))) ; anything else =20 +(define (delete-generation store profile number) + "Delete generation with NUMBER from PROFILE." + (define (display-and-delete) + (let ((generation (generation-file-name profile number))) + (format #t (_ "deleting ~a~%") generation) + (delete-file generation))) + + (let* ((current-number (generation-number profile)) + (previous-number (previous-generation-number profile number)) + (previous-generation (generation-file-name profile previous-numbe= r))) + (cond ((zero? number)) ; do not delete generation 0 + ((and (=3D number current-number) + (not (file-exists? previous-generation))) + (link-to-empty-profile store previous-generation) + (switch-to-previous-generation profile) + (display-and-delete)) + ((=3D number current-number) + (roll-back store profile) + (display-and-delete)) + (else + (display-and-delete))))) + +(define (delete-generations store profile generations) + "Delete GENERATIONS from PROFILE. +GENERATIONS is a list of generation numbers." + (for-each (cut delete-generation store profile <>) + generations)) + (define* (matching-generations str #:optional (profile %current-profile) #:key (duration-relation <=3D)) "Return the list of available generations matching a pattern in STR. See @@ -680,32 +712,10 @@ more information.~%")) (define current-generation-number (generation-number profile)) =20 - (define (display-and-delete number) - (let ((generation (generation-file-name profile number))) - (unless (zero? number) - (format #t (_ "deleting ~a~%") generation) - (delete-file generation)))) - - (define (delete-generation number) - (let* ((previous-number (previous-generation-number profile number)) - (previous-generation - (generation-file-name profile previous-number))) - (cond ((zero? number)) ; do not delete generation 0 - ((and (=3D number current-generation-number) - (not (file-exists? previous-generation))) - (link-to-empty-profile previous-generation) - (switch-to-previous-generation profile) - (display-and-delete number)) - ((=3D number current-generation-number) - (roll-back profile) - (display-and-delete number)) - (else - (display-and-delete number))))) - ;; First roll back if asked to. (cond ((and (assoc-ref opts 'roll-back?) (not dry-run?)) (begin - (roll-back profile) + (roll-back (%store) profile) (process-actions (alist-delete 'roll-back? opts)))) ((and (assoc-ref opts 'delete-generations) (not dry-run?)) @@ -716,9 +726,10 @@ more information.~%")) (leave (_ "profile '~a' does not exist~%") profile)) ((string-null? pattern) - (for-each display-and-delete - (delete current-generation-number - (profile-generations profile)))) + (delete-generations + (%store) profile + (delete current-generation-number + (profile-generations profile)))) ;; Do not delete the zeroth generation. ((equal? 0 (string->number pattern)) (exit 0)) @@ -731,7 +742,7 @@ more information.~%")) (lambda (numbers) (if (null-list? numbers) (exit 1) - (for-each delete-generation numbers)))) + (delete-generations (%store) profile numbers)))) (else (leave (_ "invalid syntax: ~a~%") pattern))) --=20 2.1.2 --=-=-=--