Skip to content

feat(core): add typing of core aspect keys in strict mode#449

Open
DylanRJohnston wants to merge 5 commits intodenful:mainfrom
DylanRJohnston:dylan.johnston/strict-mode
Open

feat(core): add typing of core aspect keys in strict mode#449
DylanRJohnston wants to merge 5 commits intodenful:mainfrom
DylanRJohnston:dylan.johnston/strict-mode

Conversation

@DylanRJohnston
Copy link
Copy Markdown
Collaborator

Follow up from #428, when I actually went to use this in my config I found that all the core aspect classes were missing explicit typing.

Comment thread nix/lib/strict.nix Outdated
Comment on lines +33 to +36
den.schema.aspect.options.os = lib.mkOption {
type = lib.types.deferredModule;
default = { };
};
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if it's possible, but it would be cool to only include the schema if the provider is being used. I think the only way to do it would be to turn it into a flakeModule?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it is possible right now, aspects/providers cannot influence higher levels schemas, I'd like to know if someone finds a way to have that. could enable things like an aspect setting a host entity attribute if possible.

Do we need to make this options.os presence optional here? If so I guess you are right about flakeModules.

Comment thread nix/flakeOutputs.nix
Comment thread nix/strict.nix
Comment on lines +8 to +11
defaultClasses.options = {
nixos = moduleOption;
darwin = moduleOption;
};
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Didn't know where to stick these base aspect class definitions, I don't think they should stay here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can move those to /modules, those classes are very common, and we will likely always have those definitions loaded, so just create a file for them at modules.

Comment on lines +197 to +219
test-aspect-wsl = denTest (
{ inputs, igloo, ... }:
{
imports = [
inputs.den.flakeModules.strict
inputs.den.flakeOutputs.all
];

den.hosts.x86_64-linux.igloo = {
wsl.enable = true;
users.tux = { };
};

den.aspects.igloo.wsl.defaultUser = "igloo";

expr =
if inputs ? nixos-wsl then
igloo.wsl.defaultUser
else
lib.warn "nixos-wsl not found in inputs, skipping test `strict-mode.flakeModule.test-aspect-wsl" "igloo";
expected = "igloo";
}
);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

nixos-wsl isn't in our imports and nix-unit doesn't have a concept of "skipping a test for a reason", so this is the nearest thing I could come up with.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since nixos-wsl is not at inputs, we set host.wsl.module to a deferredModule that defines only wsl.enable and wsl.defaultUser, see files features/*wsl* for tests.

@DylanRJohnston DylanRJohnston changed the title feat(flakeModules/strict): add typing of core aspect keys in strict mode feat(core): add typing of core aspect keys in strict mode Apr 13, 2026
Comment thread nix/lib/strict.nix
throw ''
STRICT MODE
explanation =
if lib.lists.hasPrefix [ "flake" ] path then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think using these ifs is the right way to do this, but I dont quite like large if branches, I'd prefer to have messages assigned as let bindings and have a short if chain at the end referencing those messages, that we can have visibility of what the if condition is doing.

inherit (den.lib.ctxTypes nsCtxApply) ctxTreeType;
in
{
imports = [ (den.schema.namespace or { }) ];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

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