forked from clan/clan-core
lib: eval clan module as lib function
This commit is contained in:
parent
294c5548b9
commit
13c3169b41
|
@ -5,6 +5,7 @@
|
|||
...
|
||||
}:
|
||||
{
|
||||
evalClanModules = import ./eval-clan-modules { inherit clan-core nixpkgs lib; };
|
||||
jsonschema = import ./jsonschema { inherit lib; };
|
||||
modules = import ./description.nix { inherit clan-core lib; };
|
||||
buildClan = import ./build-clan { inherit clan-core lib nixpkgs; };
|
||||
|
|
34
lib/eval-clan-modules/default.nix
Normal file
34
lib/eval-clan-modules/default.nix
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
nixpkgs,
|
||||
clan-core,
|
||||
lib,
|
||||
}:
|
||||
let
|
||||
inherit (import nixpkgs { system = "x86_64-linux"; }) pkgs;
|
||||
|
||||
inherit (clan-core) clanModules;
|
||||
|
||||
baseModule = {
|
||||
imports = (import (pkgs.path + "/nixos/modules/module-list.nix")) ++ [
|
||||
{
|
||||
nixpkgs.hostPlatform = "x86_64-linux";
|
||||
clan.core.clanName = "dummy";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# This function takes a list of module names and evaluates them
|
||||
# evalClanModules :: [ String ] -> { config, options, ... }
|
||||
evalClanModules =
|
||||
modulenames:
|
||||
let
|
||||
evaled = lib.evalModules {
|
||||
modules = [
|
||||
baseModule
|
||||
clan-core.nixosModules.clanCore
|
||||
] ++ (map (name: clanModules.${name}) modulenames);
|
||||
};
|
||||
in
|
||||
evaled;
|
||||
in
|
||||
evalClanModules
|
|
@ -7,7 +7,7 @@
|
|||
{
|
||||
imports = [ ./jsonschema/flake-module.nix ];
|
||||
flake.lib = import ./default.nix {
|
||||
inherit lib;
|
||||
inherit lib inputs;
|
||||
inherit (inputs) nixpkgs;
|
||||
clan-core = self;
|
||||
};
|
||||
|
|
|
@ -10,37 +10,21 @@
|
|||
# borgbackup = self.clanModules.borgbackup;
|
||||
# };
|
||||
|
||||
baseModule = {
|
||||
imports = (import (pkgs.path + "/nixos/modules/module-list.nix")) ++ [
|
||||
{
|
||||
nixpkgs.hostPlatform = "x86_64-linux";
|
||||
clan.core.clanName = "dummy";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
optionsFromModule =
|
||||
modulename: module:
|
||||
mName:
|
||||
let
|
||||
evaled = lib.evalModules {
|
||||
modules = [
|
||||
module
|
||||
baseModule
|
||||
self.nixosModules.clanCore
|
||||
];
|
||||
};
|
||||
eval = self.lib.evalClanModules [ mName ];
|
||||
in
|
||||
# Filter out "injected" options that are not part of the module
|
||||
if (evaled.options.clan ? "${modulename}") then evaled.options.clan.${modulename} else { };
|
||||
if (eval.options.clan ? "${mName}") then eval.options.clan.${mName} else { };
|
||||
|
||||
clanModuleSchemas = lib.mapAttrs (
|
||||
modulename: module: self.lib.jsonschema.parseOptions (optionsFromModule modulename module)
|
||||
modulename: _: self.lib.jsonschema.parseOptions (optionsFromModule modulename)
|
||||
) clanModules;
|
||||
|
||||
clanModuleFunctionSchemas = lib.mapAttrsFlatten (modulename: module: {
|
||||
clanModuleFunctionSchemas = lib.mapAttrsFlatten (modulename: _: {
|
||||
name = modulename;
|
||||
description = self.lib.modules.getShortDescription modulename;
|
||||
parameters = self.lib.jsonschema.parseOptions (optionsFromModule modulename module);
|
||||
parameters = self.lib.jsonschema.parseOptions (optionsFromModule modulename);
|
||||
}) clanModules;
|
||||
in
|
||||
rec {
|
||||
|
|
Loading…
Reference in New Issue
Block a user