scripts: environment: Allow lists of packages in expressions.
* guix/scripts/environment.scm (options/resolve-packages): Match against lists of packages when evaluating expressions. * tests/guix-environment.sh: Add test. * doc/guix.texi ("invoking guix environment"): Add docs.master
parent
4fca58a6c6
commit
c9c282cea0
|
@ -4730,7 +4730,8 @@ The available options are summarized below.
|
||||||
@table @code
|
@table @code
|
||||||
@item --expression=@var{expr}
|
@item --expression=@var{expr}
|
||||||
@itemx -e @var{expr}
|
@itemx -e @var{expr}
|
||||||
Create an environment for the package that @var{expr} evaluates to.
|
Create an environment for the package or list of packages that
|
||||||
|
@var{expr} evaluates to.
|
||||||
|
|
||||||
For example, running:
|
For example, running:
|
||||||
|
|
||||||
|
@ -4741,10 +4742,18 @@ guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
|
||||||
starts a shell with the environment for this specific variant of the
|
starts a shell with the environment for this specific variant of the
|
||||||
PETSc package.
|
PETSc package.
|
||||||
|
|
||||||
|
Running:
|
||||||
|
|
||||||
|
@example
|
||||||
|
guix environment --ad-hoc -e '(@ (gnu) %base-packages)'
|
||||||
|
@end example
|
||||||
|
|
||||||
|
starts a shell with all the GuixSD base packages available.
|
||||||
|
|
||||||
@item --load=@var{file}
|
@item --load=@var{file}
|
||||||
@itemx -l @var{file}
|
@itemx -l @var{file}
|
||||||
Create an environment for the package that the code within @var{file}
|
Create an environment for the package or list of packages that the code
|
||||||
evaluates to.
|
within @var{file} evaluates to.
|
||||||
|
|
||||||
As an example, @var{file} might contain a definition like this
|
As an example, @var{file} might contain a definition like this
|
||||||
(@pxref{Defining Packages}):
|
(@pxref{Defining Packages}):
|
||||||
|
|
|
@ -253,6 +253,18 @@ COMMAND or an interactive shell in that environment.\n"))
|
||||||
(define (options/resolve-packages opts)
|
(define (options/resolve-packages opts)
|
||||||
"Return OPTS with package specification strings replaced by actual
|
"Return OPTS with package specification strings replaced by actual
|
||||||
packages."
|
packages."
|
||||||
|
(define (package->outputs package mode)
|
||||||
|
(map (lambda (output)
|
||||||
|
(list mode package output))
|
||||||
|
(package-outputs package)))
|
||||||
|
|
||||||
|
(define (packages->outputs packages mode)
|
||||||
|
(match packages
|
||||||
|
((? package? package)
|
||||||
|
(package->outputs package mode))
|
||||||
|
(((? package? packages) ...)
|
||||||
|
(append-map (cut package->outputs <> mode) packages))))
|
||||||
|
|
||||||
(compact
|
(compact
|
||||||
(append-map (match-lambda
|
(append-map (match-lambda
|
||||||
(('package mode (? string? spec))
|
(('package mode (? string? spec))
|
||||||
|
@ -261,17 +273,11 @@ packages."
|
||||||
(list (list mode package output))))
|
(list (list mode package output))))
|
||||||
(('expression mode str)
|
(('expression mode str)
|
||||||
;; Add all the outputs of the package STR evaluates to.
|
;; Add all the outputs of the package STR evaluates to.
|
||||||
(match (read/eval str)
|
(packages->outputs (read/eval str) mode))
|
||||||
((? package? package)
|
|
||||||
(map (lambda (output)
|
|
||||||
(list mode package output))
|
|
||||||
(package-outputs package)))))
|
|
||||||
(('load mode file)
|
(('load mode file)
|
||||||
;; Add all the outputs of the package defined in FILE.
|
;; Add all the outputs of the package defined in FILE.
|
||||||
(let ((package (load* file (make-user-module '()))))
|
(let ((module (make-user-module '())))
|
||||||
(map (lambda (output)
|
(packages->outputs (load* file module) mode)))
|
||||||
(list mode package output))
|
|
||||||
(package-outputs package))))
|
|
||||||
(_ '(#f)))
|
(_ '(#f)))
|
||||||
opts)))
|
opts)))
|
||||||
|
|
||||||
|
|
|
@ -111,4 +111,15 @@ then
|
||||||
grep -E '^export CPATH=.*-gcc-bootstrap-0/include' "$tmpdir/a"
|
grep -E '^export CPATH=.*-gcc-bootstrap-0/include' "$tmpdir/a"
|
||||||
grep -E '^export CPATH=.*-glibc-bootstrap-0/include' "$tmpdir/a"
|
grep -E '^export CPATH=.*-glibc-bootstrap-0/include' "$tmpdir/a"
|
||||||
grep -E '^export LIBRARY_PATH=.*-glibc-bootstrap-0/lib' "$tmpdir/a"
|
grep -E '^export LIBRARY_PATH=.*-glibc-bootstrap-0/lib' "$tmpdir/a"
|
||||||
|
|
||||||
|
# Make sure a package list can be used with -e.
|
||||||
|
expr_list_test_code="
|
||||||
|
(list (@@ (gnu packages commencement) gnu-make-boot0)
|
||||||
|
(@ (gnu packages bootstrap) %bootstrap-guile))"
|
||||||
|
|
||||||
|
guix environment --ad-hoc --no-substitutes --search-paths --pure \
|
||||||
|
-e "$expr_list_test_code" > "$tmpdir/a"
|
||||||
|
|
||||||
|
grep -E '^export PATH=.*-make-boot0-4.1/bin' "$tmpdir/a"
|
||||||
|
grep -E '^export PATH=.*-guile-bootstrap-2.0/bin' "$tmpdir/a"
|
||||||
fi
|
fi
|
||||||
|
|
Reference in New Issue