3. Explore Nix Development Environments
The Nix CLI did a few things:
- It used the
github:DeterminateSystems/zero-to-nix
flake reference to pull in some Nix code and built a specific flake output (more on this later).
- It built the packages specified in the environment configuration (again, more on this later).
- It set up an environment with a
PATH
that enables thegit
andcurl
packages to be discovered in the Nix store.
While it’s fun to explore the environment, you don’t always want to be inside the environment to use it. The
nix develop
command provides a--command
(or-c
) flag that you can use to run commands that use the environment but from your current environment.
Nix development environments are hermetic in that they’re isolated from the surrounding environment (such as your environment variables and paths like
/bin
and/usr/bin
).
direnv is a popular tool that automatically loads specific environment variables whenever you
cd
into a directory (and then unloads those variables when youcd
out of the directory). The combination of direnv and Nix can be quite powerful, enabling you to automatically load Nix development environments whenever you navigate to a directory.
The
flake.nix
file defines the flake for your project.
The
flake.lock
pins all of the flake inputs—essentially the Nix dependencies—in yourflake.nix
file to specific Git revisions.