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
|
|
|
|
|
|
|
# A directed acyclic graph of some inner type OR a list of that
|
|
|
|
# inner type. This is a temporary hack for use by the
|
|
|
|
# `programs.ssh.matchBlocks` and is only guaranteed to be vaguely
|
|
|
|
# correct!
|
|
|
|
#
|
|
|
|
# In particular, adding a dependency on one of the "unnamed-N-M"
|
|
|
|
# entries generated by a list value is almost guaranteed to destroy
|
|
|
|
# the list's order.
|
|
|
|
#
|
|
|
|
# This function will be removed in version 20.09.
|
|
|
|
listOrDagOf = elemType:
|
|
|
|
let
|
|
|
|
paddedIndexStr = list: i:
|
2020-02-02 00:39:17 +01:00
|
|
|
let padWidth = stringLength (toString (length list));
|
|
|
|
in fixedWidthNumber padWidth i;
|
2020-01-14 23:41:59 +01:00
|
|
|
|
2020-04-15 00:31:47 +02:00
|
|
|
convertAll = loc: defs:
|
2020-01-14 23:41:59 +01:00
|
|
|
let
|
2020-04-15 00:31:47 +02:00
|
|
|
convertListValue = namePrefix: def:
|
2020-01-14 23:41:59 +01:00
|
|
|
let
|
2020-04-15 00:31:47 +02:00
|
|
|
vs = def.value;
|
2020-01-14 23:41:59 +01:00
|
|
|
pad = paddedIndexStr vs;
|
2020-04-13 22:01:20 +02:00
|
|
|
makeEntry = i: v: nameValuePair "${namePrefix}.${pad i}" v;
|
2020-04-15 00:31:47 +02:00
|
|
|
warning = ''
|
|
|
|
In file ${def.file}
|
|
|
|
a list is being assigned to the option '${
|
|
|
|
concatStringsSep "." loc
|
|
|
|
}'.
|
|
|
|
This will soon be an error due to the list form being deprecated.
|
|
|
|
Please use the attribute set form instead with DAG functions to
|
|
|
|
express the desired order of entries.
|
|
|
|
'';
|
|
|
|
in warn warning (listToAttrs (imap1 makeEntry vs));
|
2020-01-14 23:41:59 +01:00
|
|
|
|
2020-04-15 00:31:47 +02:00
|
|
|
convertValue = i: def:
|
|
|
|
if isList def.value then
|
|
|
|
convertListValue "unnamed-${paddedIndexStr defs i}" def
|
2020-02-02 00:39:17 +01:00
|
|
|
else
|
2020-04-15 00:31:47 +02:00
|
|
|
def.value;
|
|
|
|
in imap1 (i: def: def // { value = convertValue i def; }) defs;
|
2020-01-14 23:41:59 +01:00
|
|
|
|
2020-04-13 22:01:20 +02:00
|
|
|
dagType = dagOf elemType;
|
2020-02-02 00:39:17 +01:00
|
|
|
in mkOptionType rec {
|
2020-04-13 22:01:20 +02:00
|
|
|
name = "listOrDagOf";
|
|
|
|
description = "list or DAG of ${elemType.description}s";
|
|
|
|
check = x: isList x || dagType.check x;
|
2020-04-15 00:31:47 +02:00
|
|
|
merge = loc: defs: dagType.merge loc (convertAll loc defs);
|
2020-04-13 22:01:20 +02:00
|
|
|
getSubOptions = dagType.getSubOptions;
|
|
|
|
getSubModules = dagType.getSubModules;
|
|
|
|
substSubModules = m: listOrDagOf (elemType.substSubModules m);
|
2020-02-02 00:39:17 +01:00
|
|
|
functor = (defaultFunctor name) // { wrapped = elemType; };
|
|
|
|
};
|
2020-01-14 23:41:59 +01:00
|
|
|
}
|