Skip to content

fix(core): an optional context arg with no context takes its default - #769

Merged
sini merged 1 commit into
mainfrom
fix/optional-absent-ctx-arg
Nov 16, 2026
Merged

sini merged 1 commit into
mainfrom
fix/optional-absent-ctx-arg

Conversation

@sini

@sini sini commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Reported by @vipultyagi in Matrix: a class module that takes an optional context arg with no context in scope, next to one that is in scope, throws as soon as the absent one is read.

den.aspects.feature.homeManager = { home ? null, user ? null, ... }: {
  programs.atuin.enable = home == null;
};
error: attribute 'home' missing
… while evaluating the module argument `home' in "homeManager@feature/{user=tux}:anon-1":
… noting that argument `home` is not externally provided, so querying `_module.args` instead

Their diagnosis was right. Taking a context arg that den has (user) makes wrapFunctionModule wrap the module, and the wrapper advertised every arg it didn't supply itself to the module system, including the absent optional home. The module system then looked home up in _module.args. With home ? null alone the module isn't wrapped, stripEnrichmentArgs drops the defaulted arg, and it works, which is why the single-arg form hid this. The same happens on nixos: { user ? null, host ? null, ... }: on a host's own aspect throws on user.

Fix. wrapFunctionModule doesn't advertise an optional arg that names an entity kind and has no context here; it's den's to supply, and its default applies. Required ones still take the existing "requests '…' but no … context" path, and optional args that aren't entity kinds still reach the module system as in nixpkgs.

Validation

  • New cells, templates/ci/modules/deadbugs/optional-absent-context-arg.nix:

    • home ? null alone (control, passes on main too);
    • home ? null, user ? null, the reported case;
    • home ? null, user, config, the wrapper path that also passes module-system args;
    • user ? null, host ? null on nixos.

    The last three fail on main and pass here.

  • Full suite (ci.bash, 4 workers): 2208/2208.

A class module taking a context arg den supplies is wrapped, and the wrapper advertised every other arg to the module system, including an optional entity-kind arg with no context here (home ? null on a host user). The module system then looked it up in _module.args and threw once it was read. Don't advertise those; their default applies.

Reported in Matrix.
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Nov 16, 2026
@sini
sini merged commit 9dcee08 into main Nov 16, 2026
17 checks passed
@sini
sini deleted the fix/optional-absent-ctx-arg branch November 16, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-ci allow all CI integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant