From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH] scripts: Add 'environment' command. Date: Thu, 09 Oct 2014 21:30:43 +0200 Message-ID: <87siix59cs.fsf@gnu.org> References: <87oatmch5i.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcJQH-0002r5-8Y for guix-devel@gnu.org; Thu, 09 Oct 2014 15:30:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XcJQC-0001xM-5X for guix-devel@gnu.org; Thu, 09 Oct 2014 15:30:49 -0400 Received: from hera.aquilenet.fr ([2a01:474::1]:52275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcJQB-0001x7-EM for guix-devel@gnu.org; Thu, 09 Oct 2014 15:30:43 -0400 In-Reply-To: <87oatmch5i.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> (David Thompson's message of "Wed, 08 Oct 2014 18:48:09 -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: David Thompson Cc: guix-devel@gnu.org Hey! David Thompson skribis: > The purpose of 'guix environment' is to assist hackers in creating > reproducible development environments without polluting their package > profile. 'guix environment' takes a package (or packages), builds all > of the necessary inputs, and creates a shell environment to use them. Awesome! [...] > By default, running 'guix environment' spawns a new $SHELL process, > because it is usually what one would want to do. However, the '--exec' > flag can be used to specify the command to run. > > Additionally, the default behavior is to prepend search paths to the > existing environment variable values so that one has access to other > installed software e.g. git. To clear the existing environment firstf, > the '--pure' flag can be used. > > Finally, the '--load' flag can be used to read a package from a file > instead of searching $GUIX_PACKAGE_PATH. This looks good to me. > From 298dcc1dd3aac49e033debeea154c91b25229c14 Mon Sep 17 00:00:00 2001 > From: David Thompson > Date: Sun, 21 Sep 2014 13:40:05 -0400 > Subject: [PATCH] scripts: Add 'environment' command. > > * guix/scripts/environment.scm: New file. > * Makefile.am (MODULES): Add it. [...] > +(define (purify-environment) > + "Unset almost all environment variables. A small number of variables = such > +as 'HOME' and 'USER' are left untouched." > + (for-each unsetenv > + (filter (lambda (variable) > + ;; Protect some env vars from purification. Borro= wed > + ;; from nix-shell. > + (not (member variable > + '("HOME" "USER" "LOGNAME" "DISPLAY" > + "TERM" "TZ" "PAGER")))) > + (map car (get-environment-variables))))) Maybe put the list of env. vars in a global variable, say =E2=80=98%precious-variables=E2=80=99, and then: (remove (cut member <> %precious-variables) (match (get-environment-variables) (((names . values) ...) names))) (My allergy to =E2=80=98car=E2=80=99 goes this far. ;-)) > + (display (_ " > + -e, --exec shell command to execute")) Perhaps make it -E, and use -e consistently with =E2=80=98guix build=E2=80= =99? It may be possible to reuse =E2=80=98options/resolve-packages=E2=80=99 for that. > +(define %default-options > + ;; Default to opening a new shell. > + `((exec . ,(getenv "SHELL")) (or (getenv "SHELL") "/bin/sh") > +(define (build-inputs inputs opts) > + "Build the packages in INPUTS using the build options in OPTS." > + (with-store store > + (run-with-store store > + (mlet* %store-monad ((drvs (sequence %store-monad > + (map package->derivation inpu= ts)))) > + (mbegin %store-monad > + (show-what-to-build* drvs > + #:use-substitutes? (assoc-ref opts 'subst= itutes?) > + #:dry-run? #f) > + (set-build-options-from-command-line* opts) > + (built-derivations drvs) > + (return drvs)))))) The store should rather be kept open around (system command). Otherwise the above derivations and their outputs could be GC=E2=80=99d (it should be possible to check that by trying to run =E2=80=98guix gc -d XXX=E2=80=99 on= one of them from within the sub-shell.) > +;; Entry point. > +(define (guix-environment . args) > + (define (parse-options) > + (args-fold* args %options > + (lambda (opt name arg result) > + (leave (_ "~A: unrecognized option~%") name)) > + (lambda (arg result) > + (alist-cons 'package arg result)) > + %default-options)) > + > + (let* ((opts (parse-options)) > + (pure? (assoc-ref opts 'pure)) > + (command (assoc-ref opts 'exec)) > + ;; Load from file if given, otherwise search for packages. > + (inputs (packages->transitive-inputs > + (or (and=3D> (assoc-ref opts 'load) load) > + (map specification->package > + (pick-all opts 'package))))) > + (drvs (build-inputs inputs opts))) Would be good to honor --dry-run as well. It would just print what needs to be built and exit. Thank you! Ludo=E2=80=99.