Clone this Gist:
git clone git@gist.github.com:/bbe689928cfa6ca1e55b7f2506e09626.git try-devenv-lock
This Gist demonstrates how devenv.lock can be parsed from plain Nix to
resolve inputs without enabling flakes.
| File | Purpose |
|---|---|
devenv.yaml |
Standard devenv input declarations |
devenv.nix |
Standard devenv configuration |
devenv.lock |
Lock file generated by devenv update |
default.nix |
uses devenv.lock for inputs pinning |
shell-*.nix |
provides devenv to use the above |
We use one of the shell-*.nix file to provide devenv.
Then we can use devenv, nix build or nix-build to build our package:
$ nix-shell shell-devenv.nix
$ devenv build outputs.app
✓ Building 6.2s
└ ✓ Downloading https://cache.nixos.org/nix-cache-info from cache.nixos.org 82ms
└ ✓ Downloading https://devenv.cachix.org/nix-cache- from 186ms
└ ✓ Evaluating Nix 1301 files 343ms
└ ✓ Evaluating devenv.config.outputs.app 1299 files 512ms
└ ✓ Querying app from cache.nixos.org 173ms
└ ✓ Building app 33ms
{
"outputs.app": "/nix/store/ybf4wyw9a7qv4nbwkp2miqi55i13rjx7-app"
}
$ nix build -f default.nix app --print-out-paths --no-link
/nix/store/ybf4wyw9a7qv4nbwkp2miqi55i13rjx7-app
$ nix-build -A app --no-out-link
/nix/store/ybf4wyw9a7qv4nbwkp2miqi55i13rjx7-app
We use shell-25.11.nix to get a "recent" version of devenv (1.11.1 in my
case) and generate a devenv.lock file from the devenv.yaml file:
$ nix-shell shell-25.11.nix --run "devenv version"
devenv 1.11.1 (x86_64-linux)
$ nix-shell shell-25.11.nix --run "devenv update"
The generated lock file is just JSON, so we can use e.g. jq to inspect it:
$ jq '.nodes[.nodes.root.inputs.nixpkgs].locked' devenv.lock
$ jq '.nodes[.nodes.root.inputs.nixpkgs].locked | {owner, repo, rev}' devenv.lock
We can use the lock file to define a new Nix shell with pinned dependencies:
$ nix-shell shell-locked.nix --run 'devenv version'
devenv 1.11.2 (x86_64-linux)
To get a very recent devenv, we can use a GitHub release:
$ nix-shell shell-devenv-2.0.3.nix --run 'devenv version' \
--option extra-substituters "https://devenv.cachix.org" \
--option extra-trusted-public-keys \
"devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
devenv 2.0.3 (x86_64-linux)
The way we use the lock file in shell-locked.nix can also be used from a
default.nix file. This should show the same ouput as the above jq call:
$ nix-instantiate --eval --strict --json \
-A inputsMetadata.nixpkgs ./default.nix | jq '{owner, repo, rev}'