environment: Add --manifest option.

* guix/scripts/environment.scm (show-help, %options): Add -m/--manifest.
(options/resolve-packages): Handle manifests.
* tests/guix-envronment.sh: Add a test.
* doc/guix.texi (Invoking guix environment): Document it.
This commit is contained in:
David Thompson 2018-02-15 20:54:28 -05:00
parent ea6b1baec7
commit 267379f852
No known key found for this signature in database
GPG Key ID: 8328C7470FF1D807
3 changed files with 39 additions and 1 deletions

View File

@ -7231,6 +7231,15 @@ As an example, @var{file} might contain a definition like this
@verbatiminclude environment-gdb.scm @verbatiminclude environment-gdb.scm
@end example @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 @item --ad-hoc
Include all specified packages in the resulting environment, as if an Include all specified packages in the resulting environment, as if an
@i{ad hoc} package were defined with them as inputs. This option is @i{ad hoc} package were defined with them as inputs. This option is

View File

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; 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> ;;; Copyright © 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
@ -141,6 +141,8 @@ COMMAND or an interactive shell in that environment.\n"))
(display (G_ " (display (G_ "
-l, --load=FILE create environment for the package that the code within -l, --load=FILE create environment for the package that the code within
FILE evaluates to")) FILE evaluates to"))
(display (G_ "
-m, --manifest=FILE create environment with the manifest from FILE"))
(display (G_ " (display (G_ "
--ad-hoc include all specified packages in the environment instead --ad-hoc include all specified packages in the environment instead
of only their inputs")) of only their inputs"))
@ -220,6 +222,11 @@ COMMAND or an interactive shell in that environment.\n"))
(alist-cons 'expression (alist-cons 'expression
(tag-package-arg result arg) (tag-package-arg result arg)
result))) result)))
(option '(#\m "manifest") #t #f
(lambda (opt name arg result)
(alist-cons 'manifest
arg
result)))
(option '("ad-hoc") #f #f (option '("ad-hoc") #f #f
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'ad-hoc? #t result))) (alist-cons 'ad-hoc? #t result)))
@ -286,6 +293,16 @@ packages."
(((? package-or-package+output?) ...) ; many packages (((? package-or-package+output?) ...) ; many packages
(map (cut package->output <> mode) 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 (compact
(append-map (match-lambda (append-map (match-lambda
(('package mode (? string? spec)) (('package mode (? string? spec))
@ -299,6 +316,9 @@ packages."
;; Add all the outputs of the package defined in FILE. ;; Add all the outputs of the package defined in FILE.
(let ((module (make-user-module '()))) (let ((module (make-user-module '())))
(packages->outputs (load* file module) mode))) (packages->outputs (load* file module) mode)))
(('manifest . file)
(let ((module (make-user-module '())))
(manifest->outputs (load* file module))))
(_ '(#f))) (_ '(#f)))
opts))) opts)))

View File

@ -62,6 +62,15 @@ fi
guix environment --bootstrap --ad-hoc guile-bootstrap --pure \ guix environment --bootstrap --ad-hoc guile-bootstrap --pure \
-- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"' -- "$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. # Make sure '-r' works as expected.
rm -f "$gcroot" rm -f "$gcroot"
expected="`guix environment --bootstrap --ad-hoc guile-bootstrap \ expected="`guix environment --bootstrap --ad-hoc guile-bootstrap \