Skip to content

chore: split default.nix and main.nix#403

Open
MattSturgeon wants to merge 3 commits into
NixOS:masterfrom
MattSturgeon:split-entrypoint
Open

chore: split default.nix and main.nix#403
MattSturgeon wants to merge 3 commits into
NixOS:masterfrom
MattSturgeon:split-entrypoint

Conversation

@MattSturgeon
Copy link
Copy Markdown
Contributor

@MattSturgeon MattSturgeon commented May 22, 2026

Followup to #401 where I noticed that nix flake show requires IFD.

This PR delays merging the default package into the top-level default attrset, and avoids needing to evaluate the actual package (currently using IFD) in order to compute flake outputs.

This fixes nix flake show when allow-import-from-derivation is false.

The previous behaviour (nix-build without arguments building the default package and nix-build -A having access to specific attributes) is retained.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 22, 2026

Nixpkgs diff processing..

Will be available here

Copy link
Copy Markdown
Collaborator

@jfly jfly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, although this will cause conflicts with my upgrade PR :( That's fine, I can rebase.

I feel like I've seen ci.nix or release.nix as alternate names for this main.nix file, if you were searching for something idiomatic. No big deal either way.

Have you confirmed that the attrset returned by default.nix is an exact match (or superset) of the attrset previously returned? I haven't read the code carefully enough to confirm.

Comment thread default.nix
Comment on lines 1 to +5
{
system ? builtins.currentSystem,
nixpkgs ? sources.nixpkgs,
serokell-nix ? sources.serokell-nix,
}:
system ? null,
nixpkgs ? null,
serokell-nix ? null,
}@args:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This smells a little odd to me. Why not do args: ...? Are you trying to preserve the old behavior of not accepting any other keys? Could use a brief comment if that's why.

Copy link
Copy Markdown
Contributor Author

@MattSturgeon MattSturgeon May 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit ugly, but it is a pretty common pattern in nix.

Here, we use it for a few orthoganal reasons.

The main reason we use it here is that nix-build (etc) can fill in named set-pattern arguments, which is why nix-build or nix-instantiate without arguments can evaluate the existing default.nix before this PR.

We could also solve that by not taking an args at all (like in shell.nix), but that breaks the other useages; supplying --arg or --argstr to nix-build or importing the file and calling it with a {} argument.

I'll add a comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Mirror main.nix's function arguments for nix-command --arg support

to default.nix and

NOTE: update mirrored args in default.nix when modifying

to main.nix.

@MattSturgeon
Copy link
Copy Markdown
Contributor Author

MattSturgeon commented May 23, 2026

I feel like I've seen ci.nix or release.nix as alternate names for this main.nix file, if you were searching for something idiomatic. No big deal either way.

I wouldn't choose ci.nix, because this is unrelated to CI. I could see an argument for release.nix, as these are our "public" entrypoints. I feel like main.nix also expresses that well, without conflating it with tagged-releases?

I see main.nix as the central semi-internal/semi-public orchestration point of our public outputs, used by flake.nix, default.nix, shell.nix, and internal scripts.

In preparation for the next commit, this temporarily removes
`default.nix`.
This restores the `default.nix` entrypoint removed in commit
80089fc

The `build // { /* other attrs */ }` update is moved out of `main.nix`
and into `default.nix`, so that the main package can be evaluated lazily.

As the main package relies on IFD, this allows other consumers of
`main.nix` to evaluate without `allow-import-from-derivation`.

For example, this fixes `nix flake show` when
`allow-import-from-derivation = false`.
@MattSturgeon
Copy link
Copy Markdown
Contributor Author

I split up the commit history a bit more, so when rebasing or blaming git will now recognize default.nix -> main.nix as a rename. This should mean most conflicts can be resolved automatically.

@MattSturgeon
Copy link
Copy Markdown
Contributor Author

@jfly the nixpkgs-diff CI failure is expected here, because it runs from the default-branch's context and the this PR's changes to scripts/sync-pr-support.nix don't affect it.

That means the one commit where default.nix is removed fails to evaluate, leading to the CI failure.

I laid out the commits that way intentionally, so that git recognises the "old" default.nix was renamed to main.nix and then the next commit introduces a "new" default.nix.

If we want to merge this with the sane git history, you'll need to bypass the rulesets and force-merge (as repo admin).

Incidentally, any other PRs based on a revision that doesn't have a main.nix will also fail nixpkgs-diff once this merges; at least, until they rebase. Because the default branch will at that point be trying to import main.nix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants