From 2535fdcb1254c660e47a9d0f2da11fb539ca181a Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 26 Jun 2024 15:16:20 +0200 Subject: [PATCH] Inventory: restructure folders --- lib/description.nix | 2 +- lib/inventory/example.nix | 1 + .../{src/tests => examples}/borgbackup.json | 0 .../{src/tests => examples}/syncthing.json | 0 .../{src/tests => examples}/zerotier.json | 0 lib/inventory/flake-module.nix | 23 ++++++++----------- .../{src => spec}/cue.mod/module.cue | 0 lib/inventory/{src => spec}/root.cue | 0 lib/inventory/{src => spec}/schema/schema.cue | 0 9 files changed, 11 insertions(+), 15 deletions(-) rename lib/inventory/{src/tests => examples}/borgbackup.json (100%) rename lib/inventory/{src/tests => examples}/syncthing.json (100%) rename lib/inventory/{src/tests => examples}/zerotier.json (100%) rename lib/inventory/{src => spec}/cue.mod/module.cue (100%) rename lib/inventory/{src => spec}/root.cue (100%) rename lib/inventory/{src => spec}/schema/schema.cue (100%) diff --git a/lib/description.nix b/lib/description.nix index c4c641e64..4e4ad0817 100644 --- a/lib/description.nix +++ b/lib/description.nix @@ -18,7 +18,7 @@ rec { content = getReadme modulename; parts = lib.splitString "---" content; # Partition the parts into the first part (the readme content) and the rest (the metadata) - parsed = builtins.partition ({ index }: if index >= 2 then false else true) ( + parsed = builtins.partition ({ index, ... }: if index >= 2 then false else true) ( lib.filter ({ index, ... }: index != 0) (lib.imap0 (index: part: { inherit index part; }) parts) ); diff --git a/lib/inventory/example.nix b/lib/inventory/example.nix index 50b417923..f7a7154ef 100644 --- a/lib/inventory/example.nix +++ b/lib/inventory/example.nix @@ -19,6 +19,7 @@ self.lib.buildClan { machines = { "backup_server" = { clan.tags = [ "all" ]; + # ... rest of the machine config }; "client_1_machine" = { clan.tags = [ diff --git a/lib/inventory/src/tests/borgbackup.json b/lib/inventory/examples/borgbackup.json similarity index 100% rename from lib/inventory/src/tests/borgbackup.json rename to lib/inventory/examples/borgbackup.json diff --git a/lib/inventory/src/tests/syncthing.json b/lib/inventory/examples/syncthing.json similarity index 100% rename from lib/inventory/src/tests/syncthing.json rename to lib/inventory/examples/syncthing.json diff --git a/lib/inventory/src/tests/zerotier.json b/lib/inventory/examples/zerotier.json similarity index 100% rename from lib/inventory/src/tests/zerotier.json rename to lib/inventory/examples/zerotier.json diff --git a/lib/inventory/flake-module.nix b/lib/inventory/flake-module.nix index 8778e4654..f2d7ed090 100644 --- a/lib/inventory/flake-module.nix +++ b/lib/inventory/flake-module.nix @@ -1,34 +1,29 @@ -{ ... }: +{ self, ... }: { + + flake.inventory = import ./example.nix { inherit self; }; perSystem = { pkgs, config, ... }: { - packages.inventory-schema = pkgs.stdenv.mkDerivation { - name = "inventory-schema"; - src = ./src; - - buildInputs = [ pkgs.cue ]; - - installPhase = '' - mkdir -p $out - ''; + devShells.inventory-schema = pkgs.mkShell { + inputsFrom = [ config.checks.inventory-schema-checks ]; }; - devShells.inventory-schema = pkgs.mkShell { inputsFrom = [ config.packages.inventory-schema ]; }; - checks.inventory-schema-checks = pkgs.stdenv.mkDerivation { name = "inventory-schema-checks"; - src = ./src; + src = ./.; buildInputs = [ pkgs.cue ]; buildPhase = '' echo "Running inventory tests..." + # Cue is easier to run in the same directory as the schema + cd spec echo "Export cue as json-schema..." cue export --out openapi root.cue echo "Validate test/*.json against inventory-schema..." - test_dir="test" + test_dir="../examples" for file in "$test_dir"/*; do # Check if the item is a file if [ -f "$file" ]; then diff --git a/lib/inventory/src/cue.mod/module.cue b/lib/inventory/spec/cue.mod/module.cue similarity index 100% rename from lib/inventory/src/cue.mod/module.cue rename to lib/inventory/spec/cue.mod/module.cue diff --git a/lib/inventory/src/root.cue b/lib/inventory/spec/root.cue similarity index 100% rename from lib/inventory/src/root.cue rename to lib/inventory/spec/root.cue diff --git a/lib/inventory/src/schema/schema.cue b/lib/inventory/spec/schema/schema.cue similarity index 100% rename from lib/inventory/src/schema/schema.cue rename to lib/inventory/spec/schema/schema.cue