{ self, lib, inputs, config, ... }: let inherit (lib) concatMapAttrs mapAttrs; inherit (builtins) readFileType pathExists readDir; inherit (lib.strings) hasSuffix removeSuffix; readModules = dir: if pathExists "${dir}.nix" && readFileType "${dir}.nix" == "regular" then {default = dir;} else if pathExists dir && readFileType dir == "directory" then concatMapAttrs ( entry: type: let dirDefault = "${dir}/${entry}/default.nix"; in if type == "regular" && hasSuffix ".nix" entry then {${removeSuffix ".nix" entry} = "${dir}/${entry}";} else if pathExists dirDefault && readFileType dirDefault == "regular" then {${entry} = dirDefault;} else {} ) (readDir dir) else {}; droidConfigs = lib.filterAttrs (name: val: val.droid != null) config.hosts; hardwareConfigs = mapAttrs (name: config: config.hardware) (lib.filterAttrs (name: val: val.hardware != null) config.hosts); hostByNet = net: (lib.foldlAttrs (acc: name: val: acc ++ ( if val.net == net then [name] else [] )) [] hardwareConfigs); in { options = { nex = { lib = lib.mkOption { type = lib.types.attrs; default = {}; }; hardwareConfigs = lib.mkOption { type = lib.types.attrs; default = {}; }; }; }; config = { nex = { inherit hardwareConfigs; lib = { inherit readModules hostByNet; }; }; }; }