Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/integration/third_party/direnv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

??? note "Installing direnv"

Of course you can use `pixi` to install `direnv` globally. We recommend to run

```bash
pixi global install direnv
```

to install the latest version of `direnv` on your computer.

You can use `pixi` in combination with `direnv` to automatically activate environments on entering the corresponding directory.
Enter the following into your `.envrc` file:

```shell title=".envrc"
watch_file pixi.lock # (1)!
eval "$(pixi shell-hook)" # (2)!
```

1. This ensures that every time your `pixi.lock` changes, `direnv` invokes the shell-hook again.
2. This installs if needed, and activates the environment. `direnv` ensures that the environment is deactivated when you leave the directory.

```shell
$ cd my-project
direnv: error /my-project/.envrc is blocked. Run `direnv allow` to approve its content
$ direnv allow
direnv: loading /my-project/.envrc
✔ Project in /my-project is ready to use!
direnv: export +CONDA_DEFAULT_ENV +CONDA_PREFIX +PIXI_ENVIRONMENT_NAME +PIXI_ENVIRONMENT_PLATFORMS +PIXI_PROJECT_MANIFEST +PIXI_PROJECT_NAME +PIXI_PROJECT_ROOT +PIXI_PROJECT_VERSION +PIXI_PROMPT ~PATH
$ which python
/my-project/.pixi/envs/default/bin/python
$ cd ..
direnv: unloading
$ which python
python not found
```
39 changes: 2 additions & 37 deletions docs/workspace/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,43 +133,8 @@ $ (default) which python
!!! warning
It is not encouraged to use the traditional `conda activate`-like activation, as deactivating the environment is not really possible. Use `pixi shell` instead.

### Using `pixi` with `direnv`

??? note "Installing direnv"

Of course you can use `pixi` to install `direnv` globally. We recommend to run

```
pixi global install direnv
```

to install the latest version of `direnv` on your computer.

This allows you to use `pixi` in combination with `direnv`.
Enter the following into your `.envrc` file:

```shell title=".envrc"
watch_file pixi.lock # (1)!
eval "$(pixi shell-hook)" # (2)!
```

1. This ensures that every time your `pixi.lock` changes, `direnv` invokes the shell-hook again.
2. This installs if needed, and activates the environment. `direnv` ensures that the environment is deactivated when you leave the directory.

```shell
$ cd my-project
direnv: error /my-project/.envrc is blocked. Run `direnv allow` to approve its content
$ direnv allow
direnv: loading /my-project/.envrc
✔ Project in /my-project is ready to use!
direnv: export +CONDA_DEFAULT_ENV +CONDA_PREFIX +PIXI_ENVIRONMENT_NAME +PIXI_ENVIRONMENT_PLATFORMS +PIXI_PROJECT_MANIFEST +PIXI_PROJECT_NAME +PIXI_PROJECT_ROOT +PIXI_PROJECT_VERSION +PIXI_PROMPT ~PATH
$ which python
/my-project/.pixi/envs/default/bin/python
$ cd ..
direnv: unloading
$ which python
python not found
```
!!! tip ""
See our [direnv page](../integration/third_party/direnv.md) on how to leverage `pixi shell-hook` to integrate with direnv.

## Environment variables

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ nav:
- GitHub Actions: integration/ci/github_actions.md
- Lockfile Updates: integration/ci/updates_github_actions.md
- Third Party:
- Direnv: integration/third_party/direnv.md
- Pixi Diff: integration/third_party/pixi_diff.md
- Starship: integration/third_party/starship.md
- Switching from:
Expand Down
Loading