dynix/modules/dynamicism/lib.nix
2026-02-17 19:48:53 +01:00

37 lines
1.2 KiB
Nix

{
lib ? import <nixpkgs/lib>,
}: let
t = lib.types;
in lib.fix (self: {
/** Perform module-system type checking and resolving on a single option value. */
typeCheck = loc: optionType: value:
assert lib.isOptionType optionType;
assert lib.isList loc;
assert lib.all lib.isString loc;
let
merged = lib.modules.mergeDefinitions loc optionType [ {
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);
executablePathInStore = lib.mkOptionType {
name = "exepath";
description = "executable path in the Nix store";
descriptionClass = "noun";
merge = lib.mergeEqualOption;
functor = lib.defaultFunctor "exepath";
check = x: if lib.isDerivation x then (
x.meta.mainProgram or null != null
) else (
lib.pathInStore.check x
);
};
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;
})