3. Explore Nix Development Environments
The Nix CLI did a few things:
- It used the
github:DeterminateSystems/zero-to-nixflake 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
PATHthat enables thegitandcurlpackages 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 developcommand 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
/binand/usr/bin).
direnv is a popular tool that automatically loads specific environment variables whenever you
cdinto a directory (and then unloads those variables when youcdout 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.nixfile defines the flake for your project.
The
flake.lockpins all of the flake inputs—essentially the Nix dependencies—in yourflake.nixfile to specific Git revisions.