2022-01-13 18:21:32 +01:00
|
|
|
{ lib }:
|
2020-01-14 23:41:59 +01:00
|
|
|
|
|
|
|
let
|
2021-10-27 13:58:56 +02:00
|
|
|
inherit (lib)
|
2022-01-13 18:21:32 +01:00
|
|
|
concatStringsSep defaultFunctor fixedWidthNumber hm imap1 isAttrs isList
|
|
|
|
length listToAttrs mapAttrs mkIf mkOrder mkOption mkOptionType nameValuePair
|
2022-05-09 19:50:15 +02:00
|
|
|
stringLength types warn;
|
2020-01-14 23:41:59 +01:00
|
|
|
|
2022-03-23 05:01:52 +01:00
|
|
|
dagEntryOf = elemType:
|
|
|
|
let
|
|
|
|
submoduleType = types.submodule ({ name, ... }: {
|
|
|
|
options = {
|
|
|
|
data = mkOption { type = elemType; };
|
2022-05-09 19:50:15 +02:00
|
|
|
after = mkOption { type = with types; listOf str; };
|
|
|
|
before = mkOption { type = with types; listOf str; };
|
2022-03-23 05:01:52 +01:00
|
|
|
};
|
|
|
|
config = mkIf (elemType.name == "submodule") {
|
|
|
|
data._module.args.dagName = name;
|
|
|
|
};
|
|
|
|
});
|
2022-05-09 19:50:15 +02:00
|
|
|
maybeConvert = def:
|
2022-01-13 18:21:32 +01:00
|
|
|
if hm.dag.isEntry def.value then
|
2022-05-09 19:50:15 +02:00
|
|
|
def.value
|
|
|
|
else
|
2022-01-13 18:21:32 +01:00
|
|
|
hm.dag.entryAnywhere (if def ? priority then
|
2022-05-09 19:50:15 +02:00
|
|
|
mkOrder def.priority def.value
|
|
|
|
else
|
|
|
|
def.value);
|
2022-03-23 05:01:52 +01:00
|
|
|
in mkOptionType {
|
|
|
|
name = "dagEntryOf";
|
|
|
|
description = "DAG entry of ${elemType.description}";
|
|
|
|
# leave the checking to the submodule type
|
|
|
|
merge = loc: defs:
|
2022-05-09 19:50:15 +02:00
|
|
|
submoduleType.merge loc (map (def: {
|
|
|
|
inherit (def) file;
|
|
|
|
value = maybeConvert def;
|
|
|
|
}) defs);
|
2022-03-23 05:01:52 +01:00
|
|
|
};
|
2020-01-14 23:41:59 +01:00
|
|
|
|
2020-04-13 22:01:20 +02:00
|
|
|
in rec {
|
2020-01-14 23:41:59 +01:00
|
|
|
# A directed acyclic graph of some inner type.
|
2020-04-13 22:01:20 +02:00
|
|
|
#
|
|
|
|
# Note, if the element type is a submodule then the `name` argument
|
|
|
|
# will always be set to the string "data" since it picks up the
|
|
|
|
# internal structure of the DAG values. To give access to the
|
|
|
|
# "actual" attribute name a new submodule argument is provided with
|
|
|
|
# the name `dagName`.
|
2020-01-14 23:41:59 +01:00
|
|
|
dagOf = elemType:
|
2022-03-23 05:01:52 +01:00
|
|
|
let attrEquivalent = types.attrsOf (dagEntryOf elemType);
|
2020-02-02 00:39:17 +01:00
|
|
|
in mkOptionType rec {
|
|
|
|
name = "dagOf";
|
2022-05-09 19:50:15 +02:00
|
|
|
description = "DAG of ${elemType.description}";
|
2022-03-23 05:01:52 +01:00
|
|
|
inherit (attrEquivalent) check merge emptyValue;
|
2020-02-02 00:39:17 +01:00
|
|
|
getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "<name>" ]);
|
|
|
|
getSubModules = elemType.getSubModules;
|
|
|
|
substSubModules = m: dagOf (elemType.substSubModules m);
|
|
|
|
functor = (defaultFunctor name) // { wrapped = elemType; };
|
2022-03-23 05:01:52 +01:00
|
|
|
nestedTypes.elemType = elemType;
|
2020-02-02 00:39:17 +01:00
|
|
|
};
|
2020-01-14 23:41:59 +01:00
|
|
|
}
|