[Nix-dev] systemd + sshfs

Bjørn Forsman bjorn.forsman at gmail.com
Mon Sep 19 15:04:49 CEST 2016


Hi Rickard,

On 18 September 2016 at 23:19, Rickard Nilsson
<rickard.nilsson at telia.com> wrote:
> Hi Bjørn,
>
> I remember struggling with this too. The following works for me:
>
> fileSystems."/target" =
>   fsType = "fuse";
>   device = "${pkgs.sshfsFuse}/bin/sshfs#user at host:/path";
>   options = [
>     "noauto" "comment=systemd.automount"
>     "ssh_command=${sshAsUser}"
>   ];
> };
>
> where
>
>   sshAsUser = user:
>     writeScript "ssh_as_${user}" ''
>       exec ${pkgs.sudo}/bin/sudo -i -u ${user} \
>         ${pkgs.openssh}/bin/ssh $@
>     '';
>
> The "sshAsUser" command makes systemd use my gpg-agent session correctly
> when auto-mounting. But I guess you could use it to set any ssh options
> you'd like.

Thanks, that worked!

I get a bad feeling that it has to be done this way though (if this is
the _only_ way). Shouldn't it be a way to tell systemd about 'sshfs'?

Btw, I'm still struggling to get proper "lazy" mounts that (1) detect
failure in reasonable time and (2) never silently unmount the
filesystem, even for a second. Lazy mount means I cannot use the sshfs
'reconnect' option, because that causes an ever lasting (re)connect
loop. Autofs looks like the solution (which is what the above config
uses), but GVFS really doesn't want to leave autofs filesystems alone.
It constantly tries to mount/activate them. And if the filesystem
cannot be mounted (network down) the systemd unit enters failed state
and users see will see the empty mountpoint directory without any
warning. Bad.

Here are my options so far:

          options = [
            "noauto" "_netdev" "allow_other" "x-systemd.automount" #"reconnect"
            "ServerAliveInterval=5" "ServerAliveCountMax=1"
            "ssh_command=${sshAsUser user}"
          ];

Best regards,
Bjørn Forsman


More information about the nix-dev mailing list