Basics
Given a hello world example, click on the end of each line to get an explanation:
devenv.nix
{ pkgs, ... }: # (1)!
{ # (2)!
env.GREET = "hello"; # (3)!
packages = [ pkgs.jq ];
enterShell = ''
echo $GREET
jq --version
''; # (4)!
}
devenv.nix
is a function with inputs.pkgs
is an input passed as a special argument to the function. We use a special input...
at the end as a catch-all to avoid enumerating all of the inputs.- Our function is returning an attribute set, similar to an object in JSON.
- Attributes can be nested and have similar values as in JSON.
- Values can refer to the inputs. See Inputs for how to define inputs.
enterShell
allows you to execute bash code once the shell activates, while env
allows you to set environment variables:
See Nix language tutorial for a 1-2 hour deep dive that will allow you to read any Nix file.
Environment Summary
If you'd like to print the summary of the current environment:
$ devenv info
...
# env
- DEVENV_DOTFILE: .../myproject/.devenv
- DEVENV_ROOT: .../myproject
- DEVENV_STATE: .../myproject/.devenv/state
- GREET: hello
# packages
- jq-1.6
# scripts
# processes
CLI Options Overrides
New in 1.6
You can override configuration options temporarily using the --option
flag:
The option requires you to specify the inferred Nix type:
:string
for string values:int
for integer values:float
for floating-point values:bool
for boolean values (true/false):path
for file paths (interpreted as relative paths)
This is useful for temporarily changing the configuration without modifying your devenv.nix
file, such as when testing different configurations or creating option matrices.