Mic92 / nixos-shell

Spawns lightweight nixos vms in a shell
MIT License
684 stars 39 forks source link

How to configure uid/gid with `extraMounts` option? #71

Closed onny closed 8 months ago

onny commented 1 year ago

Hey, I'm looking to configure permissions of a 9p mount point. Usually they are owned by root inside the nixos-shell VM. How can I change the ownership?

What I can do currently is:

mount -o remount,uid=<UID>,gid=<GID> <mountpoint>

or alternaivley

bindfs -u 997 -g 997 /var/lib/nextcloud/calendar /var/lib/nextcloud/store-apps/calendar

Best regards Jonas

onny commented 1 year ago

Hm changing uid and gid doesn't quite seems to work with 9p. Would it be possible to switch to virtiofs?

My current workaround with bindfs:

  systemd.mounts = [
    {
      what = "/var/lib/nextcloud/calendar";
      where = "/var/lib/nextcloud/store-apps/calendar";
      type = "fuse.bindfs";
      options = "uid=997,gid=997";
      wantedBy = [ "multi-user.target" ];
      enable = true;
    }
  ];
Mic92 commented 1 year ago

Have you tried setting these mount options on the virtio-9p mounts?

  dfltuid   attempt to mount as a particular uid

  dfltgid   attempt to mount with a particular gid

Those are coming from here: https://www.kernel.org/doc/Documentation/filesystems/9p.txt

Mic92 commented 1 year ago

There is also X-mount.idmap= otherwise: https://github.com/brauner/mount-idmapped

onny commented 1 year ago

Hm didn't have any luck with these two approaches. Thank you for sharing anyway. Currently I'm trying to use virtiofs but uid and gid mapping as non-root user doesn't seem so simple yet

Mic92 commented 1 year ago

Would be interesting to have support for this in nixos-shell

Mic92 commented 8 months ago

Afaik This is not possible with 9p unfortunately.