Skip to content

How it Works

flake-file integrates input definition as part of your Nix modules.

It provides a set of module options under the flake-file namespace that describe the contents of flake.nix.

When you run nix run .#write-flake, it evaluates those options and writes the file.

edit modules/*.nix # declare flake-file options
nix run .#write-flake # extracts inputs and serializes
flake.nix # updated and locked

Any Nix module can set flake-file.* options. Because this is the standard Nix module system, all the usual tools apply:

  • lib.mkDefault — set a value that can be overridden by other modules.
  • lib.mkForce — force a value regardless of what other modules set.
  • lib.mkIf — conditionally define an input.
  • Attribute merging — multiple files contribute to the same input set.
{ inputs, lib, ... }: {
flake-file.inputs.nixpkgs.url = lib.mkDefault "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-file.inputs.nixpkgs-lib.follows = "nixpkgs";
}

Options mirror the flake schema and extend it further:

NamespacePurpose
flake-file.descriptionFlake description string
flake-file.nixConfigNix binary cache and substituter config
flake-file.inputs.<name>.*Input declarations (url, follows, flake, ref, …)
flake-file.outputsLiteral Nix expression for the outputs function
flake-file.write-hooksCommands run after writing
flake-file.check-hooksCommands run during check
flake-file.prune-lock.*Automatic lock flattening

See the Options Reference for the complete table.

nix run .#write-flake collects inputs, serialises the merged options to valid Nix syntax, and writes flake.nix. It also runs any configured write-hooks.

nix flake check verifies that flake.nix is up to date with the current module state. If it is stale, the check fails. Add this to CI.

flake-file.outputs is a literal Nix string that becomes the body of the outputs function in flake.nix. It defaults to:

inputs: import ./outputs.nix inputs

This keeps flake.nix as a pure dependency manifest. All Nix logic lives in outputs.nix. See the Outputs guide for details.

Contribute Community Sponsor