Skip to content

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

Closed
DylanRJohnston wants to merge 5 commits into
denful:mainfrom
DylanRJohnston:dylan.johnston/strict-mode
Closed

feat(core): add typing of core aspect keys in strict mode#449
DylanRJohnston wants to merge 5 commits into
denful: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.

👍

@vic
Copy link
Copy Markdown
Member

vic commented May 10, 2026

Hey @DylanRJohnston we have finally merged The Big fx-pipeline branch #475. Do you want me to rebase and solve conflicts so we can keep progress on this ?

@sini
Copy link
Copy Markdown
Collaborator

sini commented May 11, 2026

Hello @DylanRJohnston I could use your review on:
https://github.com/sini/den-schema/ => https://github.com/sini/den-schema/tree/main/templates/demo

Will this satisfy your needs if we swap the current entity system for it?

Also any review feedback you have on the design or implementation is 100% welcome.

@DylanRJohnston
Copy link
Copy Markdown
Collaborator Author

Apologies @sini and @vic work has gotten really busy these last few weeks and I haven't had the chance to come back and finish this work off. I'd say you can close this PR for now although strict mode isn't very useful without it. I'll have to fix it when I get around to updating my config

@sini
Copy link
Copy Markdown
Collaborator

sini commented May 12, 2026

@DylanRJohnston no worries. If you have time to look at den-schema, it's a ground-up clean-room re-implementation of den's schema library that we're going to be subbing in and I believe it should cover your use-case requirements.

Soliciting review to confirm that. :)

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.

3 participants