Repository navigation
Conversation
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.
|
@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 |
Co-authored-by: Luc Perkins <[email protected]>
WalkthroughThis PR introduces role-based configuration across multiple flake output schemas and adds a new Changes
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
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
|
@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. |
There was a problem hiding this comment.
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-bundlerrole,appendSystem, anddefaultAttrPath. However, the validation at line 379 only checksbuiltins.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. Sincechecksare built bynix flake check, consider whether a dedicated role (e.g.,nix-checkornix-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
📒 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-runrole,appendSystem, anddefaultAttrPathare 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 likeroles = [ "nix-run" ]might be more ergonomic thanroles.nix-run = { }.Based on PR comments
79-83: LGTM: Packages correctly support multiple roles.Assigning
nix-build,nix-run, andnix-developroles to packages makes sense since packages can be built, executed, and used in development environments.
101-103: Verify the absence ofdefaultAttrPathfor legacyPackages.Unlike
packagesSchema(line 83),legacyPackagesSchemadoesn't specify adefaultAttrPath. Given that the doc describes legacyPackages as "similar topackagesbut different in that it can be nested," confirm whether the absence ofdefaultAttrPathis intentional due to the nested structure, or if it should default to[ "default" ]like packages.
160-162: LGTM: Dev shells correctly configured.The
nix-developrole,appendSystem, anddefaultAttrPathare appropriate for development environments.
171-173: Verify the emptydefaultAttrPathfor formatter.The
formatterSchemausesdefaultAttrPath = [ ](empty list), unlike other schemas that use[ "default" ]. Confirm this is intentional—it may indicate thatnix fmtshould not attempt a default lookup, or it could reflect that the output isformatter(singular) rather thanformatters(plural with named entries).
193-194: LGTM: Templates correctly omit appendSystem.The
nix-templaterole anddefaultAttrPathare appropriate. The absence ofappendSystemis 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.
Roles allow schemas to declare what commands operate on them. For instance, the
nix-buildrole means that thenix buildcommand 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
nixosConfigurationsshould have thenix-buildrole, e.g.nix buildwould try to buildnixosConfigurations.default, andnix build machinewould try to buildnixosConfigurations.machine.This also adds a schema for the
bundlersflake output, since that is now needed fornix bundleto work.Summary by CodeRabbit