rclone: extend mount unit PATH for non-NixOS fusermount

The mount user-service set Environment=PATH=/run/wrappers/bin, which is
a NixOS-only directory. On standalone home-manager hosts running other
Linux distros the directory does not exist, and because Environment=PATH=
replaces systemd's inherited PATH, the resulting unit has no usable PATH
at all.

libfuse falls back to a hardcoded /usr/bin/fusermount3 lookup so the
helper still executes, but the eventual mount(2) syscall returns EPERM,
likely because libfuse's internal system()/popen() invocations into
mount.fuse3 fail without /bin/sh and friends on PATH. Empirically, the
EPERM goes away the moment PATH is widened to include standard Linux
locations.

Enumerate /run/wrappers/bin and /run/current-system/sw/bin alongside the
usual /usr/{local/,}{s,}bin and /{s,}bin entries. Path search order is
preserved, so the NixOS wrappers still win where they exist, and
fusermount/fusermount3 is found at /usr/bin on Ubuntu/Debian/Fedora and
similar distros.
This commit is contained in:
jiezhuzzz
2026-05-07 22:04:15 -05:00
committed by Austin Horstman
parent fd272ce76e
commit 93b932fdbb
2 changed files with 7 additions and 2 deletions

View File

@@ -92,7 +92,12 @@ let
Type =
if !isMount && !(builtins.elem sidecar.protocol serveProtocolNotifies) then "simple" else "notify";
Environment =
(lib.optional isMount "PATH=/run/wrappers/bin")
# PATH is set explicitly so fusermount/fusermount3 is found on both
# NixOS (/run/wrappers/bin) and standalone home-manager hosts running
# other Linux distros (where the FUSE setuid helper lives in standard
# /usr or /sbin paths). Setting Environment=PATH= replaces systemd's
# inherited PATH, so we must enumerate the non-NixOS locations too.
(lib.optional isMount "PATH=/run/wrappers/bin:/run/current-system/sw/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
++ lib.optional (sidecar.logLevel != null) "RCLONE_LOG_LEVEL=${sidecar.logLevel}";
SuccessExitStatus = "143";

View File

@@ -34,7 +34,7 @@ _: {
assertFileContains "$service" "rclone mount '--cache-dir=%C/rclone' '--dir-cache-time=5000h' '--poll-interval=10s' '--umask=002' '--vfs-cache-mode=full' sftp-remote:documents/work /home/alice/mounts/work-docs"
assertFileContains "$service" "mkdir -p /home/alice/mounts/work-docs"
assertFileContains "$service" "RCLONE_LOG_LEVEL=INFO"
assertFileContains "$service" "PATH=/run/wrappers/bin"
assertFileContains "$service" "PATH=/run/wrappers/bin:/run/current-system/sw/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
assertFileContains "$service" "Rclone FUSE daemon for sftp-remote:documents/work"
assertFileContains "$service" "Type=notify"