2024-06-26 15:19:19 +00:00
|
|
|
{ self, inputs, ... }:
|
|
|
|
let
|
|
|
|
inputOverrides = builtins.concatStringsSep " " (
|
|
|
|
builtins.map (input: " --override-input ${input} ${inputs.${input}}") (builtins.attrNames inputs)
|
|
|
|
);
|
|
|
|
in
|
2024-06-15 11:41:51 +00:00
|
|
|
{
|
2024-06-26 13:16:20 +00:00
|
|
|
flake.inventory = import ./example.nix { inherit self; };
|
2024-06-26 15:19:19 +00:00
|
|
|
|
2024-06-15 11:41:51 +00:00
|
|
|
perSystem =
|
2024-06-26 15:19:19 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
system,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
buildInventory = import ./build-inventory {
|
|
|
|
clan-core = self;
|
|
|
|
inherit lib;
|
|
|
|
};
|
|
|
|
in
|
2024-06-15 11:41:51 +00:00
|
|
|
{
|
2024-06-26 13:16:20 +00:00
|
|
|
devShells.inventory-schema = pkgs.mkShell {
|
2024-06-26 15:19:19 +00:00
|
|
|
inputsFrom = with config.checks; [
|
|
|
|
lib-inventory-schema
|
|
|
|
lib-inventory-eval
|
|
|
|
];
|
2024-06-15 11:41:51 +00:00
|
|
|
};
|
2024-06-19 14:56:26 +00:00
|
|
|
|
2024-06-26 15:19:19 +00:00
|
|
|
# Run: nix-unit --extra-experimental-features flakes --flake .#legacyPackages.x86_64-linux.evalTests
|
2024-06-27 14:09:42 +00:00
|
|
|
legacyPackages.evalTests-inventory = import ./tests {
|
2024-06-26 15:19:19 +00:00
|
|
|
inherit buildInventory;
|
|
|
|
clan-core = self;
|
|
|
|
};
|
2024-06-15 11:41:51 +00:00
|
|
|
|
2024-06-26 15:19:19 +00:00
|
|
|
checks = {
|
|
|
|
lib-inventory-eval = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
|
|
|
|
export HOME="$(realpath .)"
|
2024-06-15 11:41:51 +00:00
|
|
|
|
2024-06-26 15:19:19 +00:00
|
|
|
nix-unit --eval-store "$HOME" \
|
|
|
|
--extra-experimental-features flakes \
|
|
|
|
${inputOverrides} \
|
2024-06-27 14:09:42 +00:00
|
|
|
--flake ${self}#legacyPackages.${system}.evalTests-inventory
|
2024-06-15 11:41:51 +00:00
|
|
|
|
|
|
|
touch $out
|
|
|
|
'';
|
2024-06-26 15:19:19 +00:00
|
|
|
|
|
|
|
lib-inventory-schema = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "inventory-schema-checks";
|
|
|
|
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="../examples"
|
|
|
|
for file in "$test_dir"/*; do
|
|
|
|
# Check if the item is a file
|
|
|
|
if [ -f "$file" ]; then
|
|
|
|
# Print the filename
|
|
|
|
echo "Running test on: $file"
|
|
|
|
|
|
|
|
# Run the cue vet command
|
|
|
|
cue vet "$file" root.cue -d "#Root"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
};
|
2024-06-15 11:41:51 +00:00
|
|
|
};
|
2024-06-15 11:41:51 +00:00
|
|
|
};
|
|
|
|
}
|