Environment Variables
Configurable Environment Variables#
Pixi can also be configured via environment variables.
Name | Description | Default |
---|---|---|
PIXI_HOME |
Defines the directory where pixi puts its global data. | HOME/.pixi |
PIXI_CACHE_DIR |
Defines the directory where pixi puts its cache. |
|
Environment Variables Set By Pixi#
The following environment variables are set by Pixi, when using the pixi run
, pixi shell
, or pixi shell-hook
command:
PIXI_PROJECT_ROOT
: The root directory of the project.PIXI_PROJECT_NAME
: The name of the project.PIXI_PROJECT_MANIFEST
: The path to the manifest file (pixi.toml
).PIXI_PROJECT_VERSION
: The version of the project.PIXI_PROMPT
: The prompt to use in the shell, also used bypixi shell
itself.PIXI_ENVIRONMENT_NAME
: The name of the environment, defaults todefault
.PIXI_ENVIRONMENT_PLATFORMS
: Comma separated list of platforms supported by the project.CONDA_PREFIX
: The path to the environment. (Used by multiple tools that already understand conda environments)CONDA_DEFAULT_ENV
: The name of the environment. (Used by multiple tools that already understand conda environments)PATH
: We prepend thebin
directory of the environment to thePATH
variable, so you can use the tools installed in the environment directly.INIT_CWD
: ONLY INpixi run
: The directory where the command was run from.
Note
Even though the variables are environment variables these cannot be overridden. E.g. you can not change the root of the project by setting PIXI_PROJECT_ROOT
in the environment.
Environment Variable Priority#
The following priority rule applies for environment variables: task.env
> activation.env
> activation.scripts
> activation scripts of dependencies > outside environment variables.
Variables defined at a higher priority will override those defined at a lower priority.
Warning
In older versions of Pixi, this priority was not well-defined, and there are a number of known deviations from the current priority which exist in some older versions. Please see the warning in the advanced tasks documentation for further details and migration guidance.
Example 1: task.env
> activation.env
#
In pixi.toml
, we defined an environment variable HELLO_WORLD
in both tasks.hello
and activation.env
.
When we run echo $HELLO_WORLD
, it will output:
[tasks.hello]
cmd = "echo $HELLO_WORLD"
env = { HELLO_WORLD = "Hello world!" }
[activation.env]
HELLO_WORLD = "Activate!"
Example 2: activation.env
> activation.scripts
#
In pixi.toml
, we defined the same environment variable DEBUG_MODE
in both activation.env
and in the activation script file setup.sh
.
When we run echo Debug mode: $DEBUG_MODE
, it will output:
Example 3: activation.scripts
> activation scripts of dependencies#
In pixi.toml
, we have our local activation script and a dependency my-package
that also sets environment variables through its activation scripts.
When we run echo Library path: $LIB_PATH
, it will output:
[activation]
scripts = ["local_setup.sh"]
[dependencies]
my-package = "*" # This package has its own activation scripts that set LIB_PATH="/dep/lib"
Example 4: activation scripts of dependencies > outside environment variable#
If we have a dependency that sets PYTHON_PATH
and the same variable is already set in the outside environment.
When we run echo Python path: $PYTHON_PATH
, it will output:
[dependencies]
python-utils = "*" # This package sets PYTHON_PATH="/pixi/python" in its activation scripts
Example 5: Complex Example - All priorities combined#
In pixi.toml
, we define the same variable APP_CONFIG
across multiple levels:
[tasks.start]
cmd = "echo Config: $APP_CONFIG"
env = { APP_CONFIG = "task-specific" }
[activation.env]
APP_CONFIG = "activation-env"
[activation]
scripts = ["app_setup.sh"]
[dependencies]
config-loader = "*" # Sets APP_CONFIG="dependency-config"
Since task.env
has the highest priority, when we run pixi run start
it will output: