unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Reproducible profiles
@ 2015-05-15  1:19 David Thompson
  2015-05-16 11:16 ` Ludovic Courtès
  2015-05-18 21:07 ` David Thompson
  0 siblings, 2 replies; 15+ messages in thread
From: David Thompson @ 2015-05-15  1:19 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 960 bytes --]

Hey folks,

Lately I've been wanting to version control the list of packages that I
install in my user profile so that I can sync it amongst many machines.
So, I took a stab at adding a new '--apply' option to 'guix package'
that reads in a package list from a Scheme file and creates a new
generation of the profile with only those packages are installed.
Here's an example configuration:

    (use-modules (gnu))
    (use-package-modules base less guile emacs admin ruby mail pumpio man)
    
    (list ruby
          coreutils
          less
          man-db
          notmuch
          guile-2.0
          emacs
          dmd
          offlineimap
          pumpa)

Below is a naive patch that does the job, but is unideal because it
doesn't do some nice things like display the diff between generations
before building.  I'm looking for some guidance to make this option mesh
better with the rest of the 'guix package' utility.  Any help is
appreciated.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-package-Add-apply-option.patch --]
[-- Type: text/x-diff, Size: 7705 bytes --]

From b5348fb46fc5b6167099ed817aad8587bfbad20a Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Thu, 14 May 2015 21:11:57 -0400
Subject: [PATCH] package: Add --apply option.

---
 guix/scripts/package.scm | 104 +++++++++++++++++++++++++++--------------------
 1 file changed, 60 insertions(+), 44 deletions(-)

diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 15f3e13..bb76fc3 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -426,6 +426,9 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
   (display (_ "
   -u, --upgrade[=REGEXP] upgrade all the installed packages matching REGEXP"))
   (display (_ "
+      --apply=FILE       create a new generation with only the packages listed
+                         in FILE installed"))
+  (display (_ "
       --do-not-upgrade[=REGEXP] do not upgrade any packages matching REGEXP"))
   (display (_ "
       --roll-back        roll back to the previous generation"))
@@ -517,6 +520,10 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
                  (lambda (opt name arg result arg-handler)
                    (values (alist-cons 'roll-back? #t result)
                            #f)))
+         (option '("apply") #t #f
+                 (lambda (opt name arg result arg-handler)
+                   (values (alist-cons 'apply (load arg) result)
+                           arg-handler)))
          (option '(#\l "list-generations") #f #t
                  (lambda (opt name arg result arg-handler)
                    (values (cons `(query list-generations ,(or arg ""))
@@ -783,6 +790,50 @@ more information.~%"))
     (define dry-run? (assoc-ref opts 'dry-run?))
     (define profile  (assoc-ref opts 'profile))
 
+    (define (build-and-use-profile manifest)
+      (let* ((bootstrap?  (assoc-ref opts 'bootstrap?)))
+
+        (when (equal? profile %current-profile)
+          (ensure-default-profile))
+
+        (let* ((prof-drv (run-with-store (%store)
+                           (profile-derivation
+                            manifest
+                            #:hooks (if bootstrap?
+                                        '()
+                                        %default-profile-hooks))))
+               (prof     (derivation->output-path prof-drv)))
+          (show-what-to-build (%store) (list prof-drv)
+                              #:use-substitutes?
+                              (assoc-ref opts 'substitutes?)
+                              #:dry-run? dry-run?)
+
+          (cond
+           (dry-run? #t)
+           ((and (file-exists? profile)
+                 (and=> (readlink* profile) (cut string=? prof <>)))
+            (format (current-error-port) (_ "nothing to be done~%")))
+           (else
+            (let* ((number (generation-number profile))
+
+                   ;; Always use NUMBER + 1 for the new profile,
+                   ;; possibly overwriting a "previous future
+                   ;; generation".
+                   (name   (generation-file-name profile
+                                                 (+ 1 number))))
+              (and (build-derivations (%store) (list prof-drv))
+                   (let* ((entries (manifest-entries manifest))
+                          (count   (length entries)))
+                     (switch-symlinks name prof)
+                     (switch-symlinks profile name)
+                     (unless (string=? profile %current-profile)
+                       (register-gc-root (%store) name))
+                     (format #t (N_ "~a package in profile~%"
+                                    "~a packages in profile~%"
+                                    count)
+                             count)
+                     (display-search-paths entries profile)))))))))
+
     ;; First roll back if asked to.
     (cond ((and (assoc-ref opts 'roll-back?)
                 (not dry-run?))
@@ -817,60 +868,25 @@ more information.~%"))
                (alist-delete 'delete-generations opts)))
              (_ #f))
             opts))
+          ((and (assoc-ref opts 'apply)
+                (not dry-run?))
+           (let* ((packages   (assoc-ref opts 'apply))
+                  (manifest   (make-manifest
+                               (map package->manifest-entry packages))))
+             (build-and-use-profile manifest)))
           (else
            (let* ((manifest    (profile-manifest profile))
                   (install     (options->installable opts manifest))
                   (remove      (options->removable opts manifest))
-                  (bootstrap?  (assoc-ref opts 'bootstrap?))
                   (transaction (manifest-transaction (install install)
                                                      (remove remove)))
                   (new         (manifest-perform-transaction
                                 manifest transaction)))
 
-             (when (equal? profile %current-profile)
-               (ensure-default-profile))
-
              (unless (and (null? install) (null? remove))
-               (let* ((prof-drv (run-with-store (%store)
-                                  (profile-derivation
-                                   new
-                                   #:hooks (if bootstrap?
-                                               '()
-                                               %default-profile-hooks))))
-                      (prof     (derivation->output-path prof-drv)))
-                 (show-manifest-transaction (%store) manifest transaction
-                                            #:dry-run? dry-run?)
-                 (show-what-to-build (%store) (list prof-drv)
-                                     #:use-substitutes?
-                                     (assoc-ref opts 'substitutes?)
-                                     #:dry-run? dry-run?)
-
-                 (cond
-                  (dry-run? #t)
-                  ((and (file-exists? profile)
-                        (and=> (readlink* profile) (cut string=? prof <>)))
-                   (format (current-error-port) (_ "nothing to be done~%")))
-                  (else
-                   (let* ((number (generation-number profile))
-
-                          ;; Always use NUMBER + 1 for the new profile,
-                          ;; possibly overwriting a "previous future
-                          ;; generation".
-                          (name   (generation-file-name profile
-                                                        (+ 1 number))))
-                     (and (build-derivations (%store) (list prof-drv))
-                          (let* ((entries (manifest-entries new))
-                                 (count   (length entries)))
-                            (switch-symlinks name prof)
-                            (switch-symlinks profile name)
-                            (unless (string=? profile %current-profile)
-                              (register-gc-root (%store) name))
-                            (format #t (N_ "~a package in profile~%"
-                                           "~a packages in profile~%"
-                                           count)
-                                    count)
-                            (display-search-paths entries
-                                                  profile))))))))))))
+               (show-manifest-transaction (%store) manifest transaction
+                                          #:dry-run? dry-run?)
+               (build-and-use-profile new))))))
 
   (define (process-query opts)
     ;; Process any query specified by OPTS.  Return #t when a query was
-- 
2.1.4


[-- Attachment #3: Type: text/plain, Size: 145 bytes --]


Thanks!

-- 
David Thompson
Web Developer - Free Software Foundation - http://fsf.org
GPG Key: 0FF1D807
Support the FSF: https://fsf.org/donate

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-05-22 12:02 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-15  1:19 Reproducible profiles David Thompson
2015-05-16 11:16 ` Ludovic Courtès
2015-05-16 11:35   ` 宋文武
2015-05-16 20:05     ` Ludovic Courtès
2015-05-17 19:27     ` David Thompson
2015-05-22 12:02       ` 宋文武
2015-05-17 19:23   ` David Thompson
2015-05-17 20:22     ` Ludovic Courtès
2015-05-17 20:51       ` David Thompson
2015-05-18 19:28         ` Syntax for package inputs Ludovic Courtès
2015-05-18 13:38   ` Reproducible profiles David Thompson
2015-05-18 19:29     ` Ludovic Courtès
2015-05-18 21:07 ` David Thompson
2015-05-20 12:36   ` Ludovic Courtès
2015-05-20 16:14     ` David Thompson

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).