From 42368945660fdf7c928947b4203451fa00abfd1d Mon Sep 17 00:00:00 2001 From: diniamo Date: Mon, 15 Jul 2024 12:15:39 +0200 Subject: [PATCH] treewide: move resolveDag to lib --- lib/dag.nix | 23 +++++++++++++++++++++-- modules/wrapper/rc/config.nix | 25 +++---------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/dag.nix b/lib/dag.nix index ef5b7650..d0659fee 100644 --- a/lib/dag.nix +++ b/lib/dag.nix @@ -8,10 +8,10 @@ # - the addition of the function `entryBefore` indicating a "wanted # by" relationship. {lib}: let - inherit (builtins) isAttrs attrValues attrNames elem all head tail length; + inherit (builtins) isAttrs attrValues attrNames elem all head tail length toJSON isString; inherit (lib.attrsets) filterAttrs mapAttrs; inherit (lib.lists) toposort; - inherit (lib.nvim.dag) empty isEntry entryBetween entryAfter entriesBetween; + inherit (lib.nvim.dag) empty isEntry entryBetween entryAfter entriesBetween entryAnywhere topoSort; in { empty = {}; @@ -146,4 +146,23 @@ in { -- SECTION: ${section.name} ${section.data} ''; + + resolveDag = { + name, + dag, + mapResult, + }: let + # When the value is a string, default it to dag.entryAnywhere + finalDag = mapAttrs (_: value: + if isString value + then entryAnywhere value + else value) + dag; + sortedDag = topoSort finalDag; + result = + if sortedDag ? result + then mapResult sortedDag.result + else abort ("Dependency cycle in ${name}: " + toJSON sortedDag); + in + result; } diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index 90671e57..8b28dc9e 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -3,15 +3,15 @@ lib, ... }: let - inherit (builtins) map mapAttrs toJSON filter; + inherit (builtins) map mapAttrs filter; inherit (lib.options) mkOption; inherit (lib.attrsets) filterAttrs getAttrs attrValues attrNames; - inherit (lib.strings) isString concatLines concatMapStringsSep; + inherit (lib.strings) concatLines concatMapStringsSep; inherit (lib.misc) mapAttrsFlatten; inherit (lib.trivial) showWarnings; inherit (lib.types) str nullOr; inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.dag) entryAnywhere entryAfter topoSort mkLuarcSection; + inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.config) mkBool; @@ -104,25 +104,6 @@ in { omap = toLuaBindings "o" config.vim.maps.operator; icmap = toLuaBindings "ic" config.vim.maps.insertCommand; - resolveDag = { - name, - dag, - mapResult, - }: let - # When the value is a string, default it to dag.entryAnywhere - finalDag = mapAttrs (_: value: - if isString value - then entryAnywhere value - else value) - dag; - sortedDag = topoSort finalDag; - result = - if sortedDag ? result - then mapResult sortedDag.result - else abort ("Dependency cycle in ${name}: " + toJSON sortedDag); - in - result; - extraPluginConfigs = resolveDag { name = "extra plugins config"; dag = mapAttrs (_: value: entryAfter value.after value.setup) cfg.extraPlugins;