Repository navigation
Issue with aspect settings and quirks #776
|
I'm trying to add aspect with settings and when any part of aspect chain has the same name as any defined quirk, the setting for this aspect won't be created. Could anyone look into it and confirm if it's intended behavior or just a bug? Here is the test example: { denTest, ... }:
{
flake.tests.bogus = {
test-something = denTest (
{ den, lib, igloo, ... }:
{
den.reservedKeys = [ "settings" ];
den.schema.host.imports = [
{
# Aspect settings https://den.denful.dev/guides/aspect-settings/
options.settings = lib.mkOption {
type = import ./_settings-type.nix { inherit den lib; };
default = { };
description = "Per-aspect typed settings";
};
}
];
den.aspects.my.awesome-aspect = {
settings.something = lib.mkOption { type = lib.types.str; };
nixos = { host, ... }: { environment.variables.TEST_SETTINGS = host.settings.my.awesome-aspect.something; };
};
den.aspects.igloo.includes = [ den.aspects.my.awesome-aspect ];
den.hosts.x86_64-linux.igloo.settings.my.awesome-aspect.something = "The Penguin";
# !!! comment this line and the test will work
den.quirks.my.description = "some test quirk";
expr = igloo.environment.variables.TEST_SETTINGS;
expected = "The Penguin";
}
);
};
}Error is: |
Replies: 4 comments 1 reply
|
The pipeline is fine here, it's the skipKey = k:
isStructuralKey k
|| (den.classes or { }) ? ${k}
|| (den.quirks or { }) ? ${k};and Since the generator is your own copy, you can only skip quirk and class names below the root: nodeModule = isRoot: node:
let
own = reshape (node.settings or { });
skip = k: if isRoot then isStructuralKey k else skipKey k;
children = lib.filterAttrs
(k: v: !(skip k) && builtins.isAttrs v && hasSettingsDeep v) node;
in
{
imports = own.imports or [ ];
config = own.config or { };
options = (own.options or { }) // lib.mapAttrs (name: child:
mkOption {
type = types.submodule (nodeModule false child);
default = { };
description = "Settings under ${name}";
}) children;
};
in
types.submodule (nodeModule true (den.aspects or { }))If you'd rather not touch it, renaming either the quirk or the top-level aspect so they don't share a name works too. |
|
Thanks for the report, and +1 to @Manishram-ai's diagnosis. I wrote the aspect-settings pattern and the Two things I want to fix beyond the root-level skip:
Until then, Manishram's patch above is the right fix for your copy. As a data point on why it deserves a home in den: beyond plain options, a |
|
Follow-up on the plan: until den ships a proper builtin settings type, I'll keep the guide's example generator as the definition to copy, and I'm updating it now:
I've checked the new generator against this discussion's exact test, which now returns "The Penguin". It also gives the named error for a nested collision, and leaves the derivations of a large real config unchanged. I'll link the docs PR here when it's up. If you copied the generator, swap in the new one from the guide once that lands; until then, Manishram's patch fixes the root case. |
|
The docs fix is up: #777. It replaces the guide's generator with the corrected one and adds den CI cells for this discussion's exact case and for the nested collision, which fail on the old generator. My own nix-config already runs the same generator. Until a builtin settings type ships, the guide's example is the one to copy. |
The pipeline is fine here, it's the
_settings-type.nixgenerator from the guide that drops it. ItsskipKeyskips any key that matches a quirk (or class) name:and
nodeModuleuses it at every level, including the very top where it walksden.aspectsitself. So withden.quirks.mydefined, the top-level aspectmyis filtered out,host.settings.mynever gets declared, and yoursettings.my.awesome-aspect.somethinghas nowhere to go. Inside an aspect that skip makes sense (a key named like a quirk really is quirk data there, and key-classification.nix treats it as a pipe key too), but the keys ofd…