From 68a571f8586173b09df507a24cc4d244a5990bc0 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 4 Oct 2024 13:47:46 +0200 Subject: [PATCH] Interfaces: unclutter meta interface, file conflict position tracking --- lib/build-clan/interface.nix | 15 +++------ lib/build-clan/module.nix | 11 +++++-- lib/inventory/build-inventory/interface.nix | 31 +++++++------------ .../build-inventory/meta-interface.nix | 25 +++++++++++++++ 4 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 lib/inventory/build-inventory/meta-interface.nix diff --git a/lib/build-clan/interface.nix b/lib/build-clan/interface.nix index 16f56cf31..60c2ceb31 100644 --- a/lib/build-clan/interface.nix +++ b/lib/build-clan/interface.nix @@ -63,17 +63,10 @@ in description = '' Global information about the clan. ''; - type = types.nullOr ( - types.submodule { - options = { - name = lib.mkOption { - type = types.nullOr types.str; - description = "Needs to be (globally) unique, as this determines the folder name where the flake gets downloaded to."; - }; - }; - } - ); - default = null; + type = types.deferredModuleWith { + staticModules = [ ../inventory/build-inventory/meta-interface.nix ]; + }; + default = { }; }; pkgsForSystem = lib.mkOption { diff --git a/lib/build-clan/module.nix b/lib/build-clan/module.nix index 9f92ca691..4c3aed454 100644 --- a/lib/build-clan/module.nix +++ b/lib/build-clan/module.nix @@ -222,7 +222,12 @@ in { imports = [ # Merge the inventory file - { inventory = inventoryLoaded; } + { + inventory = _: { + _file = inventoryFile; + config = inventoryLoaded; + }; + } # TODO: Figure out why this causes infinite recursion { inventory.machines = lib.optionalAttrs (builtins.pathExists "${directory}/machines") ( @@ -235,7 +240,9 @@ in inventory.machines = lib.mapAttrs (_n: _: { }) config.machines; } # Merge the meta attributes from the buildClan function - { inventory.meta = if config.meta != null then config.meta else { }; } + # + # config.inventory.meta <- config.meta + { inventory.meta = config.meta; } ]; inherit nixosConfigurations; diff --git a/lib/inventory/build-inventory/interface.nix b/lib/inventory/build-inventory/interface.nix index 363417464..7ce60c89a 100644 --- a/lib/inventory/build-inventory/interface.nix +++ b/lib/inventory/build-inventory/interface.nix @@ -1,24 +1,7 @@ -{ config, lib, ... }: +{ lib, ... }: let types = lib.types; - metaOptions = { - name = lib.mkOption { type = types.str; }; - description = lib.mkOption { - default = null; - type = types.nullOr types.str; - description = '' - Optional freeform description - ''; - }; - icon = lib.mkOption { - default = null; - type = types.nullOr types.str; - description = '' - Under construction, will be used for the UI - ''; - }; - }; metaOptionsWith = name: { name = lib.mkOption { type = types.str; @@ -45,6 +28,8 @@ let moduleConfig = lib.mkOption { default = { }; + # TODO: use types.deferredModule + # clan.borgbackup MUST be defined as submodule type = types.attrsOf types.anything; description = '' Configuration of the specific clanModule. @@ -102,6 +87,7 @@ let }; in { + imports = [ ./assertions.nix ]; options = { assertions = lib.mkOption { @@ -110,7 +96,13 @@ in visible = false; default = [ ]; }; - meta = metaOptions; + meta = lib.mkOption { + type = lib.types.submoduleWith { + modules = [ + ./meta-interface.nix + ]; + }; + }; machines = lib.mkOption { description = '' @@ -189,6 +181,7 @@ in type = types.attrsOf ( types.attrsOf ( types.submodule ( + # instance name { name, ... }: { options.meta = metaOptionsWith name; diff --git a/lib/inventory/build-inventory/meta-interface.nix b/lib/inventory/build-inventory/meta-interface.nix new file mode 100644 index 000000000..69ebecef3 --- /dev/null +++ b/lib/inventory/build-inventory/meta-interface.nix @@ -0,0 +1,25 @@ +{ lib, ... }: +let + types = lib.types; + + metaOptions = { + name = lib.mkOption { type = types.nullOr types.str; }; + description = lib.mkOption { + default = null; + type = types.nullOr types.str; + description = '' + Optional freeform description + ''; + }; + icon = lib.mkOption { + default = null; + type = types.nullOr types.str; + description = '' + Under construction, will be used for the UI + ''; + }; + }; +in +{ + options = metaOptions; +}