[PATCH] environment: Add --manifest option.

  • Done
  • quality assurance status badge
Details
5 participants
  • Andreas Enge
  • Thompson, David
  • Jan Nieuwenhuizen
  • Leo Famulari
  • Ludovic Courtès
Owner
unassigned
Submitted by
Thompson, David
Severity
normal

Debbugs page

Thompson, David wrote 7 years ago
(address . guix-patches@gnu.org)
CAJ=Rwfby6A7KzDUf+a__fg2thAtte+4nXq-5b4vyADmH7NqoVg@mail.gmail.com
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
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(-)

Toggle diff (81 lines)
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
Jan Nieuwenhuizen wrote 7 years ago
(name . Thompson, David)(address . dthompson2@worcester.edu)(address . 30480@debbugs.gnu.org)
87k1vd1nmr.fsf@gnu.org
Thompson, David writes:

Toggle quote (4 lines)
> 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.

Ah :-) I enjoyed reading your rationale and the elegant patch.

Toggle quote (2 lines)
> Anyway, hope y'all like it.

Thank you, beautiful!
janneke

--
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com| Avatar® http://AvatarAcademy.com
Ludovic Courtès wrote 7 years ago
(name . Thompson, David)(address . dthompson2@worcester.edu)(address . 30480@debbugs.gnu.org)
87r2pgekv2.fsf@gnu.org
Hi David!

"Thompson, David" <dthompson2@worcester.edu> skribis:

Toggle quote (16 lines)
> 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.

Indeed, that makes a lot of sense. I wondered about doing that for
‘guix pack’ as well, it turns out to be more shenanigans than we’d like.

Toggle quote (9 lines)
> 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.

Could you add an example in tests/guix-environment.sh that uses a
manifest with the “guile-bootstrap” package for instance?

OK with this change! :-)

Thank you,
Ludo’.
Thompson, David wrote 7 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 30480@debbugs.gnu.org)
CAJ=RwfYEOc0MbjbXbwAwie_kM2LOSqgDOr11Hg9SeKSf4ve2NA@mail.gmail.com
Hey Ludo,

On Mon, Feb 19, 2018 at 4:21 PM, Ludovic Courtès <ludo@gnu.org> wrote:
Toggle quote (37 lines)
> Hi David!
>
> "Thompson, David" <dthompson2@worcester.edu> skribis:
>
>> 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.
>
> Indeed, that makes a lot of sense. I wondered about doing that for
> ‘guix pack’ as well, it turns out to be more shenanigans than we’d like.
>
>> 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.
>
> Could you add an example in tests/guix-environment.sh that uses a
> manifest with the “guile-bootstrap” package for instance?
>
> OK with this change! :-)

Is this what you had in mind?

- Dave
From e6d0a82e5250d51e50cd05241261a460a71dbd37 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 +++++++++++++++++++++-
tests/guix-environment.sh | 9 +++++++++
3 files changed, 39 insertions(+), 1 deletion(-)

Toggle diff (101 lines)
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)))
diff --git a/tests/guix-environment.sh b/tests/guix-environment.sh
index bf5ca17fa..b44aca099 100644
--- a/tests/guix-environment.sh
+++ b/tests/guix-environment.sh
@@ -62,6 +62,15 @@ fi
guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
-- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
+# Make sure 'GUIX_ENVIRONMENT' points to the profile when building from a
+# manifest.
+echo "(use-modules (guix profiles) (gnu packages bootstrap))
+
+(packages->manifest (list %bootstrap-guile))
+" > $tmpdir/manifest.scm
+guix environment --bootstrap --manifest=$tmpdir/manifest.scm --pure \
+ -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
+
# Make sure '-r' works as expected.
rm -f "$gcroot"
expected="`guix environment --bootstrap --ad-hoc guile-bootstrap \
--
2.16.1
Ludovic Courtès wrote 7 years ago
(name . Thompson, David)(address . dthompson2@worcester.edu)(address . 30480@debbugs.gnu.org)
87fu5uc7th.fsf@gnu.org
Hi Dave,

"Thompson, David" <dthompson2@worcester.edu> skribis:

Toggle quote (3 lines)
> On Mon, Feb 19, 2018 at 4:21 PM, Ludovic Courtès <ludo@gnu.org> wrote:
>> Hi David!

[...]

Toggle quote (16 lines)
>>> 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.
>>
>> Could you add an example in tests/guix-environment.sh that uses a
>> manifest with the “guile-bootstrap” package for instance?
>>
>> OK with this change! :-)
>
> Is this what you had in mind?

Yes, perfect. Thank you!

Ludo’.
Thompson, David wrote 7 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 30480@debbugs.gnu.org)
CAJ=RwfbZVYyPHQkP+SXXNj4G3N6CYhh1p5vKVjCjfKX+e1AmOw@mail.gmail.com
On Wed, Feb 21, 2018 at 5:10 PM, Ludovic Courtès <ludo@gnu.org> wrote:
Toggle quote (27 lines)
> Hi Dave,
>
> "Thompson, David" <dthompson2@worcester.edu> skribis:
>
>> On Mon, Feb 19, 2018 at 4:21 PM, Ludovic Courtès <ludo@gnu.org> wrote:
>>> Hi David!
>
> [...]
>
>>>> 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.
>>>
>>> Could you add an example in tests/guix-environment.sh that uses a
>>> manifest with the “guile-bootstrap” package for instance?
>>>
>>> OK with this change! :-)
>>
>> Is this what you had in mind?
>
> Yes, perfect. Thank you!

Pushed. Do I have to do something special to close this ticket?

- Dave
Leo Famulari wrote 7 years ago
(name . Thompson, David)(address . dthompson2@worcester.edu)
20180222064707.GA25321@jasmine.lan
On Wed, Feb 21, 2018 at 10:17:33PM -0500, Thompson, David wrote:
Toggle quote (2 lines)
> Pushed. Do I have to do something special to close this ticket?

I'm closing it by appending -done to the bug number in the email
address.
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEsFFZSPHn08G5gDigJkb6MLrKfwgFAlqOZ2sACgkQJkb6MLrK
fwgrbA/+Jj6ONt9QBS65w/kAe6bSqfVoWkyNakZCglb9FJyPYDLS50LEK5rsreIj
UcDsHEwdDCutPigODGXWwUdAMTvHU8iqSvBvv2tB3W5bAZPV0j9Sc6yKBrxGinoK
t90iw2Dml8cf1zDvoNCqnEc0lMah6abUbGKlr89Eb1uvkj0y4fwTFJ5fck6ktrKQ
qjvX65FxMDJ1fE3og9slNjVWiSsomsjuwYxPK9nnJLv0LKepRrp0+wscNgh3T8y4
NccF8ki32PjjR5k1X/i542c8acexwWKE0cqdoMmNZ7zawG6ipoXDlbKFaZAkzQBO
6fvFtiqQgcrvYqPrQKPe/TrCOeED1Gy7p//idtGgPbm3jz8I4LHCY4fdV80Llk05
cpMcda5GFM7R+NbpplCVw+cDDFZS/5p9cXovQ0n781lEuQG4arIhY7t4IantKoyT
RsIYxunUajINc0GQKhBhuQUV7kaMKDdu3AQmiavlwAhHUmGvT7j7xUxRWovJVB/D
NPH0+q6vfXZGlbI6ZHcq2irVFuW1lZLUFUzYrBmeVQsTfyNlXgUlQHf/gWFQt/tE
ratvSec0l4l+WIRXT4YJFAJZojsEurenOxbg4VijHXF0RVguULV68h8AcodDxjZ4
JwWY3mYlCqNS/nJyMcL/sNHnC9Eoizce+TkOYaYvdeOrpNttBuA=
=Y//B
-----END PGP SIGNATURE-----


Closed
Andreas Enge wrote 7 years ago
(name . Thompson, David)(address . dthompson2@worcester.edu)
20180222091556.GA1381@jurong
On Wed, Feb 21, 2018 at 10:17:33PM -0500, Thompson, David wrote:
Toggle quote (2 lines)
> Pushed. Do I have to do something special to close this ticket?

One just needs to send an e-mail to BUGNUMBER-done@debbugs.gnu.org,
as I am doing with this message.

Andreas
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 30480@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 30480
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help