Merge pull request 'impure-checks: improve performance by disabling dynamic deps' (#1736) from DavHau/clan-core:DavHau-vars into main

This commit is contained in:
clan-bot
2024-07-16 05:46:07 +00:00
6 changed files with 29 additions and 11 deletions

View File

@@ -1,6 +1,11 @@
{ {
perSystem = perSystem =
{ pkgs, lib, ... }: {
pkgs,
lib,
self',
...
}:
{ {
# a script that executes all other checks # a script that executes all other checks
packages.impure-checks = pkgs.writeShellScriptBin "impure-checks" '' packages.impure-checks = pkgs.writeShellScriptBin "impure-checks" ''
@@ -10,14 +15,21 @@
unset CLAN_DIR unset CLAN_DIR
export PATH="${ export PATH="${
lib.makeBinPath [ lib.makeBinPath (
pkgs.gitMinimal [
pkgs.nix pkgs.gitMinimal
pkgs.rsync # needed to have rsync installed on the dummy ssh server pkgs.nix
] pkgs.rsync # needed to have rsync installed on the dummy ssh server
]
++ self'.packages.clan-cli-full.runtimeDependencies
)
}" }"
ROOT=$(git rev-parse --show-toplevel) ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT/pkgs/clan-cli" cd "$ROOT/pkgs/clan-cli"
# this disables dynamic dependency loading in clan-cli
export CLAN_NO_DYNAMIC_DEPS=1
nix develop "$ROOT#clan-cli" -c bash -c "TMPDIR=/tmp python -m pytest -s -m impure ./tests $@" nix develop "$ROOT#clan-cli" -c bash -c "TMPDIR=/tmp python -m pytest -s -m impure ./tests $@"
''; '';
}; };

View File

@@ -166,7 +166,10 @@ class Machine:
if extra_config is not None: if extra_config is not None:
metadata = nix_metadata(self.flake_dir) metadata = nix_metadata(self.flake_dir)
url = metadata["url"] url = metadata["url"]
if "dirtyRevision" in metadata: if (
"dirtyRevision" in metadata
or "dirtyRev" in metadata["locks"]["nodes"]["clan-core"]["locked"]
):
# if not impure: # if not impure:
# raise ClanError( # raise ClanError(
# "The machine has a dirty revision, and impure mode is not allowed" # "The machine has a dirty revision, and impure mode is not allowed"

View File

@@ -103,7 +103,7 @@ def nix_metadata(flake_url: str | Path) -> dict[str, Any]:
def nix_shell(packages: list[str], cmd: list[str]) -> list[str]: def nix_shell(packages: list[str], cmd: list[str]) -> list[str]:
# we cannot use nix-shell inside the nix sandbox # we cannot use nix-shell inside the nix sandbox
# in our tests we just make sure we have all the packages # in our tests we just make sure we have all the packages
if os.environ.get("IN_NIX_SANDBOX"): if os.environ.get("IN_NIX_SANDBOX") or os.environ.get("CLAN_NO_DYNAMIC_DEPS"):
return cmd return cmd
return [ return [
*nix_command(["shell", "--inputs-from", f"{nixpkgs_flake()!s}"]), *nix_command(["shell", "--inputs-from", f"{nixpkgs_flake()!s}"]),

View File

@@ -1,6 +1,7 @@
[ [
"age", "age",
"bash", "bash",
"bubblewrap",
"e2fsprogs", "e2fsprogs",
"git", "git",
"mypy", "mypy",
@@ -8,8 +9,10 @@
"openssh", "openssh",
"qemu", "qemu",
"rsync", "rsync",
"pass",
"sops", "sops",
"sshpass", "sshpass",
"tor", "tor",
"virtiofsd",
"zbar" "zbar"
] ]

View File

@@ -30,8 +30,8 @@ let
# load nixpkgs runtime dependencies from a json file # load nixpkgs runtime dependencies from a json file
# This file represents an allow list at the same time that is checked by the run_cmd # This file represents an allow list at the same time that is checked by the run_cmd
# implementation in nix.py # implementation in nix.py
runtimeDependenciesAsSet = lib.genAttrs (lib.importJSON ./clan_cli/nix/allowed-programs.json) ( runtimeDependenciesAsSet = lib.filterAttrs (_name: pkg: !pkg.meta.unsupported or false) (
name: pkgs.${name} lib.genAttrs (lib.importJSON ./clan_cli/nix/allowed-programs.json) (name: pkgs.${name})
); );
runtimeDependencies = lib.attrValues runtimeDependenciesAsSet; runtimeDependencies = lib.attrValues runtimeDependenciesAsSet;

View File

@@ -40,7 +40,7 @@ def run_vm_in_thread(machine_name: str) -> None:
# wait for qmp socket to exist # wait for qmp socket to exist
def wait_vm_up(state_dir: Path) -> None: def wait_vm_up(state_dir: Path) -> None:
socket_file = state_dir / "qga.sock" socket_file = state_dir / "qga.sock"
timeout: float = 20 timeout: float = 100
while True: while True:
if timeout <= 0: if timeout <= 0:
raise TimeoutError( raise TimeoutError(