summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <davet@gnu.org>2015-05-28 08:41:04 -0400
committerDavid Thompson <davet@gnu.org>2015-05-28 20:52:52 -0400
commita54bd6d72dc91f649fb2b6cb3c612da1639d9b72 (patch)
tree456b1e40daa35dccff6d43d20f0abbab5584f6f2
parent1ba4796d135ba7a07f2e89126fba673601c321c2 (diff)
guix environment: Add --ad-hoc option.
* guix/scripts/environment.scm (%options): Add "ad-hoc" option. (show-help): Display help for "--ad-hoc". (packages+propagated-inputs): New procedure. (guix-environment): Create ad hoc environment when asked. * doc/guix.texi ("invoking guix environment"): Document it.
-rw-r--r--doc/guix.texi17
-rw-r--r--guix/scripts/environment.scm27
2 files changed, 40 insertions, 4 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 1956dbc422d..2d10ec9b598 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2381,7 +2381,7 @@ the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2381not found, the build system looks for @code{Setup.lhs} instead. 2381not found, the build system looks for @code{Setup.lhs} instead.
2382 2382
2383Which Haskell compiler is used can be specified with the @code{#:haskell} 2383Which Haskell compiler is used can be specified with the @code{#:haskell}
2384parameter which defaults to @code{ghc}. 2384parameter which defaults to @code{ghc}.
2385@end defvr 2385@end defvr
2386 2386
2387Lastly, for packages that do not need anything as sophisticated, a 2387Lastly, for packages that do not need anything as sophisticated, a
@@ -3932,6 +3932,21 @@ evaluates to.
3932@item -E @var{command} 3932@item -E @var{command}
3933Execute @var{command} in the new environment. 3933Execute @var{command} in the new environment.
3934 3934
3935@item --ad-hoc
3936Include all specified packages in the resulting environment, as if an
3937@i{ad hoc} package were defined with them as inputs. This option is
3938useful for quickly creating an environment without having to write a
3939package expression to contain the desired inputs.
3940
3941For instance, the command:
3942
3943@example
3944guix environment --ad-hoc guile guile-sdl -E guile
3945@end example
3946
3947runs @command{guile} in an environment where Guile and Guile-SDL are
3948available.
3949
3935@item --pure 3950@item --pure
3936Unset existing environment variables when building the new environment. 3951Unset existing environment variables when building the new environment.
3937This has the effect of creating an environment in which search paths 3952This has the effect of creating an environment in which search paths
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index d053daf02e2..42178091e66 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014 David Thompson <davet@gnu.org> 2;;; Copyright © 2014, 2015 David Thompson <davet@gnu.org>
3;;; Copyright © 2015 Ludovic Courtès <ludo@gnu.org> 3;;; Copyright © 2015 Ludovic Courtès <ludo@gnu.org>
4;;; 4;;;
5;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
@@ -103,6 +103,9 @@ shell command in that environment.\n"))
103 (display (_ " 103 (display (_ "
104 -E, --exec=COMMAND execute COMMAND in new environment")) 104 -E, --exec=COMMAND execute COMMAND in new environment"))
105 (display (_ " 105 (display (_ "
106 --ad-hoc include all specified packages in the environment instead
107 of only their inputs"))
108 (display (_ "
106 --pure unset existing environment variables")) 109 --pure unset existing environment variables"))
107 (display (_ " 110 (display (_ "
108 --search-paths display needed environment variable definitions")) 111 --search-paths display needed environment variable definitions"))
@@ -147,6 +150,9 @@ shell command in that environment.\n"))
147 (option '(#\e "expression") #t #f 150 (option '(#\e "expression") #t #f
148 (lambda (opt name arg result) 151 (lambda (opt name arg result)
149 (alist-cons 'expression arg result))) 152 (alist-cons 'expression arg result)))
153 (option '("ad-hoc") #f #f
154 (lambda (opt name arg result)
155 (alist-cons 'ad-hoc? #t result)))
150 (option '(#\n "dry-run") #f #f 156 (option '(#\n "dry-run") #f #f
151 (lambda (opt name arg result) 157 (lambda (opt name arg result)
152 (alist-cons 'dry-run? #t result))) 158 (alist-cons 'dry-run? #t result)))
@@ -191,6 +197,18 @@ packages."
191 (delete-duplicates 197 (delete-duplicates
192 (append-map transitive-inputs packages))) 198 (append-map transitive-inputs packages)))
193 199
200(define (packages+propagated-inputs packages)
201 "Return a list containing PACKAGES plus all of their propagated inputs."
202 (delete-duplicates
203 (append packages
204 (map (match-lambda
205 ((or (_ (? package? package))
206 (_ (? package? package) _))
207 package)
208 (_ #f))
209 (append-map package-transitive-propagated-inputs
210 packages)))))
211
194(define (build-inputs inputs opts) 212(define (build-inputs inputs opts)
195 "Build the packages in INPUTS using the build options in OPTS." 213 "Build the packages in INPUTS using the build options in OPTS."
196 (let ((substitutes? (assoc-ref opts 'substitutes?)) 214 (let ((substitutes? (assoc-ref opts 'substitutes?))
@@ -218,9 +236,12 @@ packages."
218 (let* ((opts (parse-command-line args %options (list %default-options) 236 (let* ((opts (parse-command-line args %options (list %default-options)
219 #:argument-handler handle-argument)) 237 #:argument-handler handle-argument))
220 (pure? (assoc-ref opts 'pure)) 238 (pure? (assoc-ref opts 'pure))
239 (ad-hoc? (assoc-ref opts 'ad-hoc?))
221 (command (assoc-ref opts 'exec)) 240 (command (assoc-ref opts 'exec))
222 (inputs (packages->transitive-inputs 241 (packages (pick-all (options/resolve-packages opts) 'package))
223 (pick-all (options/resolve-packages opts) 'package))) 242 (inputs (if ad-hoc?
243 (packages+propagated-inputs packages)
244 (packages->transitive-inputs packages)))
224 (drvs (run-with-store store 245 (drvs (run-with-store store
225 (mbegin %store-monad 246 (mbegin %store-monad
226 (set-guile-for-build (default-guile)) 247 (set-guile-for-build (default-guile))