Skip to content

Add nix flake bake command#450

Draft
edolstra wants to merge 15 commits intomainfrom
eelcodolstra/nix-379
Draft

Add nix flake bake command#450
edolstra wants to merge 15 commits intomainfrom
eelcodolstra/nix-379

Conversation

@edolstra
Copy link
Copy Markdown
Collaborator

@edolstra edolstra commented May 6, 2026

Motivation

Given a flake, nix flake bake produces a new "baked" flake consisting of the same outputs, but they're pre-evaluated, i.e. each output is a call to a function (builtins.fakeDerivation) that substitutes the output directly. Thus a baked flake is much faster since it does (almost) no evaluation.

Example usage:

# nix flake bake patchelf --dest-dir ./patchelf-baked

# nix flake show path:./patchelf-baked
path:/home/eelco/Dev/nix-master/build/patchelf-baked
├───checks
│   └───x86_64-linux
│       ├───build: CI test
│       └───pre-commit: CI test
| ...
└───packages
    └───x86_64-linux
        ├───default: package
...

# nix build path:./patchelf-baked

Note: this introduces a new builtin derivation (builtin:substitute) with its own new derivation type (DerivationType::Substituted). This derivation is never actually built (i.e. it's a "fake" derivation) - it just pulls in output paths via substitution. It looks like this:

$ nix derivation show path:./patchelf-baked
{
  "derivations": {
    "4aygrnsk0wj7hbalp7rdx078m0y6mbr7-patchelf-0.18.0.drv": {
      "args": [],
      "builder": "builtin:substitute",
      "env": {},
      "inputs": {
        "drvs": {},
        "srcs": []
      },
      "name": "patchelf-0.18.0",
      "outputs": {
        "out": {
          "path": "ingcvxr7h0zwgw1f0vyg41yr9xwi034j-patchelf-0.18.0"
        }
      },
      "system": "builtin",
      "version": 4
    }
  },
  "version": 4
}

The main reason for this is to provide a derivation that other derivations can depend on (e.g. a flake can depend on a baked flake and use its outputs as derivation inputs normally). This is inspired by #408.

Context

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 140cfe5d-00f8-4217-a531-496a7e744941

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch eelcodolstra/nix-379

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

@github-actions github-actions Bot temporarily deployed to pull request May 6, 2026 22:08 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant