Skip to content

Add modular Nix flake: dev shell, OCI images, static analysis - #13

Closed
randomizedcoder wants to merge 1 commit into
SemiAnalysisAI:masterfrom
randomizedcoder:nix
Closed

Add modular Nix flake: dev shell, OCI images, static analysis#13
randomizedcoder wants to merge 1 commit into
SemiAnalysisAI:masterfrom
randomizedcoder:nix

Conversation

@randomizedcoder

@randomizedcoder randomizedcoder commented Aug 31, 2026

Copy link
Copy Markdown

Summary

Adds a thin flake.nix orchestrator that delegates to a modular nix/ tree: flake-utils + a plain mkShell, one file per concern, and a single nix/versions.nix as the source of truth for tool versions. The flake is optional and does not change the pip install path.

What it provides

Target Purpose
nix develop Python 3.12 dev shell; cmax on PATH (a shell function shadows it interactively to run the working tree) plus ruff, mypy, bandit, shellcheck and cmax-* helpers. Type cmax-help.
nix build .#cmax buildPythonApplication of the CLI, with an install check for cmax --version and the bundled cmax.yaml / run.sh resources.
nix build .#oci-cmax Native per-system OCI image (amd64 + aarch64) via dockerTools.buildLayeredImage.
nix build .#analysis (+ analysis-ruff, -ruff-format, -mypy, -bandit, -shellcheck) Report-only static analysis. Always succeeds; writes report.txt / summary.txt. Does not gate.
nix run .#test pytest in the host environment.
nix flake check Sandbox-safe gates only: package build + CLI smoke check + nixfmt.
nix fmt Format the .nix files.

Design decisions

  • Static analysis is report-only (ruff, mypy, bandit, shellcheck). Tool config lives in pyproject.toml ([tool.ruff], [tool.mypy], [tool.bandit]) so the analysers run the same way inside and outside Nix.
  • Multi-arch containers are native per-system — build .#oci-cmax on a matching-arch host (or via binfmt/QEMU). Both x86_64-linux and aarch64-linux derivations evaluate.
  • The test suite runs via nix run .#test, not nix flake check. Its command stubs hard-code /bin/bash and /bin/cat, which do not exist in Nix's hermetic build sandbox. (These paths exist on a real host, so the suite runs there.)

Verification (x86_64-linux)

  • nix flake check — green (package build + install check + nixfmt).
  • nix build .#cmaxcmax 0.2.1.
  • nix build .#oci-cmax → loaded into Docker and ran (cmax 0.2.1).
  • nix build .#analysis → all four analysers produced reports; build succeeded.
  • nix developcmax, helpers, and tools all present.
  • aarch64 cmax / oci-cmax derivations evaluate.

Note: nix run .#test shows pre-existing audit-test failures that are not introduced here — an untouched checkout of HEAD fails the same tests through the same interpreter (they depend on host tooling such as mlxconfig/DPU detection). This change adds no Python runtime code.

Docs

nix/README.md (a Nix intro adapted for this project) plus a "Develop with Nix" quickstart in README.md.

🤖 Generated with Claude Code


Note

Low Risk
Infrastructure and documentation only; no changes to cmax runtime or audit logic.

Overview
Adds an optional Nix flake (flake.nix, flake.lock, modular nix/) alongside the existing pip install path. Contributors get nix develop (Python 3.12 plus cmax-* helpers), nix build .#cmax with install checks for the CLI and bundled cmax.yaml / audit run.sh, native per-arch .#oci-cmax images, and report-only analysis-* targets (ruff, mypy, bandit, shellcheck) that always succeed and write reports. nix flake check only gates the package build and nixfmt; pytest stays on nix run .#test because audit test stubs need host /bin/bash and /bin/cat.

pyproject.toml gains [tool.ruff], [tool.mypy], and [tool.bandit] so the same rules apply in and out of Nix. README documents a “Develop with Nix” quickstart and points to new nix/README.md.

Reviewed by Cursor Bugbot for commit 22326a1. Bugbot is set up for automated code reviews on this repo. Configure here.

Add a thin flake.nix orchestrator that delegates to a modular nix/ tree:
flake-utils + a plain mkShell, one file per concern, and a single
nix/versions.nix as the source of truth for tool versions.

Provides:
- nix develop: Python 3.12 dev shell with cmax on PATH (a shell function
  shadows it interactively to run the working tree) plus ruff, mypy, bandit,
  shellcheck, and helper commands (cmax-test, cmax-lint, ...).
- nix build .#cmax: buildPythonApplication of the cmax CLI, with an install
  check for `cmax --version` and the bundled cmax.yaml / run.sh resources.
- nix build .#oci-cmax: native per-system OCI image (amd64 + aarch64) via
  dockerTools.buildLayeredImage.
- Report-only static analysis: analysis-ruff, -ruff-format, -mypy, -bandit,
  -shellcheck, and a combined `analysis` summary. These never gate.
- nix flake check: sandbox-safe gates only (package build + nixfmt).
- nix run .#test: pytest in the host environment (the suite's command stubs
  hard-code /bin/bash and /bin/cat, absent in the hermetic sandbox).

pyproject.toml gains [tool.ruff], [tool.mypy], and [tool.bandit] config so the
analysers run the same way inside and outside Nix. Docs: nix/README.md plus a
"Develop with Nix" quickstart in README.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TiU7ttVHcNojp2T1TEutgX

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 22326a1. Configure here.

Comment thread nix/lib/mkOciImage.nix

config = {
Entrypoint = [ "/bin/cmax" ];
Env = [ "SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt" ];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OCI image cannot run audits

High Severity

The oci-cmax image never puts python3 on PATH and also omits /tmp and a home directory. cmax audit shells out to python3 and mktemp, so those runs fail even though cmax --version works.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 22326a1. Configure here.

Comment thread nix/overlays.nix
{ self }:
final: _prev: {
cmax = self.packages.${final.system}.cmax or null;
cmax-oci = self.packages.${final.system}.oci-cmax or null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overlay crashes on unsupported systems

Medium Severity

or null only covers a missing cmax attribute. Selecting self.packages.${final.system} still throws on Darwin and other systems the flake does not export, so downstream overlay users cannot evaluate pkgs.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 22326a1. Configure here.

@JordanNanos JordanNanos closed this Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants