Samba: Difference between revisions

imported>Solomon
m "windows 10" -> Windows in samba-wsdd comment
imported>Onsamyj
Clarification for mount as user
Line 12: Line 12:
   environment.systemPackages = [ pkgs.cifs-utils ];
   environment.systemPackages = [ pkgs.cifs-utils ];
   fileSystems."/mnt/share" = {
   fileSystems."/mnt/share" = {
      device = "//<IP_OR_HOST>/path/to/share";
    device = "//<IP_OR_HOST>/path/to/share";
      fsType = "cifs";
    fsType = "cifs";
      options = let
    options = let
        # this line prevents hanging on network split
      # this line prevents hanging on network split
        automount_opts = "x-systemd.automount,noauto,x-systemd.idle-timeout=60,x-systemd.device-timeout=5s,x-systemd.mount-timeout=5s";
      automount_opts = "x-systemd.automount,noauto,x-systemd.idle-timeout=60,x-systemd.device-timeout=5s,x-systemd.mount-timeout=5s";


      in ["${automount_opts},credentials=/etc/nixos/smb-secrets"];
    in ["${automount_opts},credentials=/etc/nixos/smb-secrets"];
   };
   };
}
}
Line 32: Line 32:


=== mount as user ===
=== mount as user ===
By default, CIFS shares are mounted as root. If mounting as user is desirable, `uid` and `gid` arguments can be provided as part of the filesystem options:
By default, CIFS shares are mounted as root. If mounting as user is desirable, `uid`, `gid` and usergroup arguments can be provided as part of the filesystem options:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{
{
   fileSystems."/mnt/share" = {
   fileSystems."/mnt/share" = {
     # ... rest of the filesystem config omitted
     # ... rest of the filesystem config omitted
     options = ["credentials=/etc/nixos/smb-secrets,uid=1000,gid=100"];
     options = let
      automount_opts = "x-systemd.automount,noauto,x-systemd.idle-timeout=60,x-systemd.device-timeout=5s,x-systemd.mount-timeout=5s,user,users";
 
      in ["${automount_opts},credentials=/etc/nixos/smb-secrets,uid=1000,gid=100"];
     # or if you have specified `uid` and `gid` explicitly through NixOS configuration,
     # or if you have specified `uid` and `gid` explicitly through NixOS configuration,
     # you can refer to them rather than hard-coding the values:
     # you can refer to them rather than hard-coding the values:
     # options = ["credentials=/etc/nixos/smb-secrets,uid=${config.users.users.<username>.uid},gid=${config.users.groups.<group>.gid}"];
     # in ["${automount_opts},credentials=/etc/nixos/smb-secrets,${config.users.users.<username>.uid},gid=${config.users.groups.<group>.gid}"];
   };
   };
}
}