|
| 1 | +--- |
| 2 | +title: Configuration Guide |
| 3 | +sidebar_position: 5 |
| 4 | +--- |
| 5 | + |
| 6 | +Your devbox configuration is stored in a `devbox.json` file, located in your project's root directory. This file can be edited directly, or using the [devbox CLI](cli_reference.md). |
| 7 | + |
| 8 | +```json |
| 9 | +{ |
| 10 | + "packages": [], |
| 11 | + "shell": { |
| 12 | + "init_hook": "..." |
| 13 | + }, |
| 14 | + "install_stage": { |
| 15 | + "command": "..." |
| 16 | + }, |
| 17 | + "build_stage":{ |
| 18 | + "command":"..." |
| 19 | + }, |
| 20 | + "start_stage": { |
| 21 | + "command": "..." |
| 22 | + } |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +### Packages |
| 27 | + |
| 28 | +This is a list of Nix packages that should be installed in your Devbox shell and containers. These packages will only be installed and available within your shell, and will have precedence over any packages installed in your local machine. You can search for Nix packages using [Nix Package Search](https://search.nixos.org/packages). |
| 29 | + |
| 30 | +You can add packages to your devbox.json using `devbox add <package_name>`, and remove them using `devbox rm <package_name>` |
| 31 | + |
| 32 | +### Shell |
| 33 | + |
| 34 | +You can configure `devbox shell` to run a custom commands at startup by setting an `init_hook`. This hook runs after any other `~/.*rc` scripts, allowing you to override environment variables or further customize the shell. |
| 35 | + |
| 36 | +This is an example `devbox.json` that customizes the prompt and prints a welcome message: |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "shell": { |
| 41 | + "init_hook": "export PS1='📦 devbox> '\necho 'Welcome! See CONTRIBUTING.md for tips on contributing to devbox.'" |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +When run, you'll see: |
| 47 | + |
| 48 | +``` |
| 49 | +> devbox shell |
| 50 | +Installing nix packages. This may take a while... |
| 51 | +Starting a devbox shell... |
| 52 | +Welcome! See CONTRIBUTING.md for tips on contributing to devbox. |
| 53 | +📦 devbox> |
| 54 | +``` |
| 55 | + |
| 56 | +### Stages |
| 57 | + |
| 58 | +Stages are used to configure and run commands at different points of container creation. For languages that support autodetction, Devbox will automatically detect and configure the correct stage commands for your project based on your source code. You can override any of these stages by configuring them in your devbox.json |
| 59 | + |
| 60 | +* The **install stage** will run after your base container has been initialized and your Nix packages are installed. This stage should be used to download and build your application's dependencies |
| 61 | +* The **build stage** runs after the install stage, and should be used to build or bundle your application. |
| 62 | +* The **start stage** will run when your container is started. This stage should include any commands needed to start and run your application. |
| 63 | + |
| 64 | +Each stage takes a single command that will be run when the stage is reached in your container build. |
| 65 | + |
| 66 | +```json |
| 67 | +//Install stage command for a Node Project |
| 68 | +"install_stage": { |
| 69 | + "command": "yarn install" |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +### Example: A Rust Devbox |
| 74 | + |
| 75 | +An example of a devbox configuration for a Rust project called `hello_world` might look like the following: |
| 76 | + |
| 77 | +```json |
| 78 | +{ |
| 79 | + "packages": [ |
| 80 | + "rustc" |
| 81 | + "cargo", |
| 82 | + "libiconv", |
| 83 | + ], |
| 84 | + "install_stage": { |
| 85 | + "command": "cargo install --path ." |
| 86 | + }, |
| 87 | + "build_stage":{ |
| 88 | + "command":"cargo build" |
| 89 | + }, |
| 90 | + "start_stage": { |
| 91 | + "command": "./target/build/hello_world" |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
0 commit comments