pi: merge declared settings into a persisted settings.json #1498

Merged
JakeHillion merged 1 commits from jj/qqkoruyukukv into main 2026-12-06 01:17:35 +00:00
6 changed files with 57 additions and 9 deletions

No files matched your search

+1
View File
@@ -107,6 +107,7 @@
"piPackages"."pi-web-access" = final.callPackage ./pkgs/pi-web-access.nix { };
"piPackages"."background-subagents" = final.callPackage ./pkgs/pi-background-subagents { };
"piPackages"."loop" = final.callPackage ./pkgs/pi-loop { };
"piPackages"."merge-settings" = final.callPackage ./pkgs/pi-merge-settings { };
})
];
mkSystem = import ./lib/mkSystem.nix { inherit inputs; };
+14
View File
@@ -0,0 +1,14 @@
# Your configuration
Your configuration under ~/.pi (settings.json, models.json, agents/,
extensions/, web-search.json and this file) comes from the
JakeHillion/nixos repository, in modules/home/pi/default.nix. Every deploy
replaces the settings.json fields that repository declares, and every other
file in that list, so changes made to them here don't last.
When asked to change how Pi is configured, or when you notice something in
your own configuration worth changing, don't edit those files. Propose the
change to modules/home/pi/default.nix, and make it in the repository only
when asked, following that repository's own instructions. A choice that
should last only for this session needs no change: use /model, /thinking or
/settings without saving it as a default.
+9 -5
View File
@@ -51,6 +51,7 @@ let
video = { enabled = false; };
pdf = { enabled = false; };
};
piSettingsFile = pkgs.writeText "pi-settings.json" (builtins.toJSON piSettings);
piSettings = {
lastChangelogVersion = piPackage.version;
defaultProvider = "openai";
@@ -106,6 +107,7 @@ in
custom.impermanence = lib.mkIf config.custom.impermanence.enable {
userExtraFiles.${user} = [
".pi/agent/auth.json"
".pi/agent/settings.json"
".pi/agent/trust.json"
];
userExtraDirs.${user} = [ ".pi/agent/sessions" ];
@@ -120,7 +122,7 @@ in
mode = "0400";
};
home-manager.users.${user} = {
home-manager.users.${user} = { lib, ... }: {
home = {
packages = [ piPackage ];
sessionVariables = {
@@ -130,10 +132,7 @@ in
};
home.file = {
".pi/agent/settings.json" = {
text = builtins.toJSON piSettings;
force = true;
};
".pi/agent/AGENTS.md".source = ./AGENTS.md;
".pi/agent/models.json" = {
text = builtins.toJSON piModels;
force = true;
@@ -151,6 +150,11 @@ in
force = true;
};
};
# Pi saves its own fields, such as deviceId, into settings.json
home.activation.pi-settings = lib.hm.dag.entryAfter [ "linkGeneration" ] ''
run ${lib.getExe pkgs.piPackages.merge-settings} ${piSettingsFile} "$(${pkgs.coreutils}/bin/readlink -f "$HOME/.pi/agent/settings.json")"
'';
};
};
}
@@ -181,10 +181,8 @@ in
preStart = ''
install -d -m 0700 ${home}/.pi/agent ${home}/.config/jj
install -d ${home}/.pi/agent/{extensions,agents,skills} ${home}/state
# Seed mutable settings, rather than making Pi's runtime state a store link.
if [ ! -e ${home}/.pi/agent/settings.json ]; then
install -m 0600 ${settings} ${home}/.pi/agent/settings.json
fi
# Pi saves its own fields into settings.json
${lib.getExe pkgs.piPackages.merge-settings} ${settings} ${home}/.pi/agent/settings.json
ln -sfn ${jjConfig} ${home}/.config/jj/config.toml
ln -sfn ${pkgs.piPackages.background-subagents} ${home}/.pi/agent/extensions/subagent
ln -sfn ${pkgs.piPackages.loop} ${home}/.pi/agent/extensions/loop
+7
View File
@@ -0,0 +1,7 @@
{ writeShellApplication, jq }:
writeShellApplication {
name = "pi-merge-settings";
runtimeInputs = [ jq ];
text = builtins.readFile ./merge-settings.sh;
}
+24
View File
@@ -0,0 +1,24 @@
# Usage: pi-merge-settings DECLARED TARGET
declared=$1
target=$2
current='{}'
if [ -e "$target" ]; then
current=$(<"$target")
fi
jq -r --slurpfile declared "$declared" '
def leaves: if type == "object" and length > 0
then to_entries[] | [.key] + (.value | leaves)
else [] end;
. as $cur | $declared[0] as $decl
| $decl | keys[] as $k
| select($cur | has($k))
| $cur[$k] | [leaves][] as $p
| select([$decl[$k] | getpath($p)?] != [$cur[$k] | getpath($p)])
| "pi settings: replaced \([$k] + $p | join(".")), which NixOS declares"
' <<<"$current"
jq --slurpfile declared "$declared" '. + $declared[0]' <<<"$current" >"$target.tmp"
mv "$target.tmp" "$target"