|
| 1 | +--- |
| 2 | +title: Nix & devenv support |
| 3 | +author: mfocko |
| 4 | +--- |
| 5 | + |
| 6 | +# Nix & devenv support |
| 7 | + |
| 8 | +:::tip tl;dr |
| 9 | + |
| 10 | +Ideal for atomic linux distributions and macOS setup. |
| 11 | + |
| 12 | +There's one file (`devenv.nix`) containing everything that's needed to set up an |
| 13 | +environment for the project (`packit/deployment` in this case). All tools and |
| 14 | +deps are kept only for this project, i.e., they don't pollute the host system. |
| 15 | + |
| 16 | +Since Nix and devenv.sh support pinning, it is also possible to acquire |
| 17 | +a reproducible environment. |
| 18 | + |
| 19 | +[`direnv`](https://devenv.sh/automatic-shell-activation/) makes sure the development environment is set up upon entering the repo. |
| 20 | + |
| 21 | +::: |
| 22 | + |
| 23 | +## What is [Nix](https://nixos.org/)? |
| 24 | + |
| 25 | +From the homepage: |
| 26 | + |
| 27 | +> Nix is a tool that takes a unique approach to package management and system |
| 28 | +> configuration. Learn how to make reproducible, declarative and reliable systems. |
| 29 | +
|
| 30 | +Basically you have global environment and smaller `nix-shell`s that are usually |
| 31 | +tied to git repos (or any other directory). You aim for as small base environment |
| 32 | +as possible, i.e., you don't want to keep all utilities / dependencies everywhere. |
| 33 | + |
| 34 | +One benefit, in comparison to containers, lies in the fact that the packages are |
| 35 | +defined by hash, name and version which allows them to be stored in a global |
| 36 | +location (usually `/nix`). Including packages in “environments” is done by |
| 37 | +adjusting `$PATH` (and related) variable. |
| 38 | + |
| 39 | +## What is [devenv.sh](https://devenv.sh/)? |
| 40 | + |
| 41 | +Builds on top of the _Nix_ and _nix-shell_ themselves. Is a bit more robust, |
| 42 | +cause it also allows specifying environment variables, defining tasks, services, |
| 43 | +and processes. For example it allows you to automatically spin up `nginx` or |
| 44 | +`postgres` server once you enter the repo. |
| 45 | + |
| 46 | +## Getting started |
| 47 | + |
| 48 | +Feel free to follow the [devenv.sh' “Getting Started”](https://devenv.sh/getting-started/). |
| 49 | + |
| 50 | +1. You need to have _Nix_ set up. (single-user / non-daemon setup is recommended |
| 51 | + for users with SELinux enabled) |
| 52 | +2. Install the _devenv.sh_ itself. |
| 53 | +3. Have _direnv_ present (since it automatically loads the environment upon |
| 54 | + entering the directory with _devenv.sh_). |
| 55 | + |
| 56 | +## Caveats |
| 57 | + |
| 58 | +Bitwarden CLI is currently broken on macOS, therefore it's not included in the |
| 59 | +devenv.sh' config. |
0 commit comments