Skip to content

Add nix flake bake command - #450

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

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

Conversation

@edolstra

@edolstra edolstra commented May 6, 2026

Copy link
Copy Markdown
Collaborator

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

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
✨ 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.

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request May 6, 2026 22:08 Inactive
@edolstra
edolstra force-pushed the eelcodolstra/nix-379 branch from addfe06 to 41804e6 Compare June 29, 2026 10:08
@github-actions
github-actions Bot temporarily deployed to pull request June 29, 2026 10:15 Inactive
@vivekanandan-ks

Copy link
Copy Markdown

I think this will help and complement farid's multiverse project🔥

https://github.com/fzakaria/nixpkgs-multiverse

@github-actions
github-actions Bot temporarily deployed to pull request September 7, 2026 13:55 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.

2 participants