fix(daemon): add Nix Home Manager PATH support to service environment#44433
fix(daemon): add Nix Home Manager PATH support to service environment#44433claw-explorer wants to merge 1 commit intoopenclaw:mainfrom
Conversation
- Add addNixProfileBinDirs() helper to resolve Nix profile paths - Include ~/.nix-profile/bin by default (single-user installations) - Support NIX_PROFILES env var for multi-profile setups - Apply to both macOS and Linux platforms (Nix is cross-platform) - Add comprehensive test coverage for Nix path resolution Closes openclaw#44402
Greptile SummaryThis PR adds Nix Home Manager PATH support to both the macOS LaunchAgent and Linux systemd service environments by introducing an
Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/daemon/service-env.ts
Line: 124
Comment:
**Use `appendSubdir` for consistency and defensive path handling**
All other env-configured bin directories in this file use `appendSubdir` when appending `/bin` (e.g., `appendSubdir(env?.NPM_CONFIG_PREFIX, "bin")`, `appendSubdir(env?.BUN_INSTALL, "bin")`). `appendSubdir` uses `path.posix.join` and also guards against the case where the base path already ends with the subdir (e.g., if `NIX_PROFILES` is accidentally set to paths that already include `/bin`). Using a raw template literal here is inconsistent and could produce a double-`/bin` path (e.g., `/nix/var/nix/profiles/default/bin/bin`) in that edge case.
```suggestion
addNonEmptyDir(dirs, appendSubdir(profile, "bin"));
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 7fcb1e9 |
| const profiles = nixProfiles.split(/\s+/); | ||
| for (const profile of profiles) { | ||
| if (profile) { | ||
| addNonEmptyDir(dirs, `${profile}/bin`); |
There was a problem hiding this comment.
Use appendSubdir for consistency and defensive path handling
All other env-configured bin directories in this file use appendSubdir when appending /bin (e.g., appendSubdir(env?.NPM_CONFIG_PREFIX, "bin"), appendSubdir(env?.BUN_INSTALL, "bin")). appendSubdir uses path.posix.join and also guards against the case where the base path already ends with the subdir (e.g., if NIX_PROFILES is accidentally set to paths that already include /bin). Using a raw template literal here is inconsistent and could produce a double-/bin path (e.g., /nix/var/nix/profiles/default/bin/bin) in that edge case.
| addNonEmptyDir(dirs, `${profile}/bin`); | |
| addNonEmptyDir(dirs, appendSubdir(profile, "bin")); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/daemon/service-env.ts
Line: 124
Comment:
**Use `appendSubdir` for consistency and defensive path handling**
All other env-configured bin directories in this file use `appendSubdir` when appending `/bin` (e.g., `appendSubdir(env?.NPM_CONFIG_PREFIX, "bin")`, `appendSubdir(env?.BUN_INSTALL, "bin")`). `appendSubdir` uses `path.posix.join` and also guards against the case where the base path already ends with the subdir (e.g., if `NIX_PROFILES` is accidentally set to paths that already include `/bin`). Using a raw template literal here is inconsistent and could produce a double-`/bin` path (e.g., `/nix/var/nix/profiles/default/bin/bin`) in that edge case.
```suggestion
addNonEmptyDir(dirs, appendSubdir(profile, "bin"));
```
How can I resolve this? If you propose a fix, please make it concise.|
@claw-explorer: have you applied the fix in #44433 (comment)? |
Add addNixProfileBinDirs() helper that resolves both the default ~/.nix-profile/bin path and all profile paths from the NIX_PROFILES environment variable (space-separated, used by multi-profile Nix setups). Uses appendSubdir() for consistent and defensive path handling, avoiding raw template literals that could produce double /bin paths. Called from both resolveDarwinUserBinDirs() and resolveLinuxUserBinDirs() so the fix works on all Unix platforms. Fixes openclaw/openclaw#44402 Supersedes openclaw/openclaw#44433
|
Closing this older implementation as superseded by #59935, which landed the same Nix Home Manager service PATH support with |
Summary
openclaw gateway installto capture Nix-installed binaries on both macOS and LinuxRoot Cause
The
resolveDarwinUserBinDirs()andresolveLinuxUserBinDirs()functions did not include Nix Home Manager paths (~/.nix-profile/bin,NIX_PROFILESenv var). Users running OpenClaw under Nix Home Manager would find that commands available in their shell were missing when the gateway ran as a LaunchAgent/systemd service.Fix
Added
addNixProfileBinDirs()helper that:~/.nix-profile/binby default (single-user Nix installations)NIX_PROFILESenv var (space-separated list) for multi-profile setupsCalled from both
resolveDarwinUserBinDirs()andresolveLinuxUserBinDirs()to ensure consistent behavior.Testing
Implementation Notes
Per feedback in #44402, Nix Home Manager is not macOS-specific - it runs on any Unix system. The fix applies to both platforms via a shared helper function.
Closes #44402