Skip to content

Conversation

@vic
Copy link
Owner

@vic vic commented Nov 8, 2025

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 merges currentContext // { 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.

Copilot AI review requested due to automatic review settings November 8, 2025 06:24
Copy link

Copilot AI left a 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.nix by removing the noExtras constraint and redundant empty check
  • 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.

@vic vic changed the title WIP: contexts can be incremental and non-strict. contexts can be incremental and non-strict. Nov 8, 2025
@vic vic changed the title contexts can be incremental and non-strict. contexts are not strict now Nov 8, 2025
@vic vic marked this pull request as ready for review November 8, 2025 08:11
Copilot AI review requested due to automatic review settings November 8, 2025 08:11
@vic vic merged commit e4a7c7c into main Nov 8, 2025
8 checks passed
@vic vic deleted the incremental branch November 8, 2025 08:12
Copy link

Copilot AI left a 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
Copy link

Copilot AI Nov 8, 2025

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.

Suggested change
givenAttrs && satisfied
(lib.length args == 0) || (givenAttrs && satisfied)

Copilot uses AI. Check for mistakes.
Comment on lines +74 to +75
home = root: { home, ... }: den._.import-tree "${toString root}/${home.name}";
user = root: { host, user, ... }: den._.import-tree "${toString root}/${user.name}@${host.name}";
Copy link

Copilot AI Nov 8, 2025

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.

Suggested change
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}";

Copilot uses AI. Check for mistakes.
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.

No-named args function is always called.

2 participants