opencode: preserve service PATH

This commit is contained in:
repparw
2026-09-04 15:22:13 -03:00
committed by Austin Horstman
parent 0b8d588fc2
commit 9c997ea660
6 changed files with 58 additions and 43 deletions

View File

@@ -2,11 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/home/hm-user/.nix-profile/bin</string>
</dict>
<key>KeepAlive</key>
<dict>
<key>Crashed</key>

View File

@@ -2,9 +2,8 @@
WantedBy=default.target
[Service]
Environment=PATH=/home/hm-user/.nix-profile/bin
EnvironmentFile=/run/secrets/opencode
ExecStart=@opencode@/bin/opencode serve
ExecStart=/nix/store/00000000000000000000000000000000-opencode-web-launcher/bin/opencode-web-launcher
Restart=always
RestartSec=5

View File

@@ -1,10 +1,29 @@
{
config,
lib,
pkgs,
...
}:
let
profileHelper = pkgs.writeShellScriptBin "profile-helper" "";
extraHelper = pkgs.writeShellScriptBin "extra-helper" "";
inheritedHelper = pkgs.writeShellScriptBin "inherited-helper" "";
testOpencode = pkgs.writeShellScriptBin "opencode" ''
set -e
command -v profile-helper >/dev/null
command -v extra-helper >/dev/null
command -v inherited-helper >/dev/null
'';
serviceLauncher = config.systemd.user.services.opencode-web.Service.ExecStart;
testLauncher = "$TMPDIR/opencode-web-launcher";
in
{
home.homeDirectory = lib.mkForce "/@TMPDIR@/hm-user";
programs.opencode = {
enable = true;
package = testOpencode;
extraPackages = [ extraHelper ];
web = {
enable = true;
@@ -26,18 +45,27 @@
};
nmt.script =
if pkgs.stdenv.hostPlatform.isDarwin then
''
serviceFile=LaunchAgents/org.nix-community.home.opencode-web.plist
assertFileExists "$serviceFile"
serviceFileNormalized="$(normalizeStorePaths "$serviceFile")"
assertFileContent "$serviceFileNormalized" ${./web-service.plist}
''
else
''
serviceFile=home-files/.config/systemd/user/opencode-web.service
assertFileExists "$serviceFile"
serviceFileNormalized="$(normalizeStorePaths "$serviceFile")"
assertFileContent "$serviceFileNormalized" ${./web-service.service}
'';
(
if pkgs.stdenv.hostPlatform.isDarwin then
''
serviceFile=LaunchAgents/org.nix-community.home.opencode-web.plist
assertFileExists "$serviceFile"
serviceFileNormalized="$(normalizeStorePaths "$serviceFile")"
assertFileContent "$serviceFileNormalized" ${./web-service.plist}
''
else
''
serviceFile=home-files/.config/systemd/user/opencode-web.service
assertFileExists "$serviceFile"
serviceFileNormalized="$(normalizeStorePaths "$serviceFile")"
assertFileContent "$serviceFileNormalized" ${./web-service.service}
''
)
+ ''
mkdir -p "$TMPDIR/hm-user/.nix-profile/bin"
ln -s ${lib.getExe profileHelper} "$TMPDIR/hm-user/.nix-profile/bin/profile-helper"
substitute ${lib.escapeShellArg serviceLauncher} ${testLauncher} --subst-var TMPDIR
chmod +x ${testLauncher}
PATH=${lib.makeBinPath [ inheritedHelper ]} ${testLauncher}
'';
}

View File

@@ -2,11 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/home/hm-user/.nix-profile/bin</string>
</dict>
<key>KeepAlive</key>
<dict>
<key>Crashed</key>
@@ -22,7 +17,7 @@
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>/bin/wait4path /nix/store &amp;&amp; exec @opencode@/bin/opencode serve --hostname 0.0.0.0 --port 4096 --mdns --cors https://example.com --cors http://localhost:3000 --print-logs --log-level DEBUG</string>
<string>/bin/wait4path /nix/store &amp;&amp; exec /nix/store/00000000000000000000000000000000-opencode-web-launcher/bin/opencode-web-launcher</string>
</array>
<key>RunAtLoad</key>
<true/>

View File

@@ -2,8 +2,7 @@
WantedBy=default.target
[Service]
Environment=PATH=/home/hm-user/.nix-profile/bin
ExecStart=@opencode@/bin/opencode serve --hostname 0.0.0.0 --port 4096 --mdns --cors https://example.com --cors http://localhost:3000 --print-logs --log-level DEBUG
ExecStart=/nix/store/00000000000000000000000000000000-opencode-web-launcher/bin/opencode-web-launcher
Restart=always
RestartSec=5