Environment variables: Difference between revisions
m Add clarification to section headers |
m Add categories nixos and configuration |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
== Configuration of shell environment on NixOS == | == Configuration of shell environment on NixOS == | ||
Environment variables can be set with [https://search.nixos.org/options?channel=unstable&show=environment.variables&from=0&size=50&sort=relevance&type=packages&query=environment.variables environment.variables ], [https://search.nixos.org/options?channel= | Environment variables can be set with [https://search.nixos.org/options?channel=unstable&show=environment.variables&from=0&size=50&sort=relevance&type=packages&query=environment.variables environment.variables ], [https://search.nixos.org/options?channel=unstable&show=environment.sessionVariables&from=0&size=50&sort=relevance&type=packages&query=environment.sessionVariables environment.sessionVariables ], and [https://search.nixos.org/options?channel=unstable&show=environment.profileRelativeSessionVariables&from=0&size=50&sort=relevance&type=packages&query=environment.profileRelativeSessionVariables environment.profileRelativeSessionVariables ] . | ||
<code>environment.variables</code> are global variables set on shell initialization, whereas <code>environment.sessionVariables</code> and <code>environment.profileRelativeSessionVariables</code> are initialized through PAM (Pluggable Authentication Module). | <code>environment.variables</code> are global variables set on shell initialization, whereas <code>environment.sessionVariables</code> and <code>environment.profileRelativeSessionVariables</code> are initialized through PAM (Pluggable Authentication Module). | ||
Session variable sets are merged into their environment variable set counterparts. For example, <code>environment.sessionVariables</code> is merged to <code>environment.variables</code> so you can just reload your shell to reload changed variables [https://github.com/NixOS/nixpkgs/blob/5e4fbfb6b3de1aa2872b76d49fafc942626e2add/nixos/modules/config/shells-environment.nix#L166-L170]. | |||
For example, for the [https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables XDG Base Directory Specification], the following could be set to <code>/etc/nixos/configuration.nix</code>: | For example, for the [https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables XDG Base Directory Specification], the following could be set to <code>/etc/nixos/configuration.nix</code>: | ||
Line 54: | Line 56: | ||
==== Solution or workaround ==== | ==== Solution or workaround ==== | ||
Unknown. | Unknown. | ||
== Using variables from a Nix expression == | |||
The <code>builtins.getEnv</code> function allows for reading the environment of the Nix command which triggered the expression to be evaluated, typically <code>nix-build</code>. | |||
== Variables exposed in nix-build sandbox == | == Variables exposed in nix-build sandbox == | ||
Line 77: | Line 83: | ||
NIX_STORE=/nix/store | NIX_STORE=/nix/store | ||
</pre> | </pre> | ||
[[Category:NixOS]] | |||
[[Category:Configuration]] |