Skip to content

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

Rust

Address #989 review: split FHS hardening, gate nix CI, slim settings

Testc75af157f123
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
new file mode 100644
index 00000000..77ca1242
--- /dev/null
+++ b/.github/CODEOWNERS
@@ -0,0 +1,7 @@
+# Nix packaging and NixOS module — maintained by the nix owner.
+/nix/ @rubenlr
+/flake.nix @rubenlr
+/flake.lock @rubenlr
+/scripts/check-nix-packaging.sh @rubenlr
+/scripts/test-nixos-systemd-container.sh @rubenlr
+/.github/workflows/nix.yml @rubenlr
diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml
index 987aa0bc..1e3cd337 100644
--- a/.github/workflows/nix.yml
+++ b/.github/workflows/nix.yml
@@ -1,16 +1,16 @@
name: nix
-# Builds the flake on Linux and macOS so the Nix packaging cannot rot unnoticed.
+# Builds the flake on Linux (and optionally macOS) so the Nix packaging cannot
+# rot unnoticed.
#
-# Matrix: x86_64-linux (package + NixOS module eval + NixOS systemd container
-# smoke) and aarch64-darwin (package + artifact smoke only). NixOS checks and
-# the OCI/systemd container smoke always target x86_64-linux and stay on the
-# Linux leg — Darwin attrs would add noise without signal.
+# Default PR path (path-filtered): x86_64-linux package + check-nix-packaging
+# + NixOS module eval / sandbox-parity. Cheap enough to run when flake inputs
+# or Cargo.lock change.
#
-# ai-memory does not otherwise test on Nix, so without this job `flake.nix`
-# is source nobody executes: it can break through a dependency bump, a
-# toolchain change, or a new build script and stay green because no other
-# job touches it.
+# Expensive legs — aarch64-darwin package smoke and the privileged NixOS
+# systemd container (~14 min) — run only on schedule, workflow_dispatch, or a
+# PR labelled `nix` / `full-ci`. Per AGENTS.md CI pacing: fast per merge, full
+# matrix before release.
#
# Deliberately NOT run on every pull request — a full release build under
# Nix costs far more wall-clock than the rest of the matrix combined, and
@@ -22,6 +22,7 @@ on:
branches: [main]
paths:
- 'flake.nix'
+ - 'flake.lock'
- 'nix/**'
- 'Cargo.lock'
- 'Cargo.toml'
@@ -30,8 +31,10 @@ on:
- 'scripts/test-nixos-systemd-container.sh'
- '.github/workflows/nix.yml'
pull_request:
+ types: [opened, synchronize, reopened, labeled]
paths:
- 'flake.nix'
+ - 'flake.lock'
- 'nix/**'
- 'Cargo.lock'
- 'Cargo.toml'
@@ -59,6 +62,16 @@ jobs:
runner: ubuntu-latest
- system: aarch64-darwin
runner: macos-latest
+ # Linux always runs when this workflow fires. Darwin is gated to
+ # schedule / dispatch / `nix`|`full-ci` label so Cargo.lock bumps (and
+ # pushes to main) do not burn a macOS runner on every dependency PR.
+ if: >-
+ matrix.system == 'x86_64-linux' ||
+ github.event_name == 'schedule' ||
+ github.event_name == 'workflow_dispatch' ||
+ (github.event_name == 'pull_request' &&
+ (contains(github.event.pull_request.labels.*.name, 'nix') ||
+ contains(github.event.pull_request.labels.*.name, 'full-ci')))
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -84,6 +97,7 @@ jobs:
# script imports that rootfs, starts systemd, and checks install +
# /healthz + dataDir restart/volume persistence.
#
+ # Gated like Darwin: schedule / dispatch / `nix`|`full-ci` only.
# Non-goals for this step (do not expand here):
# - A→B package upgrade / SQLite-wiki migration matrix
# - Exhaustive settings-options.nix key matrix
@@ -91,5 +105,11 @@ jobs:
# - Claiming the app Docker image covers the NixOS module
# - Darwin / multi-arch NixOS OCI (Linux x86_64 only by design)
# - Re-asserting sandbox keys (covered by nixos-sandbox-parity)
- - if: matrix.system == 'x86_64-linux'
+ - if: >-
+ matrix.system == 'x86_64-linux' &&
+ (github.event_name == 'schedule' ||
+ github.event_name == 'workflow_dispatch' ||
+ (github.event_name == 'pull_request' &&
+ (contains(github.event.pull_request.labels.*.name, 'nix') ||
+ contains(github.event.pull_request.labels.*.name, 'full-ci'))))
run: scripts/test-nixos-systemd-container.sh
diff --git a/AGENTS.md b/AGENTS.md
index 4d05d9ad..d65698ff 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -312,8 +312,10 @@ no tiers.
- Shell-level checks: `tests/hooks/test_lib.sh`,
`tests/e2e/handoff_smoke.sh`, `scripts/check-native-packaging.sh`,
`scripts/check-nix-packaging.sh` (Nix flake output).
-- `.github/workflows/nix.yml` matrix covers `x86_64-linux` + `aarch64-darwin`;
- NixOS module eval is Linux-only.
+- `.github/workflows/nix.yml`: path-filtered PRs always run `x86_64-linux`
+ (package + NixOS module eval / sandbox-parity). `aarch64-darwin` and the
+ privileged NixOS container smoke run on schedule, `workflow_dispatch`, or
+ a PR labelled `nix` / `full-ci`.
- CI additionally runs `cargo build --release --bin ai-memory` on
Linux/macOS, a Docker image smoke test, `cargo audit` (with the ignores
listed in `ci.yml`), and differential gitleaks scanning.
@@ -540,8 +542,10 @@ Additional boundary rules:
macOS/Windows legs run on a `full-ci` PR label, nightly (windows), or
manual dispatch — and running them is **mandatory right before a
release**: dispatch `ci` (macOS legs) and `windows` on the exact
- release-candidate SHA and wait for green before tagging. Never tag a
- release whose SHA lacks a green full matrix.
+ release-candidate SHA and wait for green before tagging. Nix follows the
+ same rule: Darwin nix build and the privileged NixOS container smoke need
+ `nix` / `full-ci`, schedule, or dispatch (not every `Cargo.lock` bump).
+ Never tag a release whose SHA lacks a green full matrix.
- **Every release updates the Homebrew tap — do not forget it.** After
`release.yml` publishes the GitHub release and its per-target tarballs,
update `~/Projects/homebrew-tap/Formula/ai-memory.rb`: bump `version` and
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8e623e4..6c4d7afb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,15 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- A NixOS module (`nix/nixos-module.nix`, exposed as `nixosModules.default`)
so NixOS hosts can run `services.ai-memory.enable = true` as a hardened
systemd service — dedicated `ai-memory` system user (`nologin`, gated by
- `createUser`) plus a shared systemd sandbox applied to both NixOS and the
- packaged FHS units (`nix/systemd-sandbox.nix`). Typed
- `services.ai-memory.settings` renders declarative `config.toml`; secrets use
+ `createUser`) plus the NixOS systemd sandbox in `nix/systemd-sandbox.nix`.
+ Typed `services.ai-memory.settings` renders declarative `config.toml`
+ (minimal typed keys + `freeformType`; values land in a world-readable store
+ path — keep secrets out, including `llm_headers`); secrets use
`ageSecret`, `sopsSecret`, or `environmentFile` (required for non-loopback
binds). The web UI defaults off (`enableWeb = false`, matching the CLI
flag's own default rather than the packaged unit's hardcoded
`--enable-web`). `flake.nix` adds eval checks for sandbox keys, settings →
`--config`, agenix/sops wiring, refusal contracts (age+sops mutex, secrets
- in `settings.auth`, forbidden `settings.bind`), `ExecStart`
+ in `settings.auth`, forbidden `settings.bind`), escaped `ExecStart`
(`--data-dir` / `serve` / `--transport http`), default `StateDirectory` vs
custom `dataDir` tmpfiles/`ReadWritePaths`, and cheap
network-online / `openFirewall` / `MemoryMax` / `TasksMax` round-trips.
@@ -27,24 +28,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`system.build.toplevel` (via the docker-image rootfs tarball) and
`scripts/test-nixos-systemd-container.sh` runs a privileged systemd
container smoke (`systemctl` + in-container `/healthz` + dataDir
- restart/volume persistence) on the Linux `nix.yml` leg. The existing
- `flake.nix` package/devShell/CLI build is unchanged. (#989)
+ restart/volume persistence). The existing `flake.nix` package/devShell/CLI
+ build is unchanged. (#989)
### Changed
-- `.github/workflows/nix.yml` now builds the flake on `x86_64-linux` and
- `aarch64-darwin` with `scripts/check-nix-packaging.sh` artifact smoke tests
- (binary, hooks, config template, `nix run`); NixOS module eval and the
- NixOS systemd container smoke stay on the Linux leg only. (#989)
-
-### Fixed
-- NixOS systemd container smoke injects a NixOS `PATH` on every
- `docker exec` (`/run/current-system/sw/bin` + profile + `/bin`) so
- `systemctl`/`curl`/`chown` resolve after activation. Bare `chown` under
- `/bin/sh` previously exited 127 once `/healthz` already passed; absolute
- profile paths alone were also missing until activation linked
- `current-system`. Host-side `/healthz` stays in-container because the
- module's default `127.0.0.1` bind is unreachable through Docker
- published ports. (#989)
+- `.github/workflows/nix.yml` builds the flake on `x86_64-linux` for path-
+ filtered PRs and pushes (package smoke + NixOS module eval /
+ sandbox-parity). The `aarch64-darwin` package smoke and the privileged
+ NixOS container smoke run only on schedule, `workflow_dispatch`, or a PR
+ labelled `nix` / `full-ci`. (#989)
## [2.5.2] - 2026-10-01
diff --git a/README.md b/README.md
index b7093e76..0c78ebc2 100644
--- a/README.md
+++ b/README.md
@@ -372,11 +372,12 @@ timestamped backups next to any file they touch.
### NixOS
This flake ships a NixOS module (`nixosModules.default`) with a
-`systemd.services.ai-memory` unit. Isolation matches the packaged FHS unit:
-a dedicated `ai-memory` system user (`nologin`, no linger) plus the same
-systemd sandbox (`ProtectSystem = "strict"`, empty capability sets,
+`systemd.services.ai-memory` unit: a dedicated `ai-memory` system user
+(`nologin`, no linger) plus a hardened systemd sandbox
+(`ProtectSystem = "strict"`, empty capability sets,
`MemoryDenyWriteExecute`, `RestrictAddressFamilies`, and the rest — see
-[`nix/systemd-sandbox.nix`](nix/systemd-sandbox.nix)).
+[`nix/systemd-sandbox.nix`](nix/systemd-sandbox.nix)). Packaged FHS units
+under `packaging/systemd/` keep their existing lighter hardening.
```nix
{
@@ -407,10 +408,12 @@ systemd sandbox (`ProtectSystem = "strict"`, empty capability sets,
}
```
-Declarative non-secret config lives in `services.ai-memory.settings` (typed
-options mirroring `config.toml`, plus `freeformType` for forward-compat keys).
-The module renders a generated TOML file and passes `--config`. Top-level
-`bind`, `port`, and `enableWeb` win over duplicate settings keys.
+Declarative non-secret config lives in `services.ai-memory.settings` (a
+small typed set for common keys, plus `freeformType` for the rest of
+`config.toml`). The module renders a generated TOML file and passes
+`--config`. Top-level `bind`, `port`, and `enableWeb` win over duplicate
+settings keys. Anything in `settings` (including `llm_headers`) lands in a
+world-readable Nix store path — do not put API keys there.
Secrets such as `AI_MEMORY_AUTH_TOKEN` never go in `settings` or the Nix
store. Use `ageSecret` / `sopsSecret` (consume `config.age` / `config.sops`
diff --git a/docs/install.md b/docs/install.md
index e330b764..117d3df4 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -751,15 +751,17 @@ for the flake and module — what CI runs, and what each tier proves.
1. **Package smoke** — `nix build .#packages.<system>.default` then
`scripts/check-nix-packaging.sh ./result` (binary `--version`, hooks
- tree, config template, `nix run`). Runs on Linux and Darwin in
- `.github/workflows/nix.yml`.
+ tree, config template, `nix run`). Linux runs on every path-filtered
+ `nix.yml` PR; Darwin is schedule / `workflow_dispatch` / `nix` or
+ `full-ci` label only.
2. **Eval contracts** — `nix build .#checks.x86_64-linux.nixos-module-eval`
and `nixos-sandbox-parity`. Cheap Linux-only asserts for enable/bind/
`--config`/secrets wiring, refusal messages (age+sops mutex, secrets in
- `settings.auth`, `settings.bind`), `ExecStart` (`--data-dir`, `serve`,
- `--transport http`), default `StateDirectory` vs custom `dataDir`
- tmpfiles/`ReadWritePaths`, and sandbox key parity with
- `nix/systemd-sandbox.nix`.
+ `settings.auth`, `settings.bind`), escaped `ExecStart` (`--data-dir`,
+ `serve`, `--transport http`), default `StateDirectory` vs custom
+ `dataDir` tmpfiles/`ReadWritePaths`, and sandbox key parity with
+ `nix/systemd-sandbox.nix`. Runs on path-filtered PRs with the Linux
+ package job.
3. **Toplevel → OCI → container smoke** — one closure path. Building
`packages.x86_64-linux.nixos-ai-memory-docker` builds
`system.build.toplevel` once (via the nixpkgs docker-image tarball);
@@ -774,8 +776,9 @@ scripts/test-nixos-systemd-container.sh
(the module's default loopback bind is unreachable via Docker `-p`),
writes a
marker under `/var/lib/ai-memory`, restarts the unit, and (by default)
- remounts a named volume once. Wired into the Linux leg of `nix.yml`
- only (same path filters as the rest of the Nix job).
+ remounts a named volume once. Gated in `nix.yml` to schedule /
+ `workflow_dispatch` / `nix` or `full-ci` label (not every Cargo.lock
+ bump).
**Non-goals** (do not treat these as covered by the ladder above):
diff --git a/docs/support-matrix.md b/docs/support-matrix.md
index 8c5a42d9..83b46b45 100644
--- a/docs/support-matrix.md
+++ b/docs/support-matrix.md
@@ -7,6 +7,7 @@
| Area | Status | Notes |
|---|---|---|
| Linux | Supported | Primary Docker/server target and CI platform. Published Docker images support `linux/amd64` and `linux/arm64`. Native Arch/AUR packages include system and user systemd units. |
+| NixOS | Supported | Flake package (`nix build` / `nix run`) plus `nixosModules.default` (`services.ai-memory.enable`) with a hardened systemd unit, typed/freeform `settings` → generated `config.toml`, and agenix / sops-nix / `environmentFile` secrets. Web UI opt-in (`enableWeb = false` by default). `settings` (including `llm_headers`) lands in a world-readable Nix store path — keep secrets in age/sops/env. CI: Linux package + module eval on path-filtered PRs; Darwin package and privileged container smoke on schedule / dispatch / `nix` or `full-ci` label. See README NixOS section and [`docs/install.md`](install.md#nix--nixos). |
| macOS | Supported | Workspace tests run in CI; tagged releases publish native `ai-memory-macos-aarch64.tar.gz` and `ai-memory-macos-x86_64.tar.gz` binaries, which include a per-user launchd agent. The native binary is the recommended path on Apple Silicon. A source-built menu bar app (`companions/ai-memory-macos`) bundles that binary, starts the LaunchAgent, and opens `/web` and `ai-memory status` — README quick-start and [`docs/macos.md`](macos.md) Scenario D. |
| Windows via WSL2 | Supported | Use the Linux install path inside WSL2 when the agent runs there. |
| Native Windows | Experimental | Tagged releases publish `ai-memory-windows-x86_64.zip` with `ai-memory.exe`; Docker Desktop wrapper and source builds are also available. Native `ai-memory upgrade` is supported for writable x86_64 zip installs (checksum-verified zip + rename-aside self-replace + sibling `hooks/` refresh). Local supported profiles default to host-native hook commands; Claude Code may use its Windows exec form, while other agents use native single command strings matching their hook schema. PowerShell/Git Bash scripts are compatibility fallbacks. See [`docs/windows.md`](windows.md). |
diff --git a/nix/nixos-module.nix b/nix/nixos-module.nix
index 2b711208..fbf85161 100644
--- a/nix/nixos-module.nix
+++ b/nix/nixos-module.nix
@@ -3,7 +3,7 @@
# Standalone: no reference to `self` or anything flake-specific, so it stays
# importable outside this flake. `flake.nix`'s `nixosModules.default` wraps
# this file and supplies a default for `package` by closing over `self`.
-{ config, lib, pkgs, ... }:
+{ config, lib, pkgs, utils, ... }:
let
cfg = config.services.ai-memory;
@@ -142,6 +142,11 @@ in
Declarative config.toml fragment (non-secret keys only). Rendered to a
generated file and passed as `--config`. Top-level `bind`, `port`, and
`enableWeb` service options win over duplicate keys here.
+
+ A small typed set covers common keys; `freeformType` accepts any other
+ TOML key. Values here land in a world-readable Nix store path — never
+ put secrets in `settings` (including `llm_headers` / auth tokens);
+ use `ageSecret`, `sopsSecret`, or `environmentFile` instead.
'';
};
@@ -283,7 +288,7 @@ in
Type = "simple";
User = cfg.user;
Group = cfg.group;
- ExecStart = lib.concatStringsSep " " execStartArgs;
+ ExecStart = utils.escapeSystemdExecArgs execStartArgs;
Restart = "on-failure";
RestartSec = "5s";
TimeoutStopSec = "30s";
diff --git a/nix/settings-options.nix b/nix/settings-options.nix
index 48dd9060..63284e84 100644
--- a/nix/settings-options.nix
+++ b/nix/settings-options.nix
@@ -1,5 +1,10 @@
-# Typed `services.ai-memory.settings` options mirroring config.toml.
-# Secrets belong in age/sops/environmentFile, not here.
+# Typed `services.ai-memory.settings` options for common non-secret keys.
+#
+# The settings submodule also sets `freeformType = pkgs.formats.toml.type`, so
+# any other `config.toml` key can be set without listing it here. Keep this
+# file small: only type keys we want docs/validation for. Nested schema
+# sections (decay, auto_improve, dream, …) stay freeform to avoid drifting
+# against the Rust config.
{ lib, ... }:
let
@@ -17,66 +22,11 @@ in
default = null;
};
- tcp_keepalive_secs = lib.mkOption {
- type = types.nullOr types.int;
- default = null;
- };
-
server_url = lib.mkOption {
type = types.nullOr types.str;
default = null;
};
- base_path = lib.mkOption {
- type = types.nullOr types.str;
- default = null;
- };
-
- hook_rate_per_sec = lib.mkOption {
- type = types.nullOr types.float;
- default = null;
- };
-
- hook_rate_burst = lib.mkOption {
- type = types.nullOr types.float;
- default = null;
- };
-
- capture_assistant = lib.mkOption {
- type = types.nullOr types.bool;
- default = null;
- };
-
- consolidate_on_session_end = lib.mkOption {
- type = types.nullOr types.bool;
- default = null;
- };
-
- backfill_on_start = lib.mkOption {
- type = types.nullOr types.bool;
- default = null;
- };
-
- run_autowire = lib.mkOption {
- type = types.nullOr types.bool;
- default = null;
- };
-
- strip_root_combinators = lib.mkOption {
- type = types.nullOr types.bool;
- default = null;
- };
-
- gemini_safe_schemas = lib.mkOption {
- type = types.nullOr types.bool;
- default = null;
- };
-
- reranker = lib.mkOption {
- type = types.nullOr types.str;
- default = null;
- };
-
llm_provider = lib.mkOption {
type = types.nullOr types.str;
default = null;
@@ -92,24 +42,17 @@ in
default = null;
};
- llm_compat_strict = lib.mkOption {
- type = types.nullOr types.bool;
- default = null;
- };
-
- llm_timeout_secs = lib.mkOption {
- type = types.nullOr types.int;
- default = null;
- };
-
- llm_reasoning_effort = lib.mkOption {
- type = types.nullOr types.str;
- default = null;
- };
-
llm_headers = lib.mkOption {
type = types.nullOr (types.listOf types.str);
default = null;
+ description = ''
+ Extra HTTP headers for the LLM provider (`Header: value` strings).
+
+ Warning: values set here land in the generated `config.toml` Nix store
+ path, which is world-readable. Do not put API keys or other secrets in
+ `llm_headers`; pass those via `ageSecret` / `sopsSecret` /
+ `environmentFile` (for example `AI_MEMORY_LLM_HEADERS`) instead.
+ '';
};
embedding_provider = lib.mkOption {
@@ -122,190 +65,6 @@ in
default = null;
};
- embedding_dim = lib.mkOption {
- type = types.nullOr types.int;
- default = null;
- };
-
- embedding_base_url = lib.mkOption {
- type = types.nullOr types.str;
- default = null;
- };
-
- cors_allow_origins = lib.mkOption {
- type = types.nullOr (types.listOf types.str);
- default = null;
- };
-
- decay = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- lambda = lib.mkOption { type = types.nullOr types.float; default = null; };
- sigma = lib.mkOption { type = types.nullOr types.float; default = null; };
- mu = lib.mkOption { type = types.nullOr types.float; default = null; };
- salience_default = lib.mkOption { type = types.nullOr types.float; default = null; };
- cold_threshold = lib.mkOption { type = types.nullOr types.float; default = null; };
- hard_delete_after_days = lib.mkOption { type = types.nullOr types.int; default = null; };
- breadth_weight = lib.mkOption { type = types.nullOr types.float; default = null; };
- observation_retention_days = lib.mkOption { type = types.nullOr types.int; default = null; };
- observation_prune_batch = lib.mkOption { type = types.nullOr types.int; default = null; };
- compact_cold_episodic = lib.mkOption { type = types.nullOr types.bool; default = null; };
- dedup_cold_clusters = lib.mkOption { type = types.nullOr types.bool; default = null; };
- dedup_min_pts = lib.mkOption { type = types.nullOr types.int; default = null; };
- dedup_max_eps = lib.mkOption { type = types.nullOr types.float; default = null; };
- half_life_days = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- working = lib.mkOption { type = types.nullOr types.float; default = null; };
- episodic = lib.mkOption { type = types.nullOr types.float; default = null; };
- semantic = lib.mkOption { type = types.nullOr types.float; default = null; };
- procedural = lib.mkOption { type = types.nullOr types.float; default = null; };
- };
- });
- default = null;
- };
- };
- });
- default = null;
- };
-
- sanitize = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- extra_patterns = lib.mkOption {
- type = types.nullOr (types.listOf types.str);
- default = null;
- };
- allowlist = lib.mkOption {
- type = types.nullOr (types.listOf types.str);
- default = null;
- };
- };
- });
- default = null;
- };
-
- slots = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- per_user = lib.mkOption { type = types.nullOr types.bool; default = null; };
- };
- });
- default = null;
- };
-
- consolidation = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- max_input_tokens = lib.mkOption { type = types.nullOr types.int; default = null; };
- max_output_tokens = lib.mkOption { type = types.nullOr types.int; default = null; };
- };
- });
- default = null;
- };
-
- auto_improve = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- require_approval = lib.mkOption { type = types.nullOr types.bool; default = null; };
- on_session_end = lib.mkOption { type = types.nullOr types.bool; default = null; };
- min_observations = lib.mkOption { type = types.nullOr types.int; default = null; };
- min_session_duration_secs = lib.mkOption { type = types.nullOr types.int; default = null; };
- min_confidence = lib.mkOption { type = types.nullOr types.float; default = null; };
- max_input_tokens = lib.mkOption { type = types.nullOr types.int; default = null; };
- max_proposals_per_run = lib.mkOption { type = types.nullOr types.int; default = null; };
- eval = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- enabled = lib.mkOption { type = types.nullOr types.bool; default = null; };
- command = lib.mkOption { type = types.nullOr types.str; default = null; };
- timeout_secs = lib.mkOption { type = types.nullOr types.int; default = null; };
- targets = lib.mkOption {
- type = types.nullOr (types.listOf types.str);
- default = null;
- };
- min_delta = lib.mkOption { type = types.nullOr types.float; default = null; };
- };
- });
- default = null;
- };
- scheduler = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- enabled = lib.mkOption { type = types.nullOr types.bool; default = null; };
- interval_secs = lib.mkOption { type = types.nullOr types.int; default = null; };
- max_sessions_per_tick = lib.mkOption { type = types.nullOr types.int; default = null; };
- min_session_age_secs = lib.mkOption { type = types.nullOr types.int; default = null; };
- experience_every_sessions = lib.mkOption { type = types.nullOr types.int; default = null; };
- experience_sessions = lib.mkOption { type = types.nullOr types.int; default = null; };
- };
- });
- default = null;
- };
- };
- });
- default = null;
- };
-
- maintenance = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- enabled = lib.mkOption { type = types.nullOr types.bool; default = null; };
- forget_sweep_interval_secs = lib.mkOption { type = types.nullOr types.int; default = null; };
- lint_interval_secs = lib.mkOption { type = types.nullOr types.int; default = null; };
- embedding_backfill_interval_secs = lib.mkOption { type = types.nullOr types.int; default = null; };
- };
- });
- default = null;
- };
-
- dream = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- enabled = lib.mkOption { type = types.nullOr types.bool; default = null; };
- interval_secs = lib.mkOption { type = types.nullOr types.int; default = null; };
- idle_window_secs = lib.mkOption { type = types.nullOr types.int; default = null; };
- min_pts = lib.mkOption { type = types.nullOr types.int; default = null; };
- max_eps = lib.mkOption { type = types.nullOr types.float; default = null; };
- max_clusters_per_run = lib.mkOption { type = types.nullOr types.int; default = null; };
- min_cold_pages = lib.mkOption { type = types.nullOr types.int; default = null; };
- };
- });
- default = null;
- };
-
- retrieval = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- query_intent = lib.mkOption { type = types.nullOr types.bool; default = null; };
- session_recall_bonus = lib.mkOption { type = types.nullOr types.float; default = null; };
- abstract_vectors = lib.mkOption { type = types.nullOr types.bool; default = null; };
- belief_authority_weight = lib.mkOption { type = types.nullOr types.float; default = null; };
- };
- });
- default = null;
- };
-
- routing = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- mid_session = lib.mkOption { type = types.nullOr types.str; default = null; };
- };
- });
- default = null;
- };
-
- auto_scope = lib.mkOption {
- type = types.nullOr (types.submodule {
- options = {
- mode = lib.mkOption { type = types.nullOr types.str; default = null; };
- session_ttl_secs = lib.mkOption { type = types.nullOr types.int; default = null; };
- max_entries = lib.mkOption { type = types.nullOr types.int; default = null; };
- };
- });
- default = null;
- };
-
auth = lib.mkOption {
type = types.nullOr (types.submodule {
# Freeform so a mistaken secret key reaches the module assertion
diff --git a/nix/systemd-sandbox.nix b/nix/systemd-sandbox.nix
index 3d1ad552..56453589 100644
--- a/nix/systemd-sandbox.nix
+++ b/nix/systemd-sandbox.nix
@@ -1,8 +1,9 @@
-# Shared systemd hardening for ai-memory (NixOS module + FHS units).
+# Shared systemd hardening for the NixOS ai-memory module.
#
-# Keep packaging/systemd/ai-memory.service and ai-memory-user.service aligned
-# with these keys; scripts/check-native-packaging.sh asserts the system unit
-# contains every entry below.
+# Applied by `nix/nixos-module.nix`. Packaged FHS units under
+# `packaging/systemd/` keep their existing lighter hardening for now;
+# aligning those units with this sandbox is a follow-up (needs a real unit
+# start test — `systemd-analyze verify` alone is not enough).
{ lib, ... }:
{
@@ -36,7 +37,9 @@
ProtectSystem = "strict";
};
- # User-unit sandbox: same confinement where %h paths must stay writable.
+ # User-unit sandbox (reserved for a future FHS user-unit hardening PR).
+ # Same confinement keys less ProtectHome/ProtectSystem, which conflict
+ # with %h data paths.
aiMemoryUserSandbox = {
CapabilityBoundingSet = [ ];
AmbientCapabilities = [ ];
diff --git a/packaging/systemd/ai-memory-user.service b/packaging/systemd/ai-memory-user.service
index 6cc67b34..d70e5947 100644
--- a/packaging/systemd/ai-memory-user.service
+++ b/packaging/systemd/ai-memory-user.service
@@ -8,24 +8,6 @@ EnvironmentFile=-%h/.config/ai-memory/env
ExecStart=/usr/bin/ai-memory --data-dir %h/.local/share/ai-memory --config %h/.config/ai-memory/config.toml serve --transport http --enable-web
Restart=on-failure
RestartSec=5s
-CapabilityBoundingSet=
-AmbientCapabilities=
-MemoryDenyWriteExecute=true
-RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
-RestrictNamespaces=true
-RestrictRealtime=true
-RestrictSUIDSGID=true
-LockPersonality=true
-PrivateDevices=true
-RemoveIPC=true
-ProtectKernelTunables=true
-ProtectKernelModules=true
-ProtectKernelLogs=true
-ProtectControlGroups=true
-ProtectClock=true
-ProtectHostname=true
-SystemCallArchitectures=native
-UMask=0077
NoNewPrivileges=true
PrivateTmp=true
diff --git a/packaging/systemd/ai-memory.service b/packaging/systemd/ai-memory.service
index 4f097a83..47badbd6 100644
--- a/packaging/systemd/ai-memory.service
+++ b/packaging/systemd/ai-memory.service
@@ -12,29 +12,8 @@ EnvironmentFile=-/etc/ai-memory/env
ExecStart=/usr/bin/ai-memory --data-dir /var/lib/ai-memory --config /etc/ai-memory/config.toml serve --transport http --enable-web
Restart=on-failure
RestartSec=5s
-TimeoutStopSec=30s
-StartLimitBurst=5
-StartLimitIntervalSec=60s
StateDirectory=ai-memory
StateDirectoryMode=0750
-CapabilityBoundingSet=
-AmbientCapabilities=
-MemoryDenyWriteExecute=true
-RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
-RestrictNamespaces=true
-RestrictRealtime=true
-RestrictSUIDSGID=true
-LockPersonality=true
-PrivateDevices=true
-RemoveIPC=true
-ProtectKernelTunables=true
-ProtectKernelModules=true
-ProtectKernelLogs=true
-ProtectControlGroups=true
-ProtectClock=true
-ProtectHostname=true
-SystemCallArchitectures=native
-UMask=0077
NoNewPrivileges=true
PrivateTmp=true
ProtectHome=true
diff --git a/scripts/check-native-packaging.sh b/scripts/check-native-packaging.sh
index f7b43f86..5a3e3d1d 100755
--- a/scripts/check-native-packaging.sh
+++ b/scripts/check-native-packaging.sh
@@ -191,34 +191,12 @@ main() {
"${TMP_ROOT}/usr/lib/systemd/system/ai-memory-user-parse-test.service"
systemd-analyze --root="${TMP_ROOT}" verify ai-memory-user-parse-test.service
- log "Checking expected native paths, sandbox, and modes"
+ log "Checking expected native paths and modes"
assert_contains packaging/systemd/ai-memory.service "--data-dir /var/lib/ai-memory"
assert_contains packaging/systemd/ai-memory.service "--config /etc/ai-memory/config.toml"
assert_contains packaging/systemd/ai-memory.service "EnvironmentFile=-/etc/ai-memory/env"
assert_contains packaging/systemd/ai-memory.service "StateDirectory=ai-memory"
assert_contains packaging/systemd/ai-memory.service "ReadWritePaths=/var/lib/ai-memory"
- for sandbox_key in \
- "CapabilityBoundingSet=" \
- "AmbientCapabilities=" \
- "MemoryDenyWriteExecute=true" \
- "RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6" \
- "RestrictNamespaces=true" \
- "RestrictRealtime=true" \
- "RestrictSUIDSGID=true" \
- "LockPersonality=true" \
- "PrivateDevices=true" \
- "RemoveIPC=true" \
- "ProtectKernelTunables=true" \
- "ProtectKernelModules=true" \
- "ProtectKernelLogs=true" \
- "ProtectControlGroups=true" \
- "ProtectClock=true" \
- "ProtectHostname=true" \
- "SystemCallArchitectures=native" \
- "UMask=0077"; do
- assert_contains packaging/systemd/ai-memory.service "${sandbox_key}"
- assert_contains packaging/systemd/ai-memory-user.service "${sandbox_key}"
- done
assert_contains packaging/systemd/ai-memory-user.service "--data-dir %h/.local/share/ai-memory"
assert_contains packaging/systemd/ai-memory-user.service "--config %h/.config/ai-memory/config.toml"
assert_contains packaging/systemd/ai-memory-user.service "EnvironmentFile=-%h/.config/ai-memory/env"