Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

[fix issue405]

BobDylanscce98873856c
diff --git a/.gitignore b/.gitignore
index a17aab5b..cfed8d1d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,3 +36,7 @@ evals/runs/
# ai-memory atomic-write backups (apply_atomic in apply_shared.rs)
*.bak-*
+
+# Nix flake build output (nix build / nix run).
+result
+result-*
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1c8020b6..0554a749 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
+- Added a `flake.nix` so NixOS and Nix users can build and run ai-memory
+ without the Rust toolchain or Docker: `nix build`, `nix run . --
+ --version`, or `nix develop` for a dev shell. The build is self-contained
+ (SQLite bundled, libgit2 vendored, rustls with webpki-roots — no OpenSSL,
+ no system-library hunting). The flake skips the packaging test suite
+ because those tests exercise the Docker-wrapper shell script and need
+ `docker`/`podman` on PATH; the rest of the workspace tests can be run via
+ `nix develop -c cargo test --workspace`. ([#405])
- New `strip_root_combinators` config flag (env `AI_MEMORY_STRIP_ROOT_COMBINATORS`,
or `strip_root_combinators = true` in config.toml) strips root-level
`anyOf`/`oneOf`/`allOf` from MCP tool input schemas on every `tools/list`.
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 00000000..36cd57bc
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,135 @@
+# Nix flake for ai-memory.
+#
+# Provides:
+# nix build # → result/bin/ai-memory (native release binary)
+# nix run . -- --version # smoke-test without installing
+# nix develop # dev shell with Rust 1.95 (pinned)
+#
+# The build is self-contained: SQLite is bundled via rusqlite's `bundled`
+# feature, libgit2 is vendored via git2's `vendored-libgit2` feature, and
+# TLS uses rustls (webpki-roots) — no OpenSSL, no system-library hunting.
+# The only extra step is TAILWIND_SKIP=1 so the web crate's build script
+# uses the vendored static/tailwind.css instead of downloading the
+# Tailwind CLI (which a sandboxed Nix build cannot do).
+#
+# `doCheck = false` skips the packaging test suite. Those tests exercise
+# `bin/ai-memory`, a Docker-wrapper shell script that needs `docker` or
+# `podman` on PATH — they are host-environment tests, not build tests,
+# and are not Nix's responsibility. Run them manually with
+# `nix develop -c cargo test -p ai-memory-cli --test packaging` if your
+# machine has Docker.
+
+{
+ description = "Long-term memory for AI coding agents";
+
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+ flake-utils.url = "github:numtide/flake-utils";
+ rust-overlay = {
+ url = "github:oxalica/rust-overlay";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ };
+
+ outputs =
+ {
+ nixpkgs,
+ flake-utils,
+ rust-overlay,
+ ...
+ }:
+ flake-utils.lib.eachDefaultSystem (
+ system:
+ let
+ pkgs = import nixpkgs {
+ inherit system;
+ overlays = [ (import rust-overlay) ];
+ };
+
+ # Read the same toolchain file the project pins for every other CI
+ # path — rust-toolchain.toml says `channel = "1.95"`.
+ rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
+
+ rustPlatform = pkgs.makeRustPlatform {
+ rustc = rust;
+ cargo = rust;
+ };
+ in
+ {
+ packages.default = rustPlatform.buildRustPackage {
+ pname = "ai-memory";
+ version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
+
+ src = ./.;
+ cargoLock.lockFile = ./Cargo.lock;
+
+ # No nativeBuildInputs needed — the build is fully self-contained
+ # (SQLite bundled, libgit2 vendored, rustls with webpki-roots).
+
+ # Skip the Tailwind CLI download in the sandbox. The build script
+ # falls back to the vendored static/tailwind.css committed to the
+ # repo (see crates/ai-memory-web/build.rs).
+ TAILWIND_SKIP = "1";
+
+ buildType = "release";
+
+ # The packaging test suite (tests/packaging.rs) exercises the
+ # Docker-wrapper shell script `bin/ai-memory` and needs
+ # docker/podman on PATH — not available in a Nix sandbox. The
+ # rest of the workspace test suite (unit tests + integration)
+ # does not need them and can be run via `nix develop -c cargo
+ # test --workspace` on a machine with Docker.
+ doCheck = false;
+
+ # Install the bundled hook scripts alongside the binary,
+ # mirroring what the AUR PKGBUILD does. Native binary users
+ # (`ai-memory serve`, `install-hooks`) look up hooks under
+ # the binary's share directory at runtime.
+ #
+ # `bin/ai-memory` (the Docker-wrapper shell script) is NOT
+ # installed — Nix users build the native binary directly and
+ # have no need for a Docker wrapper.
+ postInstall = ''
+ mkdir -p $out/share/ai-memory
+ cp -a hooks $out/share/ai-memory/
+
+ # Install the default config template so `ai-memory init`
+ # has a known-good starting point without a network fetch.
+ mkdir -p $out/etc/ai-memory
+ cp crates/ai-memory-cli/templates/config.default.toml \
+ $out/etc/ai-memory/config.default.toml
+ '';
+
+ meta = {
+ description = "Long-term memory for AI coding agents";
+ homepage = "https://github.com/akitaonrails/ai-memory";
+ license = pkgs.lib.licenses.mit;
+ mainProgram = "ai-memory";
+ };
+ };
+
+ devShells.default = pkgs.mkShell {
+ name = "ai-memory-dev";
+
+ buildInputs = [
+ rust
+ pkgs.cargo-watch
+ ];
+
+ # Same escape hatch for local `cargo build` / `cargo test` —
+ # prevents the web crate from trying to download Tailwind.
+ TAILWIND_SKIP = "1";
+
+ shellHook = ''
+ echo ""
+ echo "ai-memory dev shell — Rust $(rustc --version)"
+ echo ""
+ echo " cargo build --workspace # build"
+ echo " cargo test --workspace # unit + integration tests"
+ echo " cargo test -p ai-memory-cli --test packaging # needs docker"
+ echo ""
+ '';
+ };
+ }
+ );
+}