Skip to content

Commit e34ccca

Browse files
committed
cli: refuse config mutators in Nix mode
1 parent 2bddd25 commit e34ccca

27 files changed

Lines changed: 363 additions & 10 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Docs: https://docs.openclaw.ai
107107
- Developer tooling: add checked-in VS Code Gateway debugging configs and an opt-in `OUTPUT_SOURCE_MAPS=1` source-map build path for breakpoints in TypeScript source. (#45710) Thanks @SwissArmyBud.
108108
- Managed proxy: add `proxy.loopbackMode` for Gateway loopback control-plane traffic, allowing operators to keep the default Gateway loopback bypass, force loopback Gateway traffic through the proxy, or block it. (#77018) Thanks @jesse-merhi.
109109
- Telegram/native commands: show the current thinking level above the `/think` level picker so users can see the active setting before changing it. (#78278) Thanks @obviyus.
110+
- Config/Nix: keep startup-derived plugin enablement, gateway auth tokens, control UI origins, and owner-display secrets runtime-only instead of rewriting `openclaw.json`; in Nix mode, config writers, mutating `openclaw update`, plugin lifecycle mutators, and doctor repair/token-generation now refuse with agent-first nix-openclaw guidance. Thanks @joshp123.
110111

111112
### Fixes
112113

‎docs/cli/config.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ sidebarTitle: "Config"
88

99
Config helpers for non-interactive edits in `openclaw.json`: get/set/patch/unset/file/schema/validate values by path and print the active config file. Run without a subcommand to open the configure wizard (same as `openclaw configure`).
1010

11+
<Note>
12+
When `OPENCLAW_NIX_MODE=1`, OpenClaw treats `openclaw.json` as immutable. Read-only commands such as `config get`, `config file`, `config schema`, and `config validate` still work, but config writers refuse. Agents should edit the Nix source for the install instead; for the first-party nix-openclaw distribution, use [nix-openclaw Quick Start](https://github.com/openclaw/nix-openclaw#quick-start) and set values under `programs.openclaw.config` or `instances.<name>.config`.
13+
</Note>
14+
1115
## Root options
1216

1317
<ParamField path="--section <section>" type="string">

‎docs/cli/doctor.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ openclaw doctor --generate-gateway-token
3838

3939
Notes:
4040

41+
- In Nix mode (`OPENCLAW_NIX_MODE=1`), read-only doctor checks still work, but `doctor --fix`, `doctor --repair`, `doctor --yes`, and `doctor --generate-gateway-token` are disabled because `openclaw.json` is immutable. Edit the Nix source for this install instead; for nix-openclaw, use the agent-first [Quick Start](https://github.com/openclaw/nix-openclaw#quick-start).
4142
- Interactive prompts (like keychain/OAuth fixes) only run when stdin is a TTY and `--non-interactive` is **not** set. Headless runs (cron, Telegram, no terminal) will skip prompts.
4243
- Performance: non-interactive `doctor` runs skip eager plugin loading so headless health checks stay fast. Interactive sessions still fully load plugins when a check needs their contribution.
4344
- `--fix` (alias for `--repair`) writes a backup to `~/.openclaw/openclaw.json.bak` and drops unknown config keys, listing each removal.

‎docs/cli/plugins.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ For slow install, inspect, uninstall, or registry-refresh investigation, run the
5959
command with `OPENCLAW_PLUGIN_LIFECYCLE_TRACE=1`. The trace writes phase timings
6060
to stderr and keeps JSON output parseable. See [Debugging](/help/debugging#plugin-lifecycle-trace).
6161

62+
<Note>
63+
In Nix mode (`OPENCLAW_NIX_MODE=1`), plugin lifecycle mutators are disabled. Use the Nix source for this install instead of `plugins install`, `plugins update`, `plugins uninstall`, `plugins enable`, or `plugins disable`; for nix-openclaw, use the agent-first [Quick Start](https://github.com/openclaw/nix-openclaw#quick-start).
64+
</Note>
65+
6266
<Note>
6367
Bundled plugins ship with OpenClaw. Some are enabled by default (for example bundled model providers, bundled speech providers, and the bundled browser plugin); others require `plugins enable`.
6468

@@ -293,7 +297,7 @@ Use `--pin` on npm installs to save the resolved exact spec (`name@version`) in
293297

294298
Plugin install metadata is machine-managed state, not user config. Installs and updates write it to `plugins/installs.json` under the active OpenClaw state directory. Its top-level `installRecords` map is the durable source of install metadata, including records for broken or missing plugin manifests. The `plugins` array is the manifest-derived cold registry cache. The file includes a do-not-edit warning and is used by `openclaw plugins update`, uninstall, diagnostics, and the cold plugin registry.
295299

296-
When OpenClaw sees shipped legacy `plugins.installs` records in config, it moves them into the plugin index and removes the config key; if either write fails, the config records are kept so the install metadata is not lost.
300+
When OpenClaw sees shipped legacy `plugins.installs` records in config, runtime reads treat them as compatibility input without rewriting `openclaw.json`. Explicit plugin writes and `openclaw doctor --fix` move those records into the plugin index and remove the config key when config writes are allowed; if either write fails, the config records are kept so the install metadata is not lost.
297301

298302
### Uninstall
299303

‎docs/cli/setup.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ title: "Setup"
1010

1111
Initialize `~/.openclaw/openclaw.json` and the agent workspace.
1212

13+
<Note>
14+
`openclaw setup` is for mutable config installs. In Nix mode (`OPENCLAW_NIX_MODE=1`), OpenClaw refuses setup writes because the config file is managed by Nix. Agents should use the first-party [nix-openclaw Quick Start](https://github.com/openclaw/nix-openclaw#quick-start) or the equivalent source config for another Nix package.
15+
</Note>
16+
1317
Related:
1418

1519
- Getting started: [Getting started](/start/getting-started)

‎docs/cli/update.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ console verbosity and file log level are separate: Gateway `--verbose` affects
5252
terminal/WebSocket output, while file logs require `logging.level: "debug"` or
5353
`"trace"` in config. See [Gateway logging](/gateway/logging).
5454

55+
<Note>
56+
In Nix mode (`OPENCLAW_NIX_MODE=1`), mutating `openclaw update` runs are disabled. Update the Nix source or flake input for this install instead; for nix-openclaw, use the agent-first [Quick Start](https://github.com/openclaw/nix-openclaw#quick-start). `openclaw update status` and `openclaw update --dry-run` remain read-only.
57+
</Note>
58+
5559
<Warning>
5660
Downgrades require confirmation because older versions can break configuration.
5761
</Warning>

‎docs/install/nix.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ read_when:
77
title: "Nix"
88
---
99

10-
Install OpenClaw declaratively with **[nix-openclaw](https://github.com/openclaw/nix-openclaw)** - a batteries-included Home Manager module.
10+
Install OpenClaw declaratively with **[nix-openclaw](https://github.com/openclaw/nix-openclaw)** - the first-party, batteries-included Home Manager module.
1111

1212
<Info>
1313
The [nix-openclaw](https://github.com/openclaw/nix-openclaw) repo is the source of truth for Nix installation. This page is a quick overview.
@@ -50,7 +50,7 @@ See the [nix-openclaw README](https://github.com/openclaw/nix-openclaw) for full
5050

5151
## Nix-mode runtime behavior
5252

53-
When `OPENCLAW_NIX_MODE=1` is set (automatic with nix-openclaw), OpenClaw enters a deterministic mode that disables auto-install flows.
53+
When `OPENCLAW_NIX_MODE=1` is set (automatic with nix-openclaw), OpenClaw enters a deterministic mode for Nix-managed installs. Other Nix packages can set the same mode; nix-openclaw is the first-party reference.
5454

5555
You can also set it manually:
5656

@@ -67,6 +67,8 @@ defaults write ai.openclaw.mac openclaw.nixMode -bool true
6767
### What changes in Nix mode
6868

6969
- Auto-install and self-mutation flows are disabled
70+
- `openclaw.json` is treated as immutable. Startup-derived defaults stay runtime-only, and config writers such as setup, onboarding, mutating `openclaw update`, plugin install/update/uninstall/enable, `doctor --fix`, `doctor --generate-gateway-token`, and `openclaw config set` refuse to edit the file.
71+
- Agents should edit the Nix source instead. For nix-openclaw, use the agent-first [Quick Start](https://github.com/openclaw/nix-openclaw#quick-start) and set config under `programs.openclaw.config` or `instances.<name>.config`.
7072
- Missing dependencies surface Nix-specific remediation messages
7173
- UI surfaces a read-only Nix mode banner
7274

‎docs/plugins/manage-plugins.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ Uninstall removes the plugin's config entry, plugin index record, allow/deny lis
109109
entries, and linked load paths when applicable. Managed install directories are
110110
removed unless you pass `--keep-files`.
111111

112+
In Nix mode (`OPENCLAW_NIX_MODE=1`), plugin install, update, uninstall, enable,
113+
and disable commands are disabled. Manage those choices in the Nix source for
114+
the install instead; for nix-openclaw, use the agent-first
115+
[Quick Start](https://github.com/openclaw/nix-openclaw#quick-start).
116+
112117
## Publish plugins
113118

114119
You can publish external plugins to [ClawHub](https://clawhub.ai), npmjs.com, or

‎docs/tools/plugin.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ top-level `installRecords` and rebuildable manifest metadata in `plugins`. If
574574
the registry is missing, stale, or invalid, `openclaw plugins registry
575575
--refresh` rebuilds its manifest view from install records, config policy, and
576576
manifest/package metadata without loading plugin runtime modules.
577+
578+
In Nix mode (`OPENCLAW_NIX_MODE=1`), plugin lifecycle mutators are disabled.
579+
Manage plugin package selection and config through the Nix source for the
580+
install instead; for nix-openclaw, start with the agent-first
581+
[Quick Start](https://github.com/openclaw/nix-openclaw#quick-start).
577582
`openclaw plugins update <id-or-npm-spec>` applies to tracked installs. Passing
578583
an npm package spec with a dist-tag or exact version resolves the package name
579584
back to the tracked plugin record and records the new spec for future updates.

‎src/auto-reply/reply/commands-plugins.install.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,35 @@ describe("handleCommands /plugins install", () => {
169169
});
170170
});
171171

172+
it("refuses plugin installs in Nix mode before package installer side effects", async () => {
173+
const previousNixMode = process.env.OPENCLAW_NIX_MODE;
174+
process.env.OPENCLAW_NIX_MODE = "1";
175+
try {
176+
await withTempHome("openclaw-command-plugins-home-", async () => {
177+
const workspaceDir = await workspaceHarness.createWorkspace();
178+
const params = buildPluginsParams("/plugins install @acme/demo", workspaceDir);
179+
const result = await handlePluginsCommand(params, true);
180+
if (result === null) {
181+
throw new Error("expected plugin install result");
182+
}
183+
184+
expect(result.reply?.text).toContain("OPENCLAW_NIX_MODE=1");
185+
expect(result.reply?.text).toContain("nix-openclaw#quick-start");
186+
expect(installPluginFromNpmSpecMock).not.toHaveBeenCalled();
187+
expect(installPluginFromPathMock).not.toHaveBeenCalled();
188+
expect(installPluginFromClawHubMock).not.toHaveBeenCalled();
189+
expect(installPluginFromGitSpecMock).not.toHaveBeenCalled();
190+
expect(persistPluginInstallMock).not.toHaveBeenCalled();
191+
});
192+
} finally {
193+
if (previousNixMode === undefined) {
194+
delete process.env.OPENCLAW_NIX_MODE;
195+
} else {
196+
process.env.OPENCLAW_NIX_MODE = previousNixMode;
197+
}
198+
}
199+
});
200+
172201
it("installs from an explicit git: spec", async () => {
173202
installPluginFromGitSpecMock.mockResolvedValue({
174203
ok: true,

0 commit comments

Comments
 (0)