Merge pull request 'chore(lib/getModuleClass): remove unused library function' (#3250) from hsjobeki/clan-core:lib-cleanup into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3250
This commit is contained in:
@@ -3,8 +3,6 @@
|
|||||||
## Add any logic to ./module.nix
|
## Add any logic to ./module.nix
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
nixpkgs,
|
|
||||||
nix-darwin ? null,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
@@ -35,7 +33,10 @@
|
|||||||
buildClanWith =
|
buildClanWith =
|
||||||
{
|
{
|
||||||
clan-core,
|
clan-core,
|
||||||
|
# TODO: Below should be module options such that the user can override them?
|
||||||
|
nixpkgs,
|
||||||
publicAttrs ? import ./public.nix,
|
publicAttrs ? import ./public.nix,
|
||||||
|
nix-darwin ? null,
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|||||||
@@ -15,11 +15,14 @@ lib.fix (clanLib: {
|
|||||||
*/
|
*/
|
||||||
callLib = file: args: import file ({ inherit lib clanLib; } // args);
|
callLib = file: args: import file ({ inherit lib clanLib; } // args);
|
||||||
|
|
||||||
buildClan = clanLib.buildClanModule.buildClanWith { clan-core = self; };
|
buildClan = clanLib.buildClanModule.buildClanWith {
|
||||||
|
clan-core = self;
|
||||||
|
inherit nixpkgs nix-darwin;
|
||||||
|
};
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
# ClanLib functions
|
# ClanLib functions
|
||||||
evalClan = clanLib.callLib ./inventory/eval-clan-modules { };
|
evalClan = clanLib.callLib ./inventory/eval-clan-modules { };
|
||||||
buildClanModule = clanLib.callLib ./build-clan { inherit nixpkgs nix-darwin; };
|
buildClanModule = clanLib.callLib ./build-clan { };
|
||||||
inventory = clanLib.callLib ./inventory { };
|
inventory = clanLib.callLib ./inventory { };
|
||||||
modules = clanLib.callLib ./inventory/frontmatter { };
|
modules = clanLib.callLib ./inventory/frontmatter { };
|
||||||
|
|
||||||
|
|||||||
@@ -39,45 +39,4 @@
|
|||||||
acc ++ tagMembers
|
acc ++ tagMembers
|
||||||
) [ ] members.tags or [ ]);
|
) [ ] members.tags or [ ]);
|
||||||
};
|
};
|
||||||
/**
|
|
||||||
Checks whether a module has a specific class
|
|
||||||
|
|
||||||
# Arguments
|
|
||||||
- `module` The module to check.
|
|
||||||
|
|
||||||
# Returns
|
|
||||||
- `string` | null: The specified class, or null if the class is not set
|
|
||||||
|
|
||||||
# Throws
|
|
||||||
- If the module is not a valid module
|
|
||||||
- If the module has a type that is not supported
|
|
||||||
*/
|
|
||||||
getModuleClass =
|
|
||||||
module:
|
|
||||||
let
|
|
||||||
loadModuleForClassCheck =
|
|
||||||
m:
|
|
||||||
# Logic path adapted from nixpkgs/lib/modules.nix
|
|
||||||
if lib.isFunction m then
|
|
||||||
let
|
|
||||||
args = lib.functionArgs m;
|
|
||||||
in
|
|
||||||
m args
|
|
||||||
else if lib.isAttrs m then
|
|
||||||
# module doesn't have a _type attribute
|
|
||||||
if m._type or "module" == "module" then
|
|
||||||
m
|
|
||||||
# module has a _type set but it is not "module"
|
|
||||||
else if m._type == "if" || m._type == "override" then
|
|
||||||
throw "Module modifiers are not supported yet. Got: ${m._type}"
|
|
||||||
else
|
|
||||||
throw "Unsupported module type ${lib.typeOf m}"
|
|
||||||
else if lib.isList m then
|
|
||||||
throw "Invalid or unsupported module type ${lib.typeOf m}"
|
|
||||||
else
|
|
||||||
import m;
|
|
||||||
|
|
||||||
loaded = loadModuleForClassCheck module;
|
|
||||||
in
|
|
||||||
if loaded ? _class then loaded._class else null;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ let
|
|||||||
resolvedModule =
|
resolvedModule =
|
||||||
resolvedModuleSet.${instance.module.name}
|
resolvedModuleSet.${instance.module.name}
|
||||||
or (throw "flake doesn't provide clan-module with name ${instance.module.name}");
|
or (throw "flake doesn't provide clan-module with name ${instance.module.name}");
|
||||||
moduleClass = clanLib.inventory.getModuleClass resolvedModule;
|
|
||||||
|
|
||||||
# Every instance includes machines via roles
|
# Every instance includes machines via roles
|
||||||
# :: { client :: ... }
|
# :: { client :: ... }
|
||||||
@@ -113,7 +112,7 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit (instance) module;
|
inherit (instance) module;
|
||||||
inherit resolvedModule instanceRoles moduleClass;
|
inherit resolvedModule instanceRoles;
|
||||||
}
|
}
|
||||||
) inventory.instances;
|
) inventory.instances;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user