Merge pull request 'Chore(clanInternals): remove unused attributes' (#3925) from hsjobeki/clanInternals into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3925
This commit is contained in:
@@ -13,16 +13,15 @@ let
|
|||||||
|
|
||||||
publicAttrs = import ../lib/build-clan/public.nix;
|
publicAttrs = import ../lib/build-clan/public.nix;
|
||||||
# Create output options only for listed attributes
|
# Create output options only for listed attributes
|
||||||
|
# TODO: Refactor this into an explicit module, so we can have description and other attributes to be listed in flake-parts
|
||||||
outputModule = {
|
outputModule = {
|
||||||
clan = lib.genAttrs publicAttrs.clan (
|
clan = lib.genAttrs publicAttrs.clan (
|
||||||
name:
|
name: config.clan.${name} or (throw "Output: clan.${name} not found.")
|
||||||
config.clan.clanInternals.${name}
|
|
||||||
or (throw "Output: clanInternals.${name} not found. Check: ${config.file}")
|
|
||||||
);
|
);
|
||||||
topLevel = {
|
topLevel = {
|
||||||
options = lib.genAttrs publicAttrs.topLevel (_: lib.mkOption { });
|
options = lib.genAttrs publicAttrs.topLevel (_: lib.mkOption { });
|
||||||
config = lib.genAttrs publicAttrs.topLevel (
|
config = lib.genAttrs publicAttrs.topLevel (
|
||||||
name: config.clan.${name} or (throw "Output: clan.${name} not found. See: ${config.file}")
|
name: config.clan.${name} or (throw "Output: clan.${name} not found.")
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -198,24 +198,21 @@ in
|
|||||||
options = {
|
options = {
|
||||||
# Those options are interfaced by the CLI
|
# Those options are interfaced by the CLI
|
||||||
# We don't specify the type here, for better performance.
|
# We don't specify the type here, for better performance.
|
||||||
inventory = lib.mkOption { type = lib.types.raw; };
|
|
||||||
# all exported clan templates from this clan
|
|
||||||
templates = lib.mkOption { type = lib.types.raw; };
|
|
||||||
# all exported clan modules from this clan
|
|
||||||
modules = lib.mkOption { type = lib.types.raw; };
|
|
||||||
# all inventory module schemas
|
|
||||||
inventoryFile = lib.mkOption { type = lib.types.raw; };
|
|
||||||
# The machine 'imports' generated by the inventory per machine
|
|
||||||
inventoryClass = lib.mkOption { type = lib.types.raw; };
|
|
||||||
evalServiceSchema = lib.mkOption { };
|
|
||||||
# clan-core's modules
|
# clan-core's modules
|
||||||
clanModules = lib.mkOption { type = lib.types.raw; };
|
clanModules = lib.mkOption { type = lib.types.raw; };
|
||||||
source = lib.mkOption { type = lib.types.raw; };
|
|
||||||
meta = lib.mkOption { type = lib.types.raw; };
|
# The machine 'imports' generated by the inventory per machine
|
||||||
|
inventoryClass = lib.mkOption { type = lib.types.raw; };
|
||||||
|
|
||||||
|
# TODO: remove all dependents in python, delete this option
|
||||||
|
inventory = lib.mkOption {
|
||||||
|
type = lib.types.raw;
|
||||||
|
apply = lib.warn "The 'clanInternals.inventory' option is deprecated, use 'clanInternals.inventoryClass' instead.";
|
||||||
|
};
|
||||||
|
|
||||||
secrets = lib.mkOption { type = lib.types.raw; };
|
secrets = lib.mkOption { type = lib.types.raw; };
|
||||||
clanLib = lib.mkOption { type = lib.types.raw; };
|
|
||||||
machines = lib.mkOption { type = lib.types.raw; };
|
machines = lib.mkOption { type = lib.types.raw; };
|
||||||
all-machines-json = lib.mkOption { type = lib.types.raw; };
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -133,24 +133,28 @@ let
|
|||||||
) supportedSystems
|
) supportedSystems
|
||||||
);
|
);
|
||||||
|
|
||||||
inventoryFile = "${directory}/inventory.json";
|
|
||||||
|
|
||||||
inventoryLoaded =
|
|
||||||
if builtins.pathExists inventoryFile then
|
|
||||||
(builtins.fromJSON (builtins.readFile inventoryFile))
|
|
||||||
else
|
|
||||||
{ };
|
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
# Merge the inventory file
|
(
|
||||||
|
{ ... }:
|
||||||
|
let
|
||||||
|
file = "${directory}/inventory.json";
|
||||||
|
|
||||||
|
inventoryLoaded =
|
||||||
|
if builtins.pathExists file then (builtins.fromJSON (builtins.readFile file)) else { };
|
||||||
|
in
|
||||||
{
|
{
|
||||||
inventory = _: {
|
imports = [
|
||||||
_file = inventoryFile;
|
{
|
||||||
config = inventoryLoaded;
|
inventory._inventoryFile = file;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
];
|
||||||
|
# Weirdly this works only if it is a function
|
||||||
|
# This seems to be a bug in nixpkgs
|
||||||
|
inventory = _: lib.setDefaultModuleLocation file inventoryLoaded;
|
||||||
|
}
|
||||||
|
)
|
||||||
{
|
{
|
||||||
# TODO: Figure out why this causes infinite recursion
|
# TODO: Figure out why this causes infinite recursion
|
||||||
inventory.machines = lib.optionalAttrs (builtins.pathExists "${directory}/machines") (
|
inventory.machines = lib.optionalAttrs (builtins.pathExists "${directory}/machines") (
|
||||||
@@ -238,38 +242,18 @@ in
|
|||||||
|
|
||||||
clanInternals = {
|
clanInternals = {
|
||||||
inherit inventoryClass;
|
inherit inventoryClass;
|
||||||
|
inventory = config.inventory;
|
||||||
# Endpoint that can be called to get a service schema
|
|
||||||
evalServiceSchema = clan-core.clanLib.evalServiceSchema config.self;
|
|
||||||
|
|
||||||
# TODO: unify this interface
|
# TODO: unify this interface
|
||||||
# We should have only clan.modules. (consistent with clan.templates)
|
# We should have only clan.modules. (consistent with clan.templates)
|
||||||
inherit (clan-core) clanModules clanLib;
|
inherit (clan-core) clanModules;
|
||||||
modules = config.modules;
|
|
||||||
|
|
||||||
inherit inventoryFile;
|
|
||||||
|
|
||||||
templates = config.templates;
|
templates = config.templates;
|
||||||
inventory = config.inventory;
|
|
||||||
# TODO: Remove this in about a month
|
|
||||||
# It is only here for backwards compatibility for people with older CLI versions
|
|
||||||
inventoryValuesPrios = inventoryClass.introspection;
|
|
||||||
meta = config.inventory.meta;
|
|
||||||
secrets = config.secrets;
|
|
||||||
|
|
||||||
source = "${clan-core}";
|
secrets = config.secrets;
|
||||||
|
|
||||||
# machine specifics
|
# machine specifics
|
||||||
machines = configsPerSystem;
|
machines = configsPerSystem;
|
||||||
all-machines-json =
|
|
||||||
lib.trace "Your clan-cli and the clan-core input have incompatible versions" lib.mapAttrs
|
|
||||||
(
|
|
||||||
system: configs:
|
|
||||||
nixpkgs.legacyPackages.${system}.writers.writeJSON "machines.json" (
|
|
||||||
lib.mapAttrs (_: m: m.config.system.clan.deployment.data) configs
|
|
||||||
)
|
|
||||||
)
|
|
||||||
configsPerSystem;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
This list is used to guarantee equivalent attribute sets for both flake-parts and buildClan users.
|
This list is used to guarantee equivalent attribute sets for both flake-parts and buildClan users.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
# flake.clan.{name} <- clanInternals.{name}
|
# flake.clan.{name} <- clan.{name}
|
||||||
clan = [
|
clan = [
|
||||||
"templates"
|
"templates"
|
||||||
"modules"
|
"modules"
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ in
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
expr = config.clanInternals.meta;
|
expr = config.clanInternals.inventory.meta;
|
||||||
expected = {
|
expected = {
|
||||||
description = null;
|
description = null;
|
||||||
icon = null;
|
icon = null;
|
||||||
@@ -108,35 +108,8 @@ in
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
expr = result.clanInternals.meta;
|
expr = lib.isAttrs result.clanInternals;
|
||||||
expected = {
|
expected = true;
|
||||||
description = null;
|
|
||||||
icon = null;
|
|
||||||
name = "test";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
test_fn_extensiv_meta =
|
|
||||||
let
|
|
||||||
result = buildClan {
|
|
||||||
self = {
|
|
||||||
inputs = { };
|
|
||||||
};
|
|
||||||
directory = ./.;
|
|
||||||
meta.name = "test";
|
|
||||||
meta.description = "test";
|
|
||||||
meta.icon = "test";
|
|
||||||
inventory.meta.name = "superclan";
|
|
||||||
inventory.meta.description = "description";
|
|
||||||
inventory.meta.icon = "icon";
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
expr = result.clanInternals.meta;
|
|
||||||
expectedError = {
|
|
||||||
type = "ThrownError";
|
|
||||||
msg = "";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
test_fn_clan_core =
|
test_fn_clan_core =
|
||||||
|
|||||||
@@ -97,6 +97,12 @@ in
|
|||||||
./assertions.nix
|
./assertions.nix
|
||||||
];
|
];
|
||||||
options = {
|
options = {
|
||||||
|
_inventoryFile = lib.mkOption {
|
||||||
|
type = types.path;
|
||||||
|
readOnly = true;
|
||||||
|
internal = true;
|
||||||
|
visible = false;
|
||||||
|
};
|
||||||
_legacyModules = lib.mkOption {
|
_legacyModules = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
visible = false;
|
visible = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user