nixos/kismet: fix module typechecking

70ab11c2f2 added the new v2 merge, which
performs typechecking at the same time as merging. We need to opt out of
this optimization, as it changes the behavior of the module and results
in eval errors.
This commit is contained in:
Morgan Jones
2025-10-25 17:29:36 -07:00
parent 1acaf6b89b
commit 6b87a0569a

View File

@@ -28,7 +28,14 @@ let
typeOf typeOf
match match
; ;
inherit (lib.lists) all isList flatten; inherit (lib.lists)
all
isList
head
tail
flatten
foldl'
;
inherit (lib.attrsets) inherit (lib.attrsets)
attrsToList attrsToList
filterAttrs filterAttrs
@@ -48,19 +55,60 @@ let
in in
prev prev
// { // {
check = value: prev.check value && (override type value); check =
value:
let
prevResult = builtins.tryEval (prev.check value);
nextResult = builtins.tryEval (override type value);
in
prevResult.success && prevResult.value && nextResult.success && nextResult.value;
# We need to typecheck prior to merging, so deoptimize in case prev.merge is a functor.
merge = opts: prev.merge opts;
}; };
# Deep listOf. # Deep listOf.
listOf' = deep types.listOf (type: value: all type.check value); inherit (types) listOf;
listOf' = deep listOf (type: value: all type.check value);
# Deep attrsOf. # Deep attrsOf.
attrsOf' = deep types.attrsOf (type: value: all (item: type.check item.value) (attrsToList value)); inherit (types) attrsOf;
attrsOf' = deep attrsOf (type: value: all (item: type.check item.value) (attrsToList value));
# Deep either and oneOf that performs typecheck prior to merging.
inherit (types) either;
either' =
first: second:
let
prev = either first second;
in
prev
// {
check =
value:
let
firstResult = builtins.tryEval (first.check value);
secondResult = builtins.tryEval (second.check value);
in
firstResult.success && firstResult.value || secondResult.success && secondResult.value;
# We need to typecheck prior to merging, so deoptimize in case prev.merge is a functor.
merge = opts: prev.merge opts;
};
oneOf' =
ts:
let
head' =
if ts == [ ] then throw "types.oneOf needs to get at least one type in its argument" else head ts;
tail' = tail ts;
in
foldl' either' head' tail';
# Kismet config atoms. # Kismet config atoms.
atom = atom =
with types; with types;
oneOf [ oneOf' [
number number
bool bool
str str
@@ -68,7 +116,10 @@ let
# Composite types. # Composite types.
listOfAtom = listOf' atom; listOfAtom = listOf' atom;
atomOrList = with types; either atom listOfAtom; atomOrList = oneOf' [
atom
listOfAtom
];
lists = listOf' atomOrList; lists = listOf' atomOrList;
kvPair = attrsOf' atomOrList; kvPair = attrsOf' atomOrList;
kvPairs = listOf' kvPair; kvPairs = listOf' kvPair;
@@ -80,19 +131,17 @@ let
# Toplevel config type. # Toplevel config type.
topLevel = topLevel =
let let
topLevel' = topLevel' = oneOf' [
with types; headerKvPairs
oneOf [ headerKvPair
headerKvPairs kvPairs
headerKvPair kvPair
kvPairs listOfAtom
kvPair lists
listOfAtom atom
lists ];
atom
];
in in
topLevel' attrsOf' topLevel'
// { // {
description = "Kismet config stanza"; description = "Kismet config stanza";
}; };
@@ -239,7 +288,7 @@ in
https://www.kismetwireless.net/docs/readme/configuring/configfiles/ https://www.kismetwireless.net/docs/readme/configuring/configfiles/
''; '';
default = { }; default = { };
type = with types; attrsOf topLevel; type = topLevel;
example = literalExpression '' example = literalExpression ''
{ {
/* Examples for atoms */ /* Examples for atoms */