dynix/modules/dynamicism/lib.nix

25 lines
905 B
Nix
Raw Normal View History

2026-02-06 17:12:02 +01:00
{
lib ? import <nixpkgs/lib>,
}: let
t = lib.types;
in lib.fix (self: {
/** Perform module-system type checking and resolving on a single option value. */
2026-02-16 18:02:39 +01:00
typeCheck = loc: optionType: value:
assert lib.isOptionType optionType;
2026-02-06 17:12:02 +01:00
assert lib.isList loc;
assert lib.all lib.isString loc;
let
2026-02-16 18:02:39 +01:00
merged = lib.modules.mergeDefinitions loc optionType [ {
2026-02-06 17:12:02 +01:00
inherit value;
file = "«inline»";
} ];
in merged.mergedValue;
/** Either a list of strings, or a dotted string that will be split. */
convenientAttrPath = t.coercedTo t.str (lib.splitString ".") (t.listOf t.str);
concatFoldl = f: list: lib.foldl' (acc: value: acc ++ (f value)) [ ] list;
recUpdateFoldl = f: list: lib.foldl' (acc: value: lib.recursiveUpdate acc (f value)) { } list;
recUpdateFoldlAttrs = f: attrs: lib.foldlAttrs (acc: name: value: lib.recursiveUpdate acc (f name value)) { } attrs;
})