Sample Header Ad - 728x90

Guix: How to add an environment variable in a guix.scm file for use with guix shell? Or is it not possible?

0 votes
1 answer
797 views
[guix shell](https://guix.gnu.org/manual/devel/en/html_node/Invoking-guix-shell.html) allows users to create a shell and control what resources are available. How can I use the guix.scm file to specify an environment variable in this shell environment? In this specific example, I'm just looking for a TEST environment variable with the value 2. ChatGPT gave me two suggestions below which did not work, nor are these options defined in the [package reference](https://guix.gnu.org/manual/en/html_node/package-Reference.html) . Both give me the same error: *extraneous field initializers*. I also saw [this thread](https://lists.gnu.org/archive/html/help-guix/2022-05/msg00025.html) about the inability to define environment variables in a manifest file and one user said that it should be possible to do with guix.scm files (or, the type of files passed to guix shell with --file argument), but I'm not sure if that's correct. I tried the guile [setenv](https://www.gnu.org/software/guile/manual/html_node/Runtime-Environment.html#index-setenv) Scheme procedure but I get the error: *invalid field specifier*. Here's an example guix.scm with the three options I tried at the bottom:
(use-modules
	(guix)
	(guix build-system gnu)
	((guix licenses) #:prefix license:)
	(gnu packages bison)
	(gnu packages compression)
	(gnu packages flex)
	(gnu packages m4)
	(gnu packages tls)
)

(package
	(name "coreboot")
	(version "dan")
	(source (local-file "." #:recursive? #t))
	(build-system gnu-build-system)
	(native-inputs
		(list
			bison
			flex
			m4
			openssl
			zlib
		)
	)
	(synopsis "coreboot")
	(description "coreboot")
	(home-page "https://www.coreboot.org/ ")
	(license license:expat)
	(shell '(#:variables (,"TEST=2"))) ; Does not work
	(environment-variables '("TEST" "2")) ; Does not work
	(setenv "TEST" "2") ; Does not work
)
Asked by Daniel (701 rep)
May 19, 2024, 05:47 AM
Last activity: May 19, 2024, 09:28 AM