[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: set environment variables with guix shell [-m manifest.scm]

From: Kenny Ballou
Subject: Re: set environment variables with guix shell [-m manifest.scm]
Date: Fri, 06 May 2022 16:20:42 -0600
User-agent: mu4e 1.6.10; emacs 28.1.50

On 2022-05-05 11:05 +02, zimoun wrote:
> Wed, 04 May 2022 at 18:53, Kenny Ballou <> wrote:
>> However, one necessary feature of `guix shell` I'm not seeing: ability
>> to set arbitrary environment variables when `guix shell` loads.
> Yes, it misses an equivalent to ’nix-shell’ «shellHook» [1], as also
> reported by [2] Well, maybe you could achieve something via ’--file’
> instead of ’--manifest’, I do not know.

I was not aware of [2], thanks for pointing me to it.

I have not tried `--file`.  My understanding is that this does not quite
do the same thing.

Unrelated to search paths below, I had an idea that it would be possible
to construct a derivation which sets the environment variables and add
the resulting derivation to the "manifest".  However, I suspect I'm
misunderstanding the `#:env-vars` key to the `gexp->derivation`[5]

Along this idea though, how difficult would it be to add an optional
parameter to `*->manifest` functions such that it constructs the profile
with additional environment variables?  Is that desirable?

> Since you use Direnv [3], maybe you can set the environment variables
> there instead of in the manifest file.

While this would work in general, I'm trying to add things that directly
reference computed store paths.  I'm not sure how I can easily achieve
this with `direnv`.

For example, I'm trying to set `LD_LIBRARY_PATH` to point to the `lib`
directory of the `z3` package.  Furthermore, I need to set `JAVA_HOME`
to the store path of `openjdk11-jdk`.

> 1: <>
> 2: 
> <>
> 3: <>

I've had some success setting search paths[4], as here:

(define z3-with-java
   (inherit z3-4.8.10)
    `(("which" ,which)
      ("python" ,python-wrapper)
      ("jdk" ,java:openjdk11 "jdk")))
    `(#:tests? #f
      #:validate-runpath? #f
      (modify-phases %standard-phases
                     (add-after 'unpack 'set-JDK_HOME
                                (lambda* (#:key inputs #:allow-other-keys)
                                  (setenv "JDK_HOME" (assoc-ref inputs "jdk"))
                     (replace 'configure
                              (lambda* (#:key inputs outputs #:allow-other-keys)
                                (invoke "python" "scripts/"
                                        (string-append "--prefix=" (assoc-ref 
outputs "out")))))
                     (add-after 'configure 'change-directory
                                (lambda _
                                  (chdir "build")
    (list (search-path-specification
           (variable "LD_LIBRARY_PATH")
           (separator #f)
           (files (list "lib/")))
           (variable "Z3_DIR")
           (separator #f)
           (files (list "")))))))

Unrelated to this whole thing, and likely in need of a new thread, how
do I translate the above package definition which overrides the inputs
to use the new gexp style[6]?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]