Skip to content

Add schema roles - #40

Merged
edolstra merged 3 commits into
mainfrom
roles
Oct 23, 2025
Merged

edolstra merged 3 commits into
mainfrom
roles

Conversation

@edolstra

@edolstra edolstra commented Mar 1, 2025 •

Copy link
Copy Markdown
Collaborator

Roles allow schemas to declare what commands operate on them. For instance, the nix-build role means that the nix build command should try to build the corresponding flake output.

This means that Nix commands no longer need a hard-coded list of attrpath prefixes and default attrpaths, and it makes them extensible. For instance, we could specify that nixosConfigurations should have the nix-build role, e.g. nix build would try to build nixosConfigurations.default, and nix build machine would try to build nixosConfigurations.machine.

This also adds a schema for the bundlers flake output, since that is now needed for nix bundle to work.

Summary by CodeRabbit

  • New Features
    • Introduced bundlers output support for Nix configurations.
    • Added role-based system configuration across multiple output schemas.
    • Enhanced system-append capabilities for improved configuration management.
    • Added default attribute path settings for standardized configuration access.

Roles allow schemas to declare what commands operate on them. For
instance, the `nix-build` role means that the `nix build` command
should try to build the corresponding flake output.

This means that Nix commands no longer need a hard-coded list of
attrpath prefixes and default attrpaths, and it makes them extensible.
@lucperkins

lucperkins commented Mar 20, 2025 •

Copy link
Copy Markdown
Member

@edolstra Are the available roles an enum known in advance? If so, could roles be specified as a list of strings instead?

{
  roles = [ "nix-build" "nix-develop" "nix-run" ];
}

Requiring an empty attribute à la roles.nix-build = {} would seem slightly awkward if so, but of course would make sense if the intention is to enable passing arbitrary information into the role.

Comment thread flake.nix Resolved
@coderabbitai

coderabbitai Bot commented Oct 23, 2025 •

Copy link
Copy Markdown

Walkthrough

This PR introduces role-based configuration across multiple flake output schemas and adds a new bundlersSchema output. The changes assign roles (e.g., nix-run, nix-build, nix-develop, nix-fmt, nix-bundler, nix-template) and append system support to existing and new schemas, with configurable default attribute paths.

Changes

Cohort / File(s) Summary
Existing schema role enhancements
flake.nix
Added roles, appendSystem, and defaultAttrPath to appsSchema, packagesSchema, legacyPackagesSchema, devShellsSchema, formatterSchema, and templatesSchema. Added comment placeholder to checksSchema.
New bundlers output schema
flake.nix
Introduced bundlersSchema with nix-bundler role, appendSystem, defaultAttrPath, and inventory function that builds a nested system-to-bundler mapping. Wired bundlersSchema into exported schemas mapping.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

The changes follow a consistent pattern across multiple schemas within a single file, with repetitive role and system configuration additions and one new schema definition. The logic is straightforward with minimal complexity, though the breadth of similar modifications warrants verification of correctness across all schemas.

Poem

🐰 A bundler springs forth from the nix, with roles assigned so clear,
Schemas bloom with appendSystem true, and defaults reappear,
Nix-run and nix-build dance about, while bundlers take their stand,
Each system nested, each role blessed—a flake of organized land! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Add schema roles" directly and accurately describes the primary change in the changeset. The core innovation is the introduction of "roles" across multiple schemas, enabling command-to-output mappings and extensibility. The title is concise, clear, and specific—a teammate scanning the repository history would immediately understand that role-based configuration is being added to schemas. While the changeset also includes other changes like adding appendSystem, defaultAttrPath, and a new bundlersSchema, these are supporting implementations of the core roles feature. The title appropriately focuses on the main innovation without attempting to enumerate every detail, which aligns with the stated expectations.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch roles

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

@edolstra

Copy link
Copy Markdown
Collaborator Author

@lucperkins Yeah, the roles are attrsets to allow information to be added to them in the future. I don't have a particular use case in mind for that at the moment, though.

@edolstra
edolstra requested a review from lucperkins October 23, 2025 13:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
flake.nix (1)

359-385: New bundlersSchema structure is correct; consider enhanced validation.

The schema structure is consistent with other schemas and correctly includes the nix-bundler role, appendSystem, and defaultAttrPath. However, the validation at line 379 only checks builtins.isFunction bundler—it doesn't verify the bundler signature or behavior. Since bundlers should accept a derivation and return a bundled output, consider whether stricter validation is feasible without causing evaluation overhead.

Note: A past review comment already addressed the doc string at line 362.

🧹 Nitpick comments (1)
flake.nix (1)

151-151: Address the FIXME: add role for checks.

The FIXME comment indicates that a role should be added for the checksSchema. Since checks are built by nix flake check, consider whether a dedicated role (e.g., nix-check or nix-flake-check) should be defined.

Do you want me to open an issue to track this, or would you like suggestions on which role(s) should be assigned to checks?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0e74ee and e7fdf03.

📒 Files selected for processing (1)
  • flake.nix (9 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: flake-check
🔇 Additional comments (7)
flake.nix (7)

41-43: Role additions look correct for apps.

The nix-run role, appendSystem, and defaultAttrPath are appropriate for the apps schema. However, consider the feedback from lucperkins about role syntax—if roles don't carry additional data, a simpler list-based syntax like roles = [ "nix-run" ] might be more ergonomic than roles.nix-run = { }.

Based on PR comments


79-83: LGTM: Packages correctly support multiple roles.

Assigning nix-build, nix-run, and nix-develop roles to packages makes sense since packages can be built, executed, and used in development environments.


101-103: Verify the absence of defaultAttrPath for legacyPackages.

Unlike packagesSchema (line 83), legacyPackagesSchema doesn't specify a defaultAttrPath. Given that the doc describes legacyPackages as "similar to packages but different in that it can be nested," confirm whether the absence of defaultAttrPath is intentional due to the nested structure, or if it should default to [ "default" ] like packages.


160-162: LGTM: Dev shells correctly configured.

The nix-develop role, appendSystem, and defaultAttrPath are appropriate for development environments.


171-173: Verify the empty defaultAttrPath for formatter.

The formatterSchema uses defaultAttrPath = [ ] (empty list), unlike other schemas that use [ "default" ]. Confirm this is intentional—it may indicate that nix fmt should not attempt a default lookup, or it could reflect that the output is formatter (singular) rather than formatters (plural with named entries).


193-194: LGTM: Templates correctly omit appendSystem.

The nix-template role and defaultAttrPath are appropriate. The absence of appendSystem is correct since templates are not system-specific.


436-436: LGTM: Bundlers schema correctly exported.

The bundlers schema is properly wired into the exported schemas mapping.

@edolstra
edolstra merged commit 26b5002 into main Oct 23, 2025
@edolstra
edolstra deleted the roles branch October 23, 2025 14:30
@coderabbitai coderabbitai Bot mentioned this pull request Feb 12, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Mar 10, 2026
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