YOUR JOURNEY
13 / 18
03THINKING IN FLAKES 6 MIN READ
LESSON 13 / ANATOMY OF A FLAKE

One entry point.
Clear boundaries.

A flake standardizes what a Nix project consumes and exposes.

Inputs name dependencies. Outputs expose packages, development shells, and system configurations. The lock file records resolved inputs.

Explore the lesson
~$ Hands-on examples · Nix with flakes enabled.
THE FLAKE MODEL01 / 03
Drag to rotate

Inputs describe where dependencies come from.

nixpkgs enters the project
13.1THE PROJECT CONTRACT

A file with inputs and outputs.

A flake is a source tree with a flake.nix entry point. Its outputs function receives resolved inputs and returns an attribute set. Common output names let commands discover packages and development shells.

The upstream Nix manual still marks flakes and the new command interface experimental. This course uses that interface explicitly. Enable nix-command and flakes for these lessons, or supply the flags per command.

configuration setup · choose the appropriate line
# One-command enablement, without editing settings:
nix --extra-experimental-features "nix-command flakes" flake --help
 
# For a persistent user setting, add to:
# ~/.config/nix/nix.conf
# extra-experimental-features = nix-command flakes
Next section: A small, recognizable interface.
13.2THE SHAPE

A small, recognizable interface.

The following shows the basic shape, not a package you can build yet. nixpkgs is an input; outputs is a function. The ellipsis accepts additional arguments such as self.

On NixOS, configure the feature through nix.settings.experimental-features = [ "nix-command" "flakes" ]; in your system configuration, then rebuild.

flake.nix · basic structure
{
  description = "My first Nix project";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
 
  outputs = { nixpkgs, ... }: {
    # Packages and shells go here.
  };
}
TAKE THIS WITH YOU

flake.nix defines the interface; flake.lock records resolved external inputs.

Go a little deeperThe upstream flake manual
UP NEXT

Locking the inputs

A branch can move. A lock file remembers which revision you used.

Next lesson