unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Setting environment variables in a profile
@ 2022-05-19 19:43 Théo Maxime Tyburn
  2022-05-19 20:34 ` Maxime Devos
  0 siblings, 1 reply; 3+ messages in thread
From: Théo Maxime Tyburn @ 2022-05-19 19:43 UTC (permalink / raw)
  To: guix-devel

Hi,

I would like some environement variables to be present whenever I enter
a shell using `guix shell -p ...`.
Is there an easy way to do this?
I tried it this way: in the manifest file I use to define the
profile, I define a package and set some
(native)-search-paths. Unfortunatly this It didn’t work for some
reason I ignore. The environment variables are not there when I enter
the shell or source the profile directly. Here is the code

--8<---------------cut here---------------start------------->8---
(define my-env
  (package
   (version "0")    
   (source #f)
   (build-system trivial-build-system)
   (arguments '(#:builder (mkdir %output)))
   (synopsis "Empty package")
   (description
    "This package creates its store directory and nothing more.")
   (home-page #f)
   (license license:gpl3+)
   (name "my-env")
   (native-search-paths
    (list (search-path-specification
           (variable "PYTHONPATH")
           (files '("/home/teddd/..."
		    "/home/teddd/..."
		    "/home/teddd/...")))
          (search-path-specification
           (variable "BLENDER_USER_CONFIG")
           (files '("...")))
	  (search-path-specification
	   (variable "BLENDER_OPTIONS")
	   (files '("--python-use-system-env")))
	  ))
   (arguments '(#:builder (mkdir %output)))
   ))
--8<---------------cut here---------------end--------------->8---

Another problem I would have with this method is that the last environment
variable I want to set (BLENDER_OPTIONS) is not even a path. I am not
sure it is possible to sepcify a file-type to be "just a string".
Anyway I think this seems to be the wrong approach.

How would you approach this?

I konw direnv and other utils to set environment variables exist, I
miself use a bash script to initialize my profiles with variables I
want. But it would just be much more convinient to be able to define arbitrary env
variables in a guix manifest and enter a shell with everything you need.

Best,

Théo


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Setting environment variables in a profile
  2022-05-19 19:43 Setting environment variables in a profile Théo Maxime Tyburn
@ 2022-05-19 20:34 ` Maxime Devos
  2022-05-19 21:41   ` Théo Maxime Tyburn
  0 siblings, 1 reply; 3+ messages in thread
From: Maxime Devos @ 2022-05-19 20:34 UTC (permalink / raw)
  To: Théo Maxime Tyburn, guix-devel

[-- Attachment #1: Type: text/plain, Size: 1445 bytes --]

Théo Maxime Tyburn schreef op do 19-05-2022 om 21:43 [+0200]:
>            (files '("/home/teddd/..."
> 		    "/home/teddd/..."
> 		    "/home/teddd/...")))

This will do PYTHONPATH=$GUIX_ENVIRONMENT/home/tedd/...:$GUIX_ENVIRONMENT/home/tedd/...
where $GUIX_ENVIRONMENT is something like '/gnu/store/sgx9l505s7gw1axqnyqvz7iabgsni243-profile',
which I don't think is what you want here.  Additionally, most likely /home/tedd does
not exist in the profile, so they will be ignored and PYTHONPATH won't be set.

> Another problem I would have with this method is that the last environment
> variable I want to set (BLENDER_OPTIONS) is not even a path. I am not
> sure it is possible to sepcify a file-type to be "just a string".
> Anyway I think this seems to be the wrong approach.
> 
> How would you approach this?

I don't think this is currently supported, but I suppose it would be
possible to extend guix/profiles.scm and <manifest> to support this.
Maybe an API like:

contents of manifest.scm:
  (manifest
    (packages->manifest (list python3 blender ...))
    (environment-variables ; <-- new field
      (list (extend-search-path ; <--- new procedure
              (search-path [...] "PYTHONPATH" [...])
               "/home/tedd/...")
            (with-environment-variable "BLENDER_USER_CONFIG" "...") ; <-- new procedure
            [...])))

WDYT of this API?

Greetings,
Maxime.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Setting environment variables in a profile
  2022-05-19 20:34 ` Maxime Devos
@ 2022-05-19 21:41   ` Théo Maxime Tyburn
  0 siblings, 0 replies; 3+ messages in thread
From: Théo Maxime Tyburn @ 2022-05-19 21:41 UTC (permalink / raw)
  To: Maxime Devos; +Cc: guix-devel

Maxime Devos <maximedevos@telenet.be> writes:
> I don't think this is currently supported, but I suppose it would be
> possible to extend guix/profiles.scm and <manifest> to support this.
> Maybe an API like:
>
> contents of manifest.scm:
>   (manifest
>     (packages->manifest (list python3 blender ...))
>     (environment-variables ; <-- new field
>       (list (extend-search-path ; <--- new procedure
>               (search-path [...] "PYTHONPATH" [...])
>                "/home/tedd/...")
>             (with-environment-variable "BLENDER_USER_CONFIG" "...") ; <-- new procedure
>             [...])))
>
> WDYT of this API?

I think it looks great!

It seems the following definitions would need to get updated

in guix/profiles.scm:
- record: <manifest-entry> 

in guix/build/profiles.scm:
- procedure: manifest-sexp->inputs+search-paths
- procedure: build-profile

> Greetings,
> Maxime.

 Thanks for you time.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-19 21:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19 19:43 Setting environment variables in a profile Théo Maxime Tyburn
2022-05-19 20:34 ` Maxime Devos
2022-05-19 21:41   ` Théo Maxime Tyburn

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).