From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Thompson Subject: [PATCH] guix environment: Add --ad-hoc option. Date: Thu, 28 May 2015 08:47:00 -0400 Message-ID: <87d21kg98b.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxxDV-0002Ce-Cu for guix-devel@gnu.org; Thu, 28 May 2015 08:47:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxxDP-0003rd-J5 for guix-devel@gnu.org; Thu, 28 May 2015 08:47:21 -0400 Received: from mail.fsf.org ([208.118.235.13]:53791) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxxDI-0003oW-E6 for guix-devel@gnu.org; Thu, 28 May 2015 08:47:15 -0400 Received: from [216.236.243.66] (port=59702 helo=izanagi) by mail.fsf.org with esmtpsa (TLS-1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1YxxDH-0002ME-03 for guix-devel@gnu.org; Thu, 28 May 2015 08:47:08 -0400 List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org --=-=-= Content-Type: text/plain I find myself frequently wanting to quickly create an environment with just a few packages in it, without having to go through the song and dance of creating a package expression for it. This patch addresses this use-case. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-guix-environment-Add-ad-hoc-option.patch Content-Transfer-Encoding: quoted-printable >From 30a5b0f61e5c4a0e0244015f127ba3255f834139 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 28 May 2015 08:41:04 -0400 Subject: [PATCH] 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. --- doc/guix.texi | 8 +++++++- guix/scripts/environment.scm | 27 ++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 1956dbc..2a9f61e 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -2381,7 +2381,7 @@ the @code{#:haddock-flags} parameter. If the file @c= ode{Setup.hs} is not found, the build system looks for @code{Setup.lhs} instead. =20 Which Haskell compiler is used can be specified with the @code{#:haskell} -parameter which defaults to @code{ghc}.=20 +parameter which defaults to @code{ghc}. @end defvr =20 Lastly, for packages that do not need anything as sophisticated, a @@ -3932,6 +3932,12 @@ evaluates to. @item -E @var{command} Execute @var{command} in the new environment. =20 +@item --ad-hoc +Include all specified packages in the resulting environment, as if an ad +hoc package were defined with them as inputs. This option is useful for +quickly creating an environment without having to write a package +expression to contain the desired inputs. + @item --pure Unset existing environment variables when building the new environment. This has the effect of creating an environment in which search paths diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index d053daf..4217809 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright =C2=A9 2014 David Thompson +;;; Copyright =C2=A9 2014, 2015 David Thompson ;;; Copyright =C2=A9 2015 Ludovic Court=C3=A8s ;;; ;;; This file is part of GNU Guix. @@ -103,6 +103,9 @@ shell command in that environment.\n")) (display (_ " -E, --exec=3DCOMMAND execute COMMAND in new environment")) (display (_ " + --ad-hoc include all specified packages in the environment= instead + of only their inputs")) + (display (_ " --pure unset existing environment variables")) (display (_ " --search-paths display needed environment variable definitions")) @@ -147,6 +150,9 @@ shell command in that environment.\n")) (option '(#\e "expression") #t #f (lambda (opt name arg result) (alist-cons 'expression arg result))) + (option '("ad-hoc") #f #f + (lambda (opt name arg result) + (alist-cons 'ad-hoc? #t result))) (option '(#\n "dry-run") #f #f (lambda (opt name arg result) (alist-cons 'dry-run? #t result))) @@ -191,6 +197,18 @@ packages." (delete-duplicates (append-map transitive-inputs packages))) =20 +(define (packages+propagated-inputs packages) + "Return a list containing PACKAGES plus all of their propagated inputs." + (delete-duplicates + (append packages + (map (match-lambda + ((or (_ (? package? package)) + (_ (? package? package) _)) + package) + (_ #f)) + (append-map package-transitive-propagated-inputs + packages))))) + (define (build-inputs inputs opts) "Build the packages in INPUTS using the build options in OPTS." (let ((substitutes? (assoc-ref opts 'substitutes?)) @@ -218,9 +236,12 @@ packages." (let* ((opts (parse-command-line args %options (list %default-optio= ns) #:argument-handler handle-argument= )) (pure? (assoc-ref opts 'pure)) + (ad-hoc? (assoc-ref opts 'ad-hoc?)) (command (assoc-ref opts 'exec)) - (inputs (packages->transitive-inputs - (pick-all (options/resolve-packages opts) 'package))) + (packages (pick-all (options/resolve-packages opts) 'package)) + (inputs (if ad-hoc? + (packages+propagated-inputs packages) + (packages->transitive-inputs packages))) (drvs (run-with-store store (mbegin %store-monad (set-guile-for-build (default-guile)) --=20 2.2.1 --=-=-= Content-Type: text/plain -- David Thompson GPG Key: 0FF1D807 --=-=-=--