Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions nix/modules/home-manager/openclaw/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,39 @@ let
inst.package;
pluginPackages = plugins.pluginPackagesFor name;
pluginEnvAll = plugins.pluginEnvAllFor name;
mergedConfig0 = stripNulls (
lib.recursiveUpdate (lib.recursiveUpdate baseConfig cfg.config) inst.config
);
existingWorkspace = (((mergedConfig0.agents or { }).defaults or { }).workspace or null);
mergedConfig =
if (cfg.workspace.pinAgentDefaults or true) && existingWorkspace == null then
lib.recursiveUpdate mergedConfig0 {
agents = {
defaults = {
workspace = inst.workspaceDir;
};
};
}

# Determine config source: external file or nix-generated
configFromExternal = inst.externalConfig != null;

# Validate: cannot use both config and externalConfig
configUsed = inst.config != {};
configValidation = if configFromExternal && configUsed then
throw "Cannot use both 'config' and 'externalConfig' options simultaneously. Use only one."
else true;

# For external config, use string directly; for nix config, generate from options
configJson =
if configFromExternal then
inst.externalConfig # already a string (from builtins.readFile or builtins.toJSON)
else
mergedConfig0;
configJson = builtins.toJSON mergedConfig;
let
mergedConfig0 = stripNulls (
lib.recursiveUpdate (lib.recursiveUpdate baseConfig cfg.config) inst.config
);
existingWorkspace = (((mergedConfig0.agents or { }).defaults or { }).workspace or null);
mergedConfig =
if (cfg.workspace.pinAgentDefaults or true) && existingWorkspace == null then
lib.recursiveUpdate mergedConfig0 {
agents = {
defaults = {
workspace = inst.workspaceDir;
};
};
}
else
mergedConfig0;
in builtins.toJSON mergedConfig;

configFile = pkgs.writeText "openclaw-${name}.json" configJson;
gatewayWrapper = pkgs.writeShellScriptBin "openclaw-gateway-${name}" ''
set -euo pipefail
Expand Down
10 changes: 10 additions & 0 deletions nix/modules/home-manager/openclaw/options-instance.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@
description = "OpenClaw config (schema-typed).";
};

externalConfig = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
External openclaw.json content as a string (use builtins.readFile to read from a file).
When set, this file will be used directly instead of generating config from the 'config' option.
Note: Cannot be used together with 'config' - use one or the other.
'';
};

launchd.enable = lib.mkOption {
type = lib.types.bool;
default = true;
Expand Down