revert Merge pull request 'Remove clanModules/*' (#4202) from remove-modules into main Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4202 See: https://git.clan.lol/clan/clan-core/issues/4365 Not all modules are migrated. If they are not migrated, we need to write migration docs and please display the link to the migration docs
92 lines
2.2 KiB
Nix
92 lines
2.2 KiB
Nix
{
|
|
modulesRolesOptions,
|
|
nixosOptionsDoc,
|
|
clanModules,
|
|
evalClanModules,
|
|
lib,
|
|
pkgs,
|
|
clan-core,
|
|
}:
|
|
let
|
|
inherit (clan-core.clanLib.docs) stripStorePathsFromDeclarations;
|
|
transformOptions = stripStorePathsFromDeclarations;
|
|
in
|
|
{
|
|
# clanModules docs
|
|
clanModulesViaNix = lib.mapAttrs (
|
|
name: module:
|
|
if builtins.pathExists (module + "/default.nix") then
|
|
(nixosOptionsDoc {
|
|
options =
|
|
((evalClanModules {
|
|
modules = [ module ];
|
|
inherit pkgs clan-core;
|
|
}).options
|
|
).clan.${name} or { };
|
|
warningsAreErrors = true;
|
|
inherit transformOptions;
|
|
}).optionsJSON
|
|
else
|
|
{ }
|
|
) clanModules;
|
|
|
|
clanModulesViaRoles = lib.mapAttrs (
|
|
_moduleName: rolesOptions:
|
|
lib.mapAttrs (
|
|
_roleName: options:
|
|
(nixosOptionsDoc {
|
|
inherit options;
|
|
warningsAreErrors = true;
|
|
inherit transformOptions;
|
|
}).optionsJSON
|
|
) rolesOptions
|
|
) modulesRolesOptions;
|
|
|
|
# Test with:
|
|
# nix build .\#legacyPackages.x86_64-linux.clanModulesViaService
|
|
clanModulesViaService = lib.mapAttrs (
|
|
_moduleName: moduleValue:
|
|
let
|
|
evaluatedService = clan-core.clanLib.evalService {
|
|
modules = [ moduleValue ];
|
|
prefix = [ ];
|
|
};
|
|
in
|
|
{
|
|
roles = lib.mapAttrs (
|
|
_roleName: role:
|
|
|
|
(nixosOptionsDoc {
|
|
transformOptions =
|
|
opt:
|
|
let
|
|
# Apply store path stripping first
|
|
transformed = transformOptions opt;
|
|
in
|
|
if lib.strings.hasPrefix "_" transformed.name then
|
|
transformed // { visible = false; }
|
|
else
|
|
transformed;
|
|
options = (lib.evalModules { modules = [ role.interface ]; }).options;
|
|
warningsAreErrors = true;
|
|
}).optionsJSON
|
|
) evaluatedService.config.roles;
|
|
|
|
manifest = evaluatedService.config.manifest;
|
|
|
|
}
|
|
) clan-core.clan.modules;
|
|
|
|
clanCore =
|
|
(nixosOptionsDoc {
|
|
options =
|
|
((evalClanModules {
|
|
modules = [ ];
|
|
inherit pkgs clan-core;
|
|
}).options
|
|
).clan.core or { };
|
|
warningsAreErrors = true;
|
|
inherit transformOptions;
|
|
}).optionsJSON;
|
|
}
|