2020-01-14 23:41:59 +01:00
|
|
|
{ dag, lib }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
isDagEntry = e: isAttrs e && (e ? data) && (e ? after) && (e ? before);
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
dagContentType = elemType:
|
|
|
|
types.submodule {
|
|
|
|
options = {
|
|
|
|
data = mkOption { type = elemType; };
|
|
|
|
after = mkOption { type = with types; uniq (listOf str); };
|
|
|
|
before = mkOption { type = with types; uniq (listOf str); };
|
|
|
|
};
|
2020-01-14 23:41:59 +01:00
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2020-01-14 23:41:59 +01:00
|
|
|
# A directed acyclic graph of some inner type.
|
|
|
|
dagOf = elemType:
|
|
|
|
let
|
2020-02-02 00:39:17 +01:00
|
|
|
convertAllToDags = let
|
|
|
|
maybeConvert = n: v: if isDagEntry v then v else dag.entryAnywhere v;
|
|
|
|
in map (def: def // { value = mapAttrs maybeConvert def.value; });
|
2020-01-14 23:41:59 +01:00
|
|
|
|
|
|
|
attrEquivalent = types.attrsOf (dagContentType elemType);
|
2020-02-02 00:39:17 +01:00
|
|
|
in mkOptionType rec {
|
|
|
|
name = "dagOf";
|
|
|
|
description = "DAG of ${elemType.description}s";
|
|
|
|
check = isAttrs;
|
|
|
|
merge = loc: defs: attrEquivalent.merge loc (convertAllToDags defs);
|
|
|
|
getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "<name>" ]);
|
|
|
|
getSubModules = elemType.getSubModules;
|
|
|
|
substSubModules = m: dagOf (elemType.substSubModules m);
|
|
|
|
functor = (defaultFunctor name) // { wrapped = elemType; };
|
|
|
|
};
|
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
|
|
|
|
|
|
|
convertAllToDags = defs:
|
|
|
|
let
|
|
|
|
convertAttrValue = n: v:
|
2020-02-02 00:39:17 +01:00
|
|
|
if isDagEntry v then v else dag.entryAnywhere v;
|
2020-01-14 23:41:59 +01:00
|
|
|
|
|
|
|
convertListValue = namePrefix: vs:
|
|
|
|
let
|
|
|
|
pad = paddedIndexStr vs;
|
|
|
|
makeEntry = i: v:
|
|
|
|
nameValuePair "${namePrefix}.${pad i}" (dag.entryAnywhere v);
|
2020-02-02 00:39:17 +01:00
|
|
|
in listToAttrs (imap1 makeEntry vs);
|
2020-01-14 23:41:59 +01:00
|
|
|
|
|
|
|
convertValue = i: value:
|
2020-02-02 00:39:17 +01:00
|
|
|
if isList value then
|
|
|
|
convertListValue "unnamed-${paddedIndexStr defs i}" value
|
|
|
|
else
|
|
|
|
mapAttrs convertAttrValue value;
|
|
|
|
in imap1 (i: def: def // { value = convertValue i def.value; }) defs;
|
2020-01-14 23:41:59 +01:00
|
|
|
|
|
|
|
attrEquivalent = types.attrsOf (dagContentType elemType);
|
2020-02-02 00:39:17 +01:00
|
|
|
in mkOptionType rec {
|
|
|
|
name = "dagOf";
|
|
|
|
description = "DAG of ${elemType.description}s";
|
|
|
|
check = x: isAttrs x || isList x;
|
|
|
|
merge = loc: defs: attrEquivalent.merge loc (convertAllToDags defs);
|
|
|
|
getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "<name>" ]);
|
|
|
|
getSubModules = elemType.getSubModules;
|
|
|
|
substSubModules = m: dagOf (elemType.substSubModules m);
|
|
|
|
functor = (defaultFunctor name) // { wrapped = elemType; };
|
|
|
|
};
|
2020-01-14 23:41:59 +01:00
|
|
|
}
|