diff --git a/lib/description.nix b/lib/description.nix index c4c641e6..4e4ad081 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 50b41792..f7a7154e 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 8778e465..f2d7ed09 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