mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-20 13:02:17 +00:00
fix: hardcode pi binary path, set XDG env for npm
npm prefix discovery fails in systemd and activation contexts because NPM_CONFIG_USERCONFIG and XDG_DATA_HOME are not set. Hardcode the known path ~/.local/share/npm/bin/pi instead.
This commit is contained in:
parent
345c38bfc9
commit
4860769776
2 changed files with 19 additions and 16 deletions
23
home/pi.nix
23
home/pi.nix
|
|
@ -1,9 +1,14 @@
|
||||||
{
|
{
|
||||||
|
config,
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
hostConfig,
|
hostConfig,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
npmDir = "${config.xdg.dataHome}/npm";
|
||||||
|
piBin = "${npmDir}/bin/pi";
|
||||||
|
in
|
||||||
lib.mkIf hostConfig.isLinux {
|
lib.mkIf hostConfig.isLinux {
|
||||||
# Install pi-coding-agent globally via npm at activation time.
|
# Install pi-coding-agent globally via npm at activation time.
|
||||||
home.activation.installPiAgent = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
home.activation.installPiAgent = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||||
|
|
@ -13,11 +18,11 @@ lib.mkIf hostConfig.isLinux {
|
||||||
pkgs.coreutils
|
pkgs.coreutils
|
||||||
]
|
]
|
||||||
}:$PATH"
|
}:$PATH"
|
||||||
|
export NPM_CONFIG_USERCONFIG="${config.xdg.configHome}/npm/npmrc"
|
||||||
|
export XDG_DATA_HOME="${config.xdg.dataHome}"
|
||||||
|
export XDG_CACHE_HOME="${config.xdg.cacheHome}"
|
||||||
|
|
||||||
npm_prefix="$(npm prefix -g 2>/dev/null)"
|
if [ ! -d "${npmDir}/lib/node_modules/@mariozechner/pi-coding-agent" ]; then
|
||||||
pkg_dir="$npm_prefix/lib/node_modules/@mariozechner/pi-coding-agent"
|
|
||||||
|
|
||||||
if [ ! -d "$pkg_dir" ]; then
|
|
||||||
npm install -g @mariozechner/pi-coding-agent 2>/dev/null || true
|
npm install -g @mariozechner/pi-coding-agent 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
@ -34,13 +39,13 @@ lib.mkIf hostConfig.isLinux {
|
||||||
pkgs.git
|
pkgs.git
|
||||||
]
|
]
|
||||||
}:$PATH"
|
}:$PATH"
|
||||||
|
export NPM_CONFIG_USERCONFIG="${config.xdg.configHome}/npm/npmrc"
|
||||||
|
export XDG_DATA_HOME="${config.xdg.dataHome}"
|
||||||
|
export XDG_CACHE_HOME="${config.xdg.cacheHome}"
|
||||||
|
|
||||||
npm_prefix="$(npm prefix -g 2>/dev/null)"
|
if [ -x "${piBin}" ]; then
|
||||||
pi_bin="$npm_prefix/bin/pi"
|
|
||||||
|
|
||||||
if [ -x "$pi_bin" ]; then
|
|
||||||
for pkg in "@e9n/pi-channels" "pi-schedule-prompt" "pi-subagents"; do
|
for pkg in "@e9n/pi-channels" "pi-schedule-prompt" "pi-subagents"; do
|
||||||
"$pi_bin" install "npm:$pkg" 2>/dev/null || true
|
"${piBin}" install "npm:$pkg" 2>/dev/null || true
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
|
|
@ -9,23 +9,21 @@ let
|
||||||
[ -f "${piAgentEnvFile}" ]
|
[ -f "${piAgentEnvFile}" ]
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
piBin = "/home/${username}/.local/share/npm/bin/pi";
|
||||||
|
|
||||||
# Wrapper that exec's pi inside tmux's foreground process so systemd
|
# Wrapper that exec's pi inside tmux's foreground process so systemd
|
||||||
# tracks the actual PID. When pi dies, tmux exits, systemd sees it
|
# tracks the actual PID. When pi dies, tmux exits, systemd sees it
|
||||||
# and triggers Restart=on-failure.
|
# and triggers Restart=on-failure.
|
||||||
piAgentStart = pkgs.writeShellScript "start-pi-agent" ''
|
piAgentStart = pkgs.writeShellScript "start-pi-agent" ''
|
||||||
export PATH="${pkgs.nodejs_22}/bin:$PATH"
|
if [ ! -x "${piBin}" ]; then
|
||||||
npm_prefix="$(npm prefix -g 2>/dev/null)"
|
echo "pi binary not found at ${piBin}" >&2
|
||||||
pi_bin="$npm_prefix/bin/pi"
|
|
||||||
|
|
||||||
if [ ! -x "$pi_bin" ]; then
|
|
||||||
echo "pi binary not found at $pi_bin" >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# tmux runs in the foreground (-D) so systemd tracks this process.
|
# tmux runs in the foreground (-D) so systemd tracks this process.
|
||||||
# The inner shell exec's pi so the tmux pane PID *is* the pi PID.
|
# The inner shell exec's pi so the tmux pane PID *is* the pi PID.
|
||||||
exec ${pkgs.tmux}/bin/tmux new-session -D -s pi-agent \
|
exec ${pkgs.tmux}/bin/tmux new-session -D -s pi-agent \
|
||||||
"exec $pi_bin --chat-bridge"
|
"exec ${piBin} --chat-bridge"
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue