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:
hsjobeki
2025-04-08 20:54:46 +00:00
4 changed files with 9 additions and 47 deletions

View File

@@ -3,8 +3,6 @@
## Add any logic to ./module.nix
{
lib,
nixpkgs,
nix-darwin ? null,
...
}:
{
@@ -35,7 +33,10 @@
buildClanWith =
{
clan-core,
# TODO: Below should be module options such that the user can override them?
nixpkgs,
publicAttrs ? import ./public.nix,
nix-darwin ? null,
}:
{
## Inputs

View File

@@ -15,11 +15,14 @@ lib.fix (clanLib: {
*/
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
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 { };
modules = clanLib.callLib ./inventory/frontmatter { };

View File

@@ -39,45 +39,4 @@
acc ++ tagMembers
) [ ] 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;
}

View File

@@ -63,7 +63,6 @@ let
resolvedModule =
resolvedModuleSet.${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
# :: { client :: ... }
@@ -113,7 +112,7 @@ let
in
{
inherit (instance) module;
inherit resolvedModule instanceRoles moduleClass;
inherit resolvedModule instanceRoles;
}
) inventory.instances;