mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-09-06 10:21:31 +00:00
clean up lib
This commit is contained in:
parent
4442408ee3
commit
fbd08add99
7 changed files with 12 additions and 55 deletions
68
lib/types/dag.nix
Normal file
68
lib/types/dag.nix
Normal file
|
@ -0,0 +1,68 @@
|
|||
# From home-manager: https://github.com/nix-community/home-manager/blob/master/modules/lib/types-dag.nix
|
||||
# Used for ordering config text.
|
||||
{lib}: let
|
||||
inherit
|
||||
(lib)
|
||||
defaultFunctor
|
||||
nvim
|
||||
mkIf
|
||||
mkOrder
|
||||
mkOption
|
||||
mkOptionType
|
||||
types
|
||||
;
|
||||
|
||||
dagEntryOf = elemType: let
|
||||
submoduleType = types.submodule ({name, ...}: {
|
||||
options = {
|
||||
data = mkOption {type = elemType;};
|
||||
after = mkOption {type = with types; listOf str;};
|
||||
before = mkOption {type = with types; listOf str;};
|
||||
};
|
||||
config = mkIf (elemType.name == "submodule") {
|
||||
data._module.args.dagName = name;
|
||||
};
|
||||
});
|
||||
maybeConvert = def:
|
||||
if nvim.dag.isEntry def.value
|
||||
then def.value
|
||||
else
|
||||
nvim.dag.entryAnywhere (
|
||||
if def ? priority
|
||||
then mkOrder def.priority def.value
|
||||
else def.value
|
||||
);
|
||||
in
|
||||
mkOptionType {
|
||||
name = "dagEntryOf";
|
||||
description = "DAG entry of ${elemType.description}";
|
||||
# leave the checking to the submodule type
|
||||
merge = loc: defs:
|
||||
submoduleType.merge loc (map (def: {
|
||||
inherit (def) file;
|
||||
value = maybeConvert def;
|
||||
})
|
||||
defs);
|
||||
};
|
||||
in rec {
|
||||
# A directed acyclic graph of some inner type.
|
||||
#
|
||||
# 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`.
|
||||
dagOf = elemType: let
|
||||
attrEquivalent = types.attrsOf (dagEntryOf elemType);
|
||||
in
|
||||
mkOptionType rec {
|
||||
name = "dagOf";
|
||||
description = "DAG of ${elemType.description}";
|
||||
inherit (attrEquivalent) check merge emptyValue;
|
||||
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name>"]);
|
||||
getSubModules = elemType.getSubModules;
|
||||
substSubModules = m: dagOf (elemType.substSubModules m);
|
||||
functor = (defaultFunctor name) // {wrapped = elemType;};
|
||||
nestedTypes.elemType = elemType;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue