Merge pull request 'clan-config: move jsonschema lib to clanLib' (#109) from DavHau-clan-config into main

This commit is contained in:
clan-bot
2023-08-09 14:07:03 +00:00
14 changed files with 57 additions and 45 deletions

View File

@@ -22,6 +22,7 @@
"aarch64-linux"
];
imports = [
# ./checks/flake-module.nix
./devShell.nix
./formatter.nix
./templates/flake-module.nix

View File

@@ -1,6 +1,5 @@
{ lib, ... }:
let
clanLib = {
{
findNixFiles = folder:
lib.mapAttrs'
(name: type:
@@ -12,6 +11,6 @@ let
lib.nameValuePair (lib.removeSuffix ".nix" name) "${folder}/${name}"
)
(builtins.readDir folder);
};
in
clanLib
jsonschema = import ./jsonschema { inherit lib; };
}

View File

@@ -1,5 +1,8 @@
{ lib
, ...
}: {
imports = [
./jsonschema/flake-module.nix
];
flake.lib = import ./default.nix { inherit lib; };
}

View File

@@ -0,0 +1,29 @@
{
perSystem = { pkgs, self', ... }: {
checks = {
# check if the `clan config` example jsonschema and data is valid
lib-jsonschema-example-valid = pkgs.runCommand "lib-jsonschema-example-valid" { } ''
echo "Checking that example-schema.json is valid"
${pkgs.check-jsonschema}/bin/check-jsonschema \
--check-metaschema ${./.}/example-schema.json
echo "Checking that example-data.json is valid according to example-schema.json"
${pkgs.check-jsonschema}/bin/check-jsonschema \
--schemafile ${./.}/example-schema.json \
${./.}/example-data.json
touch $out
'';
# check if the `clan config` nix jsonschema converter unit tests succeed
lib-jsonschema-nix-unit-tests = pkgs.runCommand "lib-jsonschema-nix-unit-tests" { } ''
export NIX_PATH=nixpkgs=${pkgs.path}
${self'.packages.nix-unit}/bin/nix-unit \
${./.}/test.nix \
--eval-store $(realpath .)
touch $out
'';
};
};
}

View File

@@ -1,6 +1,6 @@
# run these tests via `nix-unit ./test.nix`
{ lib ? (import <nixpkgs> { }).lib
, slib ? import ../../clan_cli/config/schema-lib.nix { inherit lib; }
, slib ? import ./. { inherit lib; }
}:
{
parseOption = import ./test_parseOption.nix { inherit lib slib; };

View File

@@ -1,7 +1,7 @@
# tests for the nixos options to jsonschema converter
# run these tests via `nix-unit ./test.nix`
{ lib ? (import <nixpkgs> { }).lib
, slib ? import ../../clan_cli/config/schema-lib.nix { inherit lib; }
, slib ? import ./. { inherit lib; }
}:
let
description = "Test Description";

View File

@@ -1,7 +1,7 @@
# tests for the nixos options to jsonschema converter
# run these tests via `nix-unit ./test.nix`
{ lib ? (import <nixpkgs> { }).lib
, slib ? import ../../clan_cli/config/schema-lib.nix { inherit lib; }
, slib ? import ./. { inherit lib; }
}:
let
evaledOptions =

View File

@@ -1,6 +1,7 @@
# !/usr/bin/env python3
import argparse
import json
import os
import subprocess
import sys
from pathlib import Path
@@ -8,6 +9,8 @@ from typing import Any, Optional, Type, Union
from clan_cli.errors import ClanError
CLAN_FLAKE = os.getenv("CLAN_FLAKE")
class Kwargs:
def __init__(self) -> None:
@@ -27,7 +30,7 @@ def schema_from_module_file(
nix_expr = f"""
let
lib = import <nixpkgs/lib>;
slib = import {__file__}/../schema-lib.nix {{inherit lib;}};
slib = import {CLAN_FLAKE}/lib/jsonschema.nix {{inherit lib;}};
in
slib.parseModule {absolute_path}
"""

View File

@@ -27,30 +27,7 @@
## End optional dependencies
};
checks = self'.packages.clan-cli.tests // {
# check if the `clan config` example jsonschema and data is valid
clan-config-example-schema-valid = pkgs.runCommand "clan-config-example-schema-valid" { } ''
echo "Checking that example-schema.json is valid"
${pkgs.check-jsonschema}/bin/check-jsonschema \
--check-metaschema ${./.}/tests/config/example-schema.json
echo "Checking that example-data.json is valid according to example-schema.json"
${pkgs.check-jsonschema}/bin/check-jsonschema \
--schemafile ${./.}/tests/config/example-schema.json \
${./.}/tests/config/example-data.json
touch $out
'';
# check if the `clan config` nix jsonschema converter unit tests succeed
clan-config-nix-unit-tests = pkgs.runCommand "clan-edit-unit-tests" { } ''
export NIX_PATH=nixpkgs=${pkgs.path}
${self'.packages.nix-unit}/bin/nix-unit \
${./.}/tests/config/test.nix \
--eval-store $(realpath .)
touch $out
'';
};
checks = self'.packages.clan-cli.tests;
};
}

View File

@@ -9,7 +9,7 @@ let
]
);
checkScript = pkgs.writeScriptBin "check" ''
nix build -f . tests -L "$@"
nix build .#checks.${pkgs.system}.{treefmt,clan-mypy,clan-pytest} -L "$@"
'';
in
pkgs.mkShell {