-
-
Notifications
You must be signed in to change notification settings - Fork 5
contexts are not strict now #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the function parameter matching logic to be more flexible by allowing functions with ... (rest parameters) to match contexts with extra unused parameters. Previously, the canTake function enforced exact parameter matching, rejecting functions when the context had parameters the function didn't explicitly list.
Key changes:
- Simplified
fn-can-take.nixby removing thenoExtrasconstraint and redundantemptycheck - Updated function signatures throughout the codebase to use
...for flexibility - Updated test expectations to reflect the new permissive matching behavior
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| nix/fn-can-take.nix | Removed strict parameter matching logic; now only checks that required parameters are satisfied |
| templates/default/modules/_profile/profiles.nix | Added ... to function signature for flexible parameter matching |
| templates/default/modules/_example/aspects.nix | Added ... to function signature for flexible parameter matching |
| modules/aspects/provides/import-tree.nix | Added ... to host/home functions and # deadnix: skip comment; user function missing ... for consistency |
| modules/aspects/provides/home-manager.nix | Added ... to function signature for flexible parameter matching |
| modules/aspects/dependencies.nix | Added ... to multiple function signatures where flexible matching is appropriate |
| checkmate/tests/function_can_take.nix | Updated test expectation from false to true for function with extra parameters |
| checkmate/tests/aspect-functor.nix | Updated test expectations to include additional matched functions due to relaxed matching |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| noExtas = lib.length required == lib.length provided; | ||
| in | ||
| empty || (givenAttrs && satisfied && noExtas) | ||
| givenAttrs && satisfied |
Copilot
AI
Nov 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function now returns true when param is not an attribute set (when givenAttrs is false), making the result false regardless of satisfied. However, the logic removed the empty check which previously allowed functions with no arguments to accept any parameter. Functions with no named arguments (like _any: {...} or x: x) should still be able to accept any input. Consider returning (lib.length args == 0) || (givenAttrs && satisfied) to preserve this behavior.
| givenAttrs && satisfied | |
| (lib.length args == 0) || (givenAttrs && satisfied) |
| home = root: { home, ... }: den._.import-tree "${toString root}/${home.name}"; | ||
| user = root: { host, user, ... }: den._.import-tree "${toString root}/${user.name}@${host.name}"; |
Copilot
AI
Nov 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The order of provides entries has been changed without explanation. Previously the order was host, user, home, now it's host, home, user. If this ordering has semantic significance (e.g., evaluation order), consider maintaining the original order for consistency. If intentional, this is fine.
| home = root: { home, ... }: den._.import-tree "${toString root}/${home.name}"; | |
| user = root: { host, user, ... }: den._.import-tree "${toString root}/${user.name}@${host.name}"; | |
| user = root: { host, user, ... }: den._.import-tree "${toString root}/${user.name}@${host.name}"; | |
| home = root: { home, ... }: den._.import-tree "${toString root}/${home.name}"; |
This is a preparation PR for contexts being incremental,
an aspect can add (merge) additional data to an existing context.
for example, a host configuration starts with
{ host }but later for each of it users it mergescurrentContext // { user }leading to{ host, user }augmented context.This allows contexts to be incremental, so parametric-aspects (functions) can specify what is the context they need:
{ user, ...}- At least user data in context.{ user, host, gaming }- Need the three of them.Will invalidate and close #51.
Breaking Change
Your existing functions taking context like
{ host }will likely need to be{ host, ... }now. See this PR diff for how batteries were updated.