Skip to content

fix(daemon): add Nix Home Manager PATH support to service environment#44433

Closed
claw-explorer wants to merge 1 commit intoopenclaw:mainfrom
claw-explorer:fix/nix-home-manager-path-support
Closed

fix(daemon): add Nix Home Manager PATH support to service environment#44433
claw-explorer wants to merge 1 commit intoopenclaw:mainfrom
claw-explorer:fix/nix-home-manager-path-support

Conversation

@claw-explorer
Copy link
Copy Markdown

Summary

  • Add Nix Home Manager PATH support to LaunchAgent and systemd service environments
  • Enables openclaw gateway install to capture Nix-installed binaries on both macOS and Linux
  • Includes comprehensive test coverage for single and multi-profile Nix setups

Root Cause

The resolveDarwinUserBinDirs() and resolveLinuxUserBinDirs() functions did not include Nix Home Manager paths (~/.nix-profile/bin, NIX_PROFILES env 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:

  • Includes ~/.nix-profile/bin by default (single-user Nix installations)
  • Parses NIX_PROFILES env var (space-separated list) for multi-profile setups
  • Works cross-platform (macOS, Linux, BSD - anywhere Nix Home Manager runs)

Called from both resolveDarwinUserBinDirs() and resolveLinuxUserBinDirs() to ensure consistent behavior.

Testing

  • Added tests for Linux Nix profile detection (single and multi-profile)
  • Added tests for macOS Nix profile detection (single and multi-profile)
  • Verified existing tests still pass
  • Follows the same pattern as existing version manager integrations (nvm, fnm, volta)

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

- 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
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Mar 12, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 12, 2026

Greptile Summary

This PR adds Nix Home Manager PATH support to both the macOS LaunchAgent and Linux systemd service environments by introducing an addNixProfileBinDirs() helper, ensuring that Nix-installed binaries are discoverable when OpenClaw runs as a background service.

  • New addNixProfileBinDirs(dirs, home, env) function unconditionally adds ~/.nix-profile/bin and parses the NIX_PROFILES env var (space-separated profile roots) for multi-profile Nix setups.
  • Called from both resolveDarwinUserBinDirs and resolveLinuxUserBinDirs, keeping the fix symmetric across platforms.
  • Existing deduplication logic in getMinimalServicePathParts correctly handles the case where NIX_PROFILES also contains ~/.nix-profile (the path would be pushed twice into dirs but deduplicated before final output).
  • Minor inconsistency: NIX_PROFILES path entries are appended with a raw template literal (${profile}/bin) rather than appendSubdir(profile, "bin"), unlike all other env-configured bin directories in this file. appendSubdir guards against double-/bin if NIX_PROFILES paths already end with /bin.
  • Tests are thorough, covering Linux and macOS for both single-profile and multi-profile NIX_PROFILES scenarios.

Confidence Score: 4/5

  • Safe to merge with one minor style fix recommended before merging.
  • The implementation is functionally correct. The addNixProfileBinDirs logic properly handles both single-user and multi-profile Nix setups, and any duplicate entries from overlapping NIX_PROFILES values are safely eliminated by the existing deduplication in getMinimalServicePathParts. Test coverage is comprehensive. The only issue is a minor inconsistency in using a raw template literal instead of appendSubdir for NIX_PROFILES path construction, which could theoretically produce a double-/bin path in edge cases — easy one-line fix.
  • src/daemon/service-env.ts — line 124, the NIX_PROFILES /bin append should use appendSubdir for consistency and edge-case safety.
Prompt To Fix All 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.

Last reviewed commit: 7fcb1e9

Comment thread src/daemon/service-env.ts
const profiles = nixProfiles.split(/\s+/);
for (const profile of profiles) {
if (profile) {
addNonEmptyDir(dirs, `${profile}/bin`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

@jerome-benoit
Copy link
Copy Markdown
Contributor

@claw-explorer: have you applied the fix in #44433 (comment)?

Arry8 pushed a commit to Arry8/openclaw-edge that referenced this pull request Apr 8, 2026
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
@BunsDev BunsDev added the close:duplicate Closed as duplicate label Apr 25, 2026
@BunsDev
Copy link
Copy Markdown
Member

BunsDev commented Apr 25, 2026

Closing this older implementation as superseded by #59935, which landed the same Nix Home Manager service PATH support with appendSubdir handling, NIX_PROFILES precedence coverage, and focused resolver tests.

@BunsDev BunsDev closed this Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

close:duplicate Closed as duplicate gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: openclaw gateway install does not capture Nix (Home Manager) PATH entries in LaunchAgent plist

3 participants