|
| 1 | +# Using Nix Development Shell for xrpld Development |
| 2 | + |
| 3 | +This guide explains how to use Nix to set up a reproducible development environment for xrpld. Using Nix eliminates the need to manually install utilities and ensures consistent tooling across different machines. |
| 4 | + |
| 5 | +## Benefits of Using Nix |
| 6 | + |
| 7 | +- **Reproducible environment**: Everyone gets the same versions of tools and compilers |
| 8 | +- **No system pollution**: Dependencies are isolated and don't affect your system packages |
| 9 | +- **Multiple compiler versions**: Easily switch between different GCC and Clang versions |
| 10 | +- **Quick setup**: Get started with a single command |
| 11 | +- **Works on Linux and macOS**: Consistent experience across platforms |
| 12 | + |
| 13 | +## Install Nix |
| 14 | + |
| 15 | +Please follow [the official installation instructions of nix package manager](https://nixos.org/download/) for your system. |
| 16 | + |
| 17 | +## Entering the Development Shell |
| 18 | + |
| 19 | +### Basic Usage |
| 20 | + |
| 21 | +From the root of the xrpld repository, enter the default development shell: |
| 22 | + |
| 23 | +```bash |
| 24 | +nix --experimental-features 'nix-command flakes' develop |
| 25 | +``` |
| 26 | + |
| 27 | +This will: |
| 28 | + |
| 29 | +- Download and set up all required development tools (CMake, Ninja, Conan, etc.) |
| 30 | +- Configure the appropriate compiler for your platform: |
| 31 | + - **macOS**: Apple Clang (default system compiler) |
| 32 | + - **Linux**: GCC 15 |
| 33 | + |
| 34 | +The first time you run this command, it will take a few minutes to download and build the environment. Subsequent runs will be much faster. |
| 35 | + |
| 36 | +> [!TIP] |
| 37 | +> To avoid typing `--experimental-features 'nix-command flakes'` every time, you can permanently enable flakes by creating `~/.config/nix/nix.conf`: |
| 38 | +> |
| 39 | +> ```bash |
| 40 | +> mkdir -p ~/.config/nix |
| 41 | +> echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf |
| 42 | +> ``` |
| 43 | +> |
| 44 | +> After this, you can simply use `nix develop` instead. |
| 45 | +
|
| 46 | +> [!NOTE] |
| 47 | +> The examples below assume you've enabled flakes in your config. If you haven't, add `--experimental-features 'nix-command flakes'` after each `nix` command. |
| 48 | +
|
| 49 | +### Choosing a different compiler |
| 50 | +
|
| 51 | +A compiler can be chosen by providing its name with the `.#` prefix, e.g. `nix develop .#gcc15`. |
| 52 | +Use `nix flake show` to see all the available development shells. |
| 53 | +
|
| 54 | +Use `nix develop .#no_compiler` to use the compiler from your system. |
| 55 | +
|
| 56 | +### Example Usage |
| 57 | +
|
| 58 | +```bash |
| 59 | +# Use GCC 14 |
| 60 | +nix develop .#gcc14 |
| 61 | +
|
| 62 | +# Use Clang 19 |
| 63 | +nix develop .#clang19 |
| 64 | +
|
| 65 | +# Use default for your platform |
| 66 | +nix develop |
| 67 | +``` |
| 68 | +
|
| 69 | +### Using a different shell |
| 70 | +
|
| 71 | +`nix develop` opens bash by default. If you want to use another shell this could be done by adding `-c` flag. For example: |
| 72 | +
|
| 73 | +```bash |
| 74 | +nix develop -c zsh |
| 75 | +``` |
| 76 | +
|
| 77 | +## Building xrpld with Nix |
| 78 | +
|
| 79 | +Once inside the Nix development shell, follow the standard [build instructions](../../BUILD.md#steps). The Nix shell provides all necessary tools (CMake, Ninja, Conan, etc.). |
| 80 | +
|
| 81 | +## Automatic Activation with direnv |
| 82 | +
|
| 83 | +[direnv](https://direnv.net/) or [nix-direnv](https://github.com/nix-community/nix-direnv) can automatically activate the Nix development shell when you enter the repository directory. |
| 84 | +
|
| 85 | +## Conan and Prebuilt Packages |
| 86 | +
|
| 87 | +Please note that there is no guarantee that binaries from conan cache will work when using nix. If you encounter any errors, please use `--build '*'` to force conan to compile everything from source: |
| 88 | +
|
| 89 | +```bash |
| 90 | +conan install .. --output-folder . --build '*' --settings build_type=Release |
| 91 | +``` |
| 92 | +
|
| 93 | +## Updating `flake.lock` file |
| 94 | +
|
| 95 | +To update `flake.lock` to the latest revision use `nix flake update` command. |
0 commit comments