Skip to content

The outputs Function

The flake-file.outputs option is a literal Nix string that is placed verbatim as the outputs attribute in the generated flake.nix:

# generated flake.nix (simplified)
{
outputs = <your flake-file.outputs value here>;
}

The default value is:

inputs: import ./outputs.nix inputs

This is deliberately minimal — it delegates all logic to outputs.nix, keeping flake.nix as a pure dependency manifest.

flake.nix is a generated file. If you embed complex Nix logic in flake-file.outputs, you are putting business logic in a string option, which is hard to read, impossible to type-check, and easy to break.

The recommended split:

  • flake.nix — generated, declares inputs and nixConfig only.
  • outputs.nix — hand-written, contains all your Nix logic.

The only reasonable case for overriding outputs is a legitimate one-liner — for example, the dendritic module sets:

flake-file.outputs = "inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules)";

This is still a single expression with no embedded logic.

You cannot assign a Nix function value to flake-file.outputs. A Nix function cannot be serialised to a string. This option exists only for a literal code string.

# WRONG — this will fail
flake-file.outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { };

Always set it to a string:

# Correct
flake-file.outputs = ''inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { }'';
Contribute Community Sponsor