chore(lib/modulesDocs): move dependency on clan-core and pkgs into function args

This is a good idea, to make lib agnostic from clan-core
The next step could be to rename the clan-core argument name
Or to explizitly pass the actual dependencies, instead of everything in
clan-core
This commit is contained in:
Johannes Kirschbauer
2025-04-04 18:50:56 +02:00
parent 97049d187c
commit ce84c4cddb
4 changed files with 47 additions and 24 deletions

View File

@@ -13,8 +13,14 @@
# { clanCore = «derivation JSON»; clanModules = { ${name} = «derivation JSON» }; }
jsonDocs = pkgs.callPackage ./get-module-docs.nix {
inherit (self) clanModules;
clan-core = self;
inherit pkgs;
evalClanModules = self.lib.evalClan.evalClanModules;
modulesRolesOptions = self.lib.evalClan.evalClanModulesWithRoles self.clanModules;
modulesRolesOptions = self.lib.evalClan.evalClanModulesWithRoles {
allModules = self.clanModules;
inherit pkgs;
clan-core = self;
};
};
# Frontmatter for clanModules

View File

@@ -4,6 +4,8 @@
clanModules,
evalClanModules,
lib,
pkgs,
clan-core,
}:
{
# clanModules docs
@@ -11,7 +13,12 @@
name: module:
if builtins.pathExists (module + "/default.nix") then
(nixosOptionsDoc {
options = ((evalClanModules [ module ]).options).clan.${name} or { };
options =
((evalClanModules {
modules = [ module ];
inherit pkgs clan-core;
}).options
).clan.${name} or { };
warningsAreErrors = true;
}).optionsJSON
else
@@ -31,7 +38,12 @@
clanCore =
(nixosOptionsDoc {
options = ((evalClanModules [ ]).options).clan.core or { };
options =
((evalClanModules {
modules = [ ];
inherit pkgs clan-core;
}).options
).clan.core or { };
warningsAreErrors = true;
}).optionsJSON;
}

View File

@@ -9,25 +9,21 @@
# 'clanLib' attribute set
# Wrapped with fix, so we can depend on other clanLib functions without passing the whole flake
lib.fix (clanLib: {
# TODO:
# SSome bad lib functions that depend on something in 'self'.
# We should reduce the dependency on 'self' aka the 'flake' object
# This makes it easier to test
# most of the time passing the whole flake is unnecessary
/**
Like callPackage, but doesn't try to automatically detect arguments
'lib' and 'clanLib' are always passed, plus the additional arguments
*/
callLib = file: args: import file ({ inherit lib clanLib; } // args);
evalClan = import ./inventory/eval-clan-modules {
inherit lib;
clan-core = self;
pkgs = nixpkgs.legacyPackages.x86_64-linux;
};
buildClanModule = clanLib.callLib ./build-clan { inherit nixpkgs nix-darwin; };
buildClan = clanLib.buildClanModule.buildClanWith { clan-core = self; };
# ------------------------------------
# Lib functions that don't depend on 'self'
# ClanLib functions
evalClan = clanLib.callLib ./inventory/eval-clan-modules { };
buildClanModule = clanLib.callLib ./build-clan { inherit nixpkgs nix-darwin; };
inventory = clanLib.callLib ./inventory { };
modules = clanLib.callLib ./inventory/frontmatter { };
# Plain imports.
values = import ./introspection { inherit lib; };
jsonschema = import ./jsonschema { inherit lib; };
select = import select/default.nix;

View File

@@ -1,10 +1,11 @@
{
clan-core,
lib,
pkgs,
clanLib,
}:
let
baseModule =
{ pkgs }:
# Module
{ config, ... }:
{
imports = (import (pkgs.path + "/nixos/modules/module-list.nix"));
@@ -20,11 +21,15 @@ let
# This function takes a list of module names and evaluates them
# [ module ] -> { config, options, ... }
evalClanModulesLegacy =
modules:
{
modules,
pkgs,
clan-core,
}:
let
evaled = lib.evalModules {
modules = [
baseModule
(baseModule { inherit pkgs; })
{
clan.core.settings.directory = clan-core;
}
@@ -56,16 +61,20 @@ let
}
*/
evalClanModulesWithRoles =
allModules:
{
allModules,
clan-core,
pkgs,
}:
let
res = builtins.mapAttrs (
moduleName: module:
let
frontmatter = clan-core.lib.modules.getFrontmatter allModules.${moduleName} moduleName;
frontmatter = clanLib.modules.getFrontmatter allModules.${moduleName} moduleName;
roles =
if builtins.elem "inventory" frontmatter.features or [ ] then
assert lib.isPath module;
clan-core.lib.modules.getRoles allModules moduleName
clanLib.modules.getRoles allModules moduleName
else
[ ];
in
@@ -75,7 +84,7 @@ let
value =
(lib.evalModules {
modules = [
baseModule
(baseModule { inherit pkgs; })
clan-core.nixosModules.clanCore
{
clan.core.settings.directory = clan-core;