unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#30480] [PATCH] environment: Add --manifest option.
@ 2018-02-16  2:12 Thompson, David
  2018-02-16  5:58 ` Jan Nieuwenhuizen
  2018-02-19 21:21 ` Ludovic Courtès
  0 siblings, 2 replies; 8+ messages in thread
From: Thompson, David @ 2018-02-16  2:12 UTC (permalink / raw)
  To: 30480

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

In my lurkings I've seen people wondering why `guix environment`
doesn't work with manifests. The answer is simply: I never thought to
add it. This patch fixes that. The implementation is kind of
interesting and might seem a little silly to people that know how
manifests work.  In order to support manifests with minimal code and
make --manifest compose with other options I simply decompile the
manifest back into a list of package/output tuples.  That means in the
case of `guix environment --manifest=foo.scm` the manifest is created,
decompiled, and a new manifest created from that.  Seems redundant!
The advantage is that since --manifest composes with all the other
ways to specify packages we can do absolutely bonkers things like
`guix environment guile --ad-hoc ruby --manifest=foo.scm
--manifest=bar.scm --load=frob.scm --expression='(@ (gnu packages
python) python)'`.  More realistically you'd use it to throw in an
extra package or two with --ad-hoc.

Anyway, hope y'all like it.

- Dave

[-- Attachment #2: 0001-environment-Add-manifest-option.patch --]
[-- Type: text/x-patch, Size: 3986 bytes --]

From 47e0cf3bef26791c72222175899790a46c49af45 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Thu, 15 Feb 2018 20:54:28 -0500
Subject: [PATCH] environment: Add --manifest option.

* guix/scripts/environment.scm (show-help, %options): Add -m/--manifest.
(options/resolve-packages): Handle manifests.
* doc/guix.texi (Invoking guix environment): Document it.
---
 doc/guix.texi                |  9 +++++++++
 guix/scripts/environment.scm | 22 +++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 7ed39ff13..16a352c8b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -7231,6 +7231,15 @@ As an example, @var{file} might contain a definition like this
 @verbatiminclude environment-gdb.scm
 @end example
 
+@item --manifest=@var{file}
+@itemx -m @var{file}
+Create an environment for the packages contained in the manifest object
+returned by the Scheme code in @var{file}.
+
+This is similar to the same-named option in @command{guix package}
+(@pxref{profile-manifest, @option{--manifest}}) and uses the same
+manifest files.
+
 @item --ad-hoc
 Include all specified packages in the resulting environment, as if an
 @i{ad hoc} package were defined with them as inputs.  This option is
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index d2568e6a7..67da6fc3b 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2014, 2015 David Thompson <davet@gnu.org>
+;;; Copyright © 2014, 2015, 2018 David Thompson <davet@gnu.org>
 ;;; Copyright © 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -141,6 +141,8 @@ COMMAND or an interactive shell in that environment.\n"))
   (display (G_ "
   -l, --load=FILE        create environment for the package that the code within
                          FILE evaluates to"))
+  (display (G_ "
+  -m, --manifest=FILE    create environment with the manifest from FILE"))
   (display (G_ "
       --ad-hoc           include all specified packages in the environment instead
                          of only their inputs"))
@@ -220,6 +222,11 @@ COMMAND or an interactive shell in that environment.\n"))
                    (alist-cons 'expression
                                (tag-package-arg result arg)
                                result)))
+         (option '(#\m "manifest") #t #f
+                 (lambda (opt name arg result)
+                   (alist-cons 'manifest
+                               arg
+                               result)))
          (option '("ad-hoc") #f #f
                  (lambda (opt name arg result)
                    (alist-cons 'ad-hoc? #t result)))
@@ -286,6 +293,16 @@ packages."
       (((? package-or-package+output?) ...) ; many packages
        (map (cut package->output <> mode) packages))))
 
+  (define (manifest->outputs manifest)
+    (map (lambda (entry)
+           (cons 'ad-hoc-package ; manifests are implicitly ad-hoc
+                 (if (package? (manifest-entry-item entry))
+                     (list (manifest-entry-item entry)
+                           (manifest-entry-output entry))
+                     ;; Direct store paths have no output.
+                     (list (manifest-entry-item entry)))))
+         (manifest-entries manifest)))
+
   (compact
    (append-map (match-lambda
                  (('package mode (? string? spec))
@@ -299,6 +316,9 @@ packages."
                   ;; Add all the outputs of the package defined in FILE.
                   (let ((module (make-user-module '())))
                     (packages->outputs (load* file module) mode)))
+                 (('manifest . file)
+                  (let ((module (make-user-module '())))
+                    (manifest->outputs (load* file module))))
                  (_ '(#f)))
                opts)))
 
-- 
2.16.1


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

end of thread, other threads:[~2018-02-22  9:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-16  2:12 [bug#30480] [PATCH] environment: Add --manifest option Thompson, David
2018-02-16  5:58 ` Jan Nieuwenhuizen
2018-02-19 21:21 ` Ludovic Courtès
2018-02-21  3:25   ` Thompson, David
2018-02-21 22:10     ` Ludovic Courtès
2018-02-22  3:17       ` Thompson, David
2018-02-22  6:47         ` bug#30480: " Leo Famulari
2018-02-22  9:15         ` [bug#30480] " Andreas Enge

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).