{ description = "OBLITERATUS test environments matching the CPU pull-request CI"; # Nix supplies the interpreter, uv and native runtime libraries; uv.lock stays # the single source of truth for Python dependencies, exactly as in CI. inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; outputs = { self, nixpkgs }: let systems = [ "x86_64-linux" "aarch64-linux" ]; forAll = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system}); # Kept in step with UV_VERSION and the marker expression in .github/workflows/ci.yml. uvVersion = "0.12.4"; ciMarkers = "not slow and not gpu and not mps and not mlx and not network" + " and not download and not remote and not operator_ui and not gloo"; ciExtras = "--extra dev --extra recovery --extra mcp"; pythons = pkgs: { py311 = pkgs.python311; py312 = pkgs.python312; py313 = pkgs.python313; }; ciEnv = pkgs: python: tag: { CUDA_VISIBLE_DEVICES = ""; HF_DATASETS_OFFLINE = "1"; HF_HUB_DISABLE_TELEMETRY = "1"; HF_HUB_OFFLINE = "1"; TOKENIZERS_PARALLELISM = "false"; TRANSFORMERS_OFFLINE = "1"; PIP_DISABLE_PIP_VERSION_CHECK = "1"; PIP_NO_INPUT = "1"; UV_PYTHON = "${python}/bin/python"; UV_PYTHON_DOWNLOADS = "never"; OBLITERATUS_NIX_TAG = tag; # Prebuilt manylinux wheels (torch, numpy, tokenizers) need these at runtime. LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib pkgs.zlib ]; }; # Installs the pinned uv into a per-interpreter tool venv, syncs the locked # non-editable test environment, then runs pytest with the CI marker filter. runner = pkgs: python: tag: pkgs.writeShellApplication { name = "obliteratus-test-${tag}"; runtimeInputs = [ python pkgs.git pkgs.coreutils ]; text = '' root="$(git rev-parse --show-toplevel)" cd "$root" state="''${OBLITERATUS_NIX_STATE:-$root/.nix-test}/${tag}" tools="$state/tools" if [ ! -x "$tools/bin/uv" ] || [ "$("$tools/bin/uv" --version | cut -d' ' -f2)" != "${uvVersion}" ]; then python -m venv --clear "$tools" "$tools/bin/python" -m pip install --quiet "uv==${uvVersion}" fi export UV_PROJECT_ENVIRONMENT="$state/env" # shellcheck disable=SC2086 "$tools/bin/uv" sync --locked --no-default-groups ''${OBLITERATUS_TEST_EXTRAS:-${ciExtras}} \ --no-editable --link-mode copy --quiet basetemp="$(mktemp -d "''${TMPDIR:-/tmp}/obliteratus-pytest-XXXXXX")" exec "$state/env/bin/python" -m pytest \ -p no:cacheprovider \ -o "addopts=--strict-config --strict-markers" \ -m "''${OBLITERATUS_TEST_MARKERS:-${ciMarkers}}" \ --basetemp="$basetemp/t" \ "''${@:-tests}" ''; }; in { devShells = forAll (pkgs: let shells = nixpkgs.lib.mapAttrs (tag: python: pkgs.mkShell ({ packages = [ python pkgs.git (runner pkgs python tag) ]; } // ciEnv pkgs python tag)) (pythons pkgs); in shells // { default = shells.py312; }); apps = forAll (pkgs: let mk = tag: python: { type = "app"; program = "${pkgs.writeShellScript "obliteratus-test-${tag}-env" '' ${pkgs.lib.concatStringsSep "\n" (pkgs.lib.mapAttrsToList (k: v: "export ${k}=${pkgs.lib.escapeShellArg v}") (ciEnv pkgs python tag))} exec ${runner pkgs python tag}/bin/obliteratus-test-${tag} "$@" ''}"; }; apps = nixpkgs.lib.mapAttrs (tag: python: mk tag python) (pythons pkgs); in nixpkgs.lib.mapAttrs' (tag: v: nixpkgs.lib.nameValuePair "test-${tag}" v) apps // { test = apps.py312; }); }; }