The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(ci): add nix flake check as unrequired job
ethernet00c38728824e
diff --git a/.github/actions/detect-changes/action.yml b/.github/actions/detect-changes/action.ymlindex 9c8fb223e8f..b16500346f5 100644--- a/.github/actions/detect-changes/action.yml+++ b/.github/actions/detect-changes/action.yml@@ -27,6 +27,9 @@ outputs:docker:description: Files included in the docker image have changed.value: ${{ steps.classify.outputs.docker }}+ nix:+ description: Run `nix flake check` (flake inputs, or any product Python change).+ value: ${{ steps.classify.outputs.nix }}site:description: Build the Docusaurus docs site.value: ${{ steps.classify.outputs.site }}diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.ymlnew file mode 100644index 00000000000..23627cbc9f1--- /dev/null+++ b/.github/workflows/nix.yml@@ -0,0 +1,117 @@+name: Nix flake check++# Builds every output of the flake: the package, the devShell, and the 21+# checks under nix/checks.nix — module evaluation, option parity, .env+# assembly, service argv, and the rest.+#+# This workflow owns its triggers and ci.yml does not call it, for the reason+# docker.yml gives: a reusable-workflow call holds the caller run in progress+# for the full build, and GitHub refuses `gh run rerun` on a run that is still+# in progress. One slow advisory job in the CI lane blocks every rerun of the+# fast required jobs beside it. A separate run reruns and cancels on its own.++on:+ pull_request:+ push:+ branches: [main]++permissions:+ contents: read++# PR runs collapse to the newest commit. A push to main is never cancelled:+# each one saves the store cache that later PRs restore from, so cancelling a+# merge would leave the next PR to build from nothing.+concurrency:+ group: nix-${{ github.event.pull_request.number || github.ref }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}++jobs:+ # A `paths:` filter cannot gate this workflow correctly. The flake packages+ # the product, and nine of the checks then run the built binary, so a change+ # to hermes_cli/ alone can fail `nix flake check` without touching one file+ # under nix/. The `nix` lane therefore follows python_prod as well as the+ # flake inputs. On push the classifier fails open and every lane is true.+ detect:+ name: Detect affected areas+ runs-on: ubuntu-latest+ timeout-minutes: 10+ outputs:+ nix: ${{ steps.classify.outputs.nix }}+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2++ - name: Detect affected areas+ id: classify+ uses: ./.github/actions/detect-changes+ with:+ github-token: ${{ github.token }}++ flake-check:+ name: nix flake check+ needs: [detect]+ if: needs.detect.outputs.nix == 'true'+ # The build compiles the package and its whole dependency closure, so this+ # is minutes and not seconds when the cache misses.+ runs-on: ubuntu-latest+ timeout-minutes: 60+ steps:+ - name: Checkout code+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2++ - name: Install Nix+ uses: cachix/install-nix-action@630ae543ea3a38a9a4166f03376c02c50f408342 # v31.11.0+ with:+ extra_nix_config: |+ experimental-features = nix-command flakes+ # A store path that does not substitute is a cache miss and not a+ # build failure. Build it here instead.+ fallback = true+ # Each source archive is fetched one time in a run, and not one+ # time for each evaluation.+ tarball-ttl = 3600++ # Restores /nix/store from the GitHub Actions cache. The store holds the+ # whole dependency closure, so a hit turns a build of several minutes+ # into a short evaluation.+ #+ # The Magic Nix Cache is not an option here. Its free tier ended in+ # February 2025 with the GitHub cache API that it was built on. This+ # action uses the current API and needs no account and no secret.+ - name: Restore and save the Nix store+ uses: nix-community/cache-nix-action@7df957e333c1e5da7721f60227dbba6d06080569 # v7+ with:+ # The closure changes when the flake inputs change or when the+ # dependencies of the project change. The key hashes both, so an+ # edit to the source alone keeps the hit.+ primary-key: nix-${{ runner.os }}-${{ hashFiles('flake.lock', 'nix/**', 'pyproject.toml', 'uv.lock') }}+ # On a miss, restore the newest store for this runner. Most of the+ # closure — Python, node, each transitive library — survives a bump+ # of the lockfile, so an old store still removes most of the work.+ restore-prefixes-first-match: nix-${{ runner.os }}-++ # Save from main only. A cache that a PR writes is visible to that+ # PR alone and never to another branch, so a save there spends the+ # 10 GB quota of the repository and helps no later run. A PR still+ # restores: it reads the cache that the merge to main wrote. This is+ # the same rule that docker.yml applies to `cache-to`.+ save: ${{ github.event_name != 'pull_request' }}++ # Collect garbage before the save, so the store stays inside the+ # 10 GB quota of the repository. Without a limit the store grows at+ # each merge until GitHub removes the entry, and the next PR then+ # gets nothing. This number is the size of the store and not the+ # size of the compressed archive.+ gc-max-store-size-linux: 5G++ # Delete the caches that this key replaces. GitHub removes caches by+ # least recent use across the whole repository, so a Nix store that+ # is never purged pushes out the caches of the other workflows.+ purge: true+ purge-prefixes: nix-${{ runner.os }}-+ purge-created: 0+ purge-primary-key: never++ - name: nix flake check+ # --print-build-logs: a check that fails then prints the assertion+ # that failed, and not only the derivation that failed to build.+ run: nix flake check --print-build-logsdiff --git a/scripts/ci/classify_changes.py b/scripts/ci/classify_changes.pyindex c5e9db383be..95a9bb13da3 100644--- a/scripts/ci/classify_changes.py+++ b/scripts/ci/classify_changes.py@@ -15,6 +15,7 @@ Lanes:skipping those product jobs.* ``docker_meta`` — Dockerfiles etc.* ``docker`` — any product change + docker meta+* ``nix`` — ``nix flake check``: the flake inputs and any product change.* ``frontend`` — TS typecheck matrix + desktop build.* ``site`` — Docusaurus + generated skill docs.* ``scan`` — supply-chain scan (Python files, .pth, setup hooks).@@ -37,6 +38,10 @@ must never skip one a change could break:or a frontend-only package; an unrecognized path keeps it on.* ``skills/`` (incl. ``SKILL.md``) is python-relevant — the skill-doc testsread that tree, so a doc-looking edit can still break Python.+* ``nix/``, ``flake.nix`` and ``flake.lock`` are the exception the other way:+ only the flake reads them, so they skip the Python lanes and run ``nix``+ alone. ``pyproject.toml`` and ``uv.lock`` are flake inputs too, but the+ packaging tests read them, so they keep every Python lane."""from __future__ import annotations@@ -48,6 +53,8 @@ import sys_FRONTEND = ("ui-tui/", "web/", "apps/") # TS typecheck-matrix packages_ROOT_NPM = {"package.json", "package-lock.json"} # shifts every package's tree_DOCKER_META = ("docker/", ".hadolint.yml", "Dockerfile") # docker setup+_NIX_PATHS = ("nix/",) # nix files+_NIX_FILES = {"flake.nix", "flake.lock"} # base nix files_SITE = ("website/", "skills/", "optional-skills/") # docs site + skill pages# Prose/frontend trees that can't touch Python. skills/ is excluded on purpose._PY_SKIP = ("docs/", "website/") + _FRONTEND@@ -84,8 +91,18 @@ def _is_docs(p: str) -> bool:return p.endswith((".md", ".mdx")) or p.startswith("docs/") or p.startswith("LICENSE")+def _is_nix(p: str) -> bool:+ return p.startswith(_NIX_PATHS) or p in _NIX_FILES++def _py_irrelevant(p: str) -> bool:- return _is_docs(p) or p in _ROOT_NPM or p.startswith(_PY_SKIP) or p.startswith(_DOCKER_META)+ return (+ _is_docs(p)+ or p in _ROOT_NPM+ or p.startswith(_PY_SKIP)+ or p.startswith(_DOCKER_META)+ or _is_nix(p)+ )def _py_test_only(p: str) -> bool:@@ -149,6 +166,7 @@ def classify(files: list[str]) -> dict[str, bool]:"installer": any(_is_installer(f) for f in files),"mcp_catalog": any(_is_mcp_catalog(f) for f in files),"ci_review": any(_is_ci_review(f) for f in files),+ "nix": python_prod or frontend or any(_is_nix(f) for f in files)}if not files or any(f.startswith(".github/") for f in files):ret["python"] = True@@ -162,6 +180,7 @@ def classify(files: list[str]) -> dict[str, bool]:ret["uv_lock"] = Trueret["npm_lock"] = Trueret["installer"] = True+ ret["nix"] = Trueret["ci_review"] = True# explicitly skip mcp catalog here. it's not needed unless those files are modified.diff --git a/tests/ci/test_classify_changes.py b/tests/ci/test_classify_changes.pyindex d1df6cdac25..7c4bd0415e9 100644--- a/tests/ci/test_classify_changes.py+++ b/tests/ci/test_classify_changes.py@@ -27,6 +27,7 @@ DEFAULT = {"frontend": True,"docker": True,"docker_meta": True,+ "nix": True,"site": True,"scan": True,"deps": True,@@ -38,12 +39,20 @@ DEFAULT = {}-def _lanes(python=False, frontend=False, site=False, scan=False, deps=False, uv_lock=False, npm_lock=False, installer=False, mcp_catalog=False, docker_meta=False, ci_review=False, python_prod=None) -> dict[str, bool]:+def _lanes(python=False, frontend=False, site=False, scan=False, deps=False, uv_lock=False, npm_lock=False, installer=False, mcp_catalog=False, docker_meta=False, ci_review=False, python_prod=None, nix=None, docker=None) -> dict[str, bool]:# python_prod tracks python except for tests-only diffs; default it to# python so the majority of cases don't need to spell it out.+ #+ # docker and nix are derived: both build the product, so both ride on+ # python_prod and frontend. The image ships the built web assets, and the+ # flake bundles the compiled ui-tui. Pass either explicitly to override.+ _python_prod = python if python_prod is None else python_prod+ _product = _python_prod or frontendreturn {"python": python,- "python_prod": python if python_prod is None else python_prod,+ "python_prod": _python_prod,+ "docker": (docker_meta or _product) if docker is None else docker,+ "nix": _product if nix is None else nix,"frontend": frontend,"docker_meta": docker_meta,"site": site,@@ -77,6 +86,23 @@ CASES = {# skill edit must still run Python."skill md → python + site": (["skills/github/SKILL.md"], _lanes(python=True, site=True)),"dockerfile → docker meta": (["Dockerfile"], _lanes(docker_meta=True)),+ # Only the flake reads these, so they run nix alone. No Python test opens+ # them, unlike pyproject.toml and uv.lock below.+ "nix module → nix only": (["nix/homeManagerModules.nix"], _lanes(nix=True)),+ "flake.nix → nix only": (["flake.nix"], _lanes(nix=True)),+ "flake.lock → nix only": (["flake.lock"], _lanes(nix=True)),+ # A flake-only file must not mask a Python change beside it.+ "nix + python → both": (["nix/checks.nix", "agent/x.py"], _lanes(python=True, scan=True)),+ # Nine checks run the built binary, so product Python is a nix input even+ # when the diff touches no file under nix/.+ "product python → nix": (["hermes_cli/config.py"], _lanes(python=True, scan=True)),+ # tests/ is not packaged, so the built binary cannot change.+ "tests-only → no nix": (+ ["tests/agent/test_foo.py"],+ _lanes(python=True, python_prod=False, scan=True),+ ),+ # Prose cannot change the closure or the binary.+ "docs-only → no nix": (["README.md"], _lanes()),# install.ps1 is a shell script Python never imports, but it's also not# provably prose, so python stays on (fail-open) alongside the Windows lane."install.ps1 → installer": (["scripts/install.ps1"], _lanes(python=True, installer=True)),