Environment variables: Difference between revisions

From NixOS Wiki
imported>Yuu
No edit summary
imported>Yuu
No edit summary
Line 1: Line 1:
= Defining environment variables =
= Defining environment variables =


Environment variables can be set with <code>environment.variables</code>, <code>environment.sessionVariables</code>, and <code>environment.profileRelativeSessionVariables</code>. For example, for the [https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variablesXDG Base Directory Specification], the following could be set to <code>/etc/nixos/configuration.nix</code>:
Environment variables can be set with <code>environment.variables</code>, <code>environment.sessionVariables</code>, and <code>environment.profileRelativeSessionVariables</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>:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">

Revision as of 16:14, 8 July 2021

Defining environment variables

Environment variables can be set with environment.variables, environment.sessionVariables, and environment.profileRelativeSessionVariables. For example, for the XDG Base Directory Specification, the following could be set to /etc/nixos/configuration.nix:

{
 # ...

  environment.sessionVariables = rec {
    XDG_CACHE_HOME  = "\${HOME}/.cache";
    XDG_CONFIG_HOME = "\${HOME}/.config";
    XDG_BIN_HOME    = "\${HOME}/.local/bin";
    XDG_DATA_HOME   = "\${HOME}/.local/share";

    PATH = [ 
      "\${XDG_BIN_HOME}"
    ];
  };

 # ...
}