diff --git a/checks/impure/flake-module.nix b/checks/impure/flake-module.nix index 18f3e7ada..b0865c6ff 100644 --- a/checks/impure/flake-module.nix +++ b/checks/impure/flake-module.nix @@ -1,66 +1,18 @@ -{ ... }: { +{ perSystem = { pkgs, lib, ... }: { - packages = rec { - # a script that executes all other checks - impure-checks = pkgs.writeShellScriptBin "impure-checks" '' - #!${pkgs.bash}/bin/bash - set -euo pipefail + # a script that executes all other checks + packages.impure-checks = pkgs.writeShellScriptBin "impure-checks" '' + #!${pkgs.bash}/bin/bash + set -euo pipefail - export PATH="${lib.makeBinPath [ - pkgs.gitMinimal - pkgs.nix - pkgs.rsync # needed to have rsync installed on the dummy ssh server - ]}" - ROOT=$(git rev-parse --show-toplevel) - cd "$ROOT/pkgs/clan-cli" - nix develop "$ROOT#clan-cli" -c bash -c "TMPDIR=/tmp python -m pytest -m impure ./tests $@" - ''; - - runMockApi = pkgs.writeShellScriptBin "run-mock-api" '' - #!${pkgs.bash}/bin/bash - set -euo pipefail - - export PATH="${lib.makeBinPath [ - pkgs.gitMinimal - pkgs.nix - pkgs.rsync # needed to have rsync installed on the dummy ssh server - pkgs.coreutils - pkgs.procps - ]}" - ROOT=$(git rev-parse --show-toplevel) - cd "$ROOT/pkgs/clan-cli" - nix develop "$ROOT#clan-cli" -c bash -c 'TMPDIR=/tmp clan webui --no-open --port 5757' - ''; - - - runSchemaTests = pkgs.writeShellScriptBin "runSchemaTests" '' - #!${pkgs.bash}/bin/bash - set -euo pipefail - - ${runMockApi}/bin/run-mock-api & - MOCK_API_PID=$! - echo "Started mock api with pid $MOCK_API_PID" - function cleanup { - echo "Stopping server..." - pkill -9 -f "python -m clan webui --no-open --port 5757" - } - trap cleanup EXIT - - export PATH="${lib.makeBinPath [ - pkgs.gitMinimal - pkgs.nix - pkgs.rsync # needed to have rsync installed on the dummy ssh server - pkgs.procps - pkgs.coreutils - ]}" - - sleep 3 - - ROOT=$(git rev-parse --show-toplevel) - cd "$ROOT/pkgs/clan-cli" - nix develop "$ROOT#clan-cli" -c bash -c 'TMPDIR=/tmp st auth login RHtr8nLtz77tqRP8yUGyf-Flv_9SLI' - nix develop "$ROOT#clan-cli" -c bash -c 'TMPDIR=/tmp st run http://localhost:5757/openapi.json --experimental=openapi-3.1 --report --workers 8 --max-response-time=50 --request-timeout=1000 -M GET' - ''; - }; + export PATH="${lib.makeBinPath [ + pkgs.gitMinimal + pkgs.nix + pkgs.rsync # needed to have rsync installed on the dummy ssh server + ]}" + ROOT=$(git rev-parse --show-toplevel) + cd "$ROOT/pkgs/clan-cli" + nix develop "$ROOT#clan-cli" -c bash -c "TMPDIR=/tmp python -m pytest -m impure ./tests $@" + ''; }; } diff --git a/checks/schema.nix b/checks/schema.nix deleted file mode 100644 index d862f8a4b..000000000 --- a/checks/schema.nix +++ /dev/null @@ -1,54 +0,0 @@ -{ self, lib, inputs, ... }: -let - inherit (builtins) - mapAttrs - toJSON - toFile - ; - inherit (lib) - mapAttrs' - ; - clanLib = self.lib; - clanModules = self.clanModules; - - -in -{ - perSystem = { pkgs, ... }: - let - baseModule = { - imports = - (import (inputs.nixpkgs + "/nixos/modules/module-list.nix")) - ++ [{ - nixpkgs.hostPlatform = pkgs.system; - }]; - }; - - optionsFromModule = module: - let - evaled = lib.evalModules { - modules = [ module baseModule ]; - }; - in - evaled.options.clan.networking; - - clanModuleSchemas = - mapAttrs - (_: module: clanLib.jsonschema.parseOptions (optionsFromModule module)) - clanModules; - - mkTest = name: schema: pkgs.runCommand "schema-${name}" { } '' - ${pkgs.check-jsonschema}/bin/check-jsonschema \ - --check-metaschema ${toFile "schema-${name}" (toJSON schema)} - touch $out - ''; - in - { - checks = mapAttrs' - (name: schema: { - name = "schema-${name}"; - value = mkTest name schema; - }) - clanModuleSchemas; - }; -} diff --git a/checks/schemas.nix b/checks/schemas.nix index f2a9960a7..c12e1d8f1 100644 --- a/checks/schemas.nix +++ b/checks/schemas.nix @@ -7,6 +7,7 @@ let (import (pkgs.path + "/nixos/modules/module-list.nix")) ++ [{ nixpkgs.hostPlatform = "x86_64-linux"; + clanCore.clanName = "dummy"; }]; }; diff --git a/docs/contributing.md b/docs/contributing.md index e6d094e0a..3ac914e08 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -174,14 +174,6 @@ nix build .#checks.x86_64-linux.clan-pytest --rebuild This command will run all pure test functions. -### Running schemathesis fuzzer on GET requests - -```bash -nix run .#runSchemaTests -``` - -If you want to test more request types edit the file `checks/impure/flake-module.nix` - ### Inspecting the Nix Sandbox If you need to inspect the Nix sandbox while running tests, follow these steps: diff --git a/nixosModules/clanCore/zerotier/default.nix b/nixosModules/clanCore/zerotier/default.nix index 5dd56b542..2ce0088c3 100644 --- a/nixosModules/clanCore/zerotier/default.nix +++ b/nixosModules/clanCore/zerotier/default.nix @@ -15,7 +15,7 @@ let ipAssignmentPools = [ ]; mtu = 2800; multicastLimit = 32; - name = ""; + name = cfg.name; uwid = cfg.networkId; objtype = "network"; private = !cfg.controller.public; @@ -52,6 +52,13 @@ in zerotier networking id ''; }; + name = lib.mkOption { + type = lib.types.str; + default = config.clanCore.clanName; + description = '' + zerotier network name + ''; + }; subnet = lib.mkOption { type = lib.types.nullOr lib.types.str; readOnly = true; @@ -129,6 +136,21 @@ in fi ''}" ]; + systemd.services.zerotierone.serviceConfig.ExecStartPost = [ + "+${pkgs.writeShellScript "configure-interface" '' + while ! ${pkgs.netcat}/bin/nc -z localhost 9993; do + sleep 0.1 + done + zerotier-cli listnetworks -j | ${pkgs.jq}/bin/jq -r '.[] | [.portDeviceName, .name] | @tsv' \ + | while IFS=$'\t' read -r portDeviceName name; do + if [[ -z "$name" ]] || [[ -z "$portDeviceName" ]]; then + continue + fi + # Execute the command for each element + ${pkgs.iproute2}/bin/ip link property add dev "$portDeviceName" altname "$name" + done + ''}" + ]; networking.firewall.interfaces."zt+".allowedTCPPorts = [ 5353 ]; # mdns networking.firewall.interfaces."zt+".allowedUDPPorts = [ 5353 ]; # mdns @@ -165,7 +187,6 @@ in environment.systemPackages = [ config.clanCore.clanPkgs.zerotier-members ]; }) (lib.mkIf (config.clanCore.secretsUploadDirectory != null && !cfg.controller.enable && cfg.networkId != null) { - clanCore.secrets.zerotier = { facts.zerotier-ip = { }; facts.zerotier-meshname = { }; diff --git a/pkgs/clan-cli/clan_cli/config/schema.py b/pkgs/clan-cli/clan_cli/config/schema.py index ad927d1ad..a709068cf 100644 --- a/pkgs/clan-cli/clan_cli/config/schema.py +++ b/pkgs/clan-cli/clan_cli/config/schema.py @@ -87,6 +87,7 @@ def machine_schema( # potentially the config might affect submodule options, # therefore we need to import it config + {{ clanCore.clanName = "fakeClan"; }} ] # add all clan modules specified via clanImports ++ (map (name: clan-core.clanModules.${{name}}) config.clanImports or []);