{ lib, plugins, startPlugins, optPlugins, ... }: let inherit (lib) partition filter concatLists subtractLists unique flatten attrValues pipe isDerivation ; partitionPlugins = plugs: let parts = partition (elem: elem.passthru.start or false) plugs; in { start = parts.right; opt = parts.wrong; }; partitionedPlugins = pipe plugins [ attrValues (filter isDerivation) partitionPlugins ]; # find deps # see https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/utils/vim-utils.nix#L159-L164 transitiveClosure = plugin: [ plugin ] ++ (lib.unique (concatLists (map transitiveClosure plugin.dependencies or [ ]))); findDependenciesRecursively = plugins: lib.concatMap transitiveClosure plugins; start' = flatten [ partitionedPlugins.start startPlugins ]; opt = flatten [ partitionedPlugins.opt optPlugins ]; depsOfOptionalPlugins = subtractLists opt (findDependenciesRecursively opt); startWithDeps = findDependenciesRecursively start'; in { start = unique (startWithDeps ++ depsOfOptionalPlugins); inherit opt; }