Validate identical dev/prod environments¶
Background¶
In order to verify that your development environment matches the production environment you can examine the Nix store path of the environment in both locations.
The Nix store is a directory that serves as a cache of all the programs,
libraries, scripts, etc in your environment.
Paths in this directory have the form /nix/store/<hash>-<name>
,
where the hash is used to uniquely identify the package.
The hash in the path is computed from the hashes of all the package
dependencies, the system (CPU architecture and OS), and the source of the
package itself, so a change in any of these will result in a different store
path.
Compare store paths¶
Each generation of an environment has its own path. Start by getting the current path for your environment:
$ tracelinks $(flox list --json -e demo | jq -r .path) # (1)!
/Users/demo/.local/share/flox/environments/mkenigs/aarch64-darwin.demo -> aarch64-darwin.demo-1-link
/Users/demo/.local/share/flox/environments/mkenigs/aarch64-darwin.demo-1-link -> /nix/store/qjzlc6adbwyd72cnbmdn3x8qxw6757vg-floxShell
/nix/store/qjzlc6adbwyd72cnbmdn3x8qxw6757vg-floxShell -> /nix/store/6nbrg3l8h4nqz0rmiz93xfijnj4i4f3a-wrapper
/nix/store/6nbrg3l8h4nqz0rmiz93xfijnj4i4f3a-wrapper: directory # (2)!
flox list --json
dumps metadata about an environment, and we filter withjq
to just keep thepath
of the environment.tracelinks
follows symlinks until it finds an actual file or directory.- flox environments are wrapped in a few layers of symlink indirection, but all the symlinks can be ignored for the purpose of this how-to
You can run this same command in your production environment, and as long as the CPU architecture and OS are the same you should get the same path.
Now add a package to your development environment:
Now get the new path for your environment and see that they are different:
$ tracelinks $(flox list --json -e $environment_name | jq -r .path)
...
/nix/store/pmk8j28228kx9drdq1chdv8gypqkrvmk-wrapper: directory # (1)!
- The previous store path was /nix/store/6nbrg3l8h4nqz0rmiz93xfijnj4i4f3a-wrapper
If you rollback to a prior generation, your environment will have the original path again:
$ flox rollback -e demo
Rolled back environment 'demo' from generation 2 to 1.
$ tracelinks $(flox list --json -e $environment_name | jq -r .path)
...
/nix/store/6nbrg3l8h4nqz0rmiz93xfijnj4i4f3a-wrapper: directory
From this exercise you can now see that a given generation of an environment on a given CPU architecture and OS will always be the same, and this can be verified by checking the underlying store path.