Samba: Difference between revisions

From NixOS Wiki
imported>Fadenb
imported>Mic92
No edit summary
Line 1: Line 1:
== Motivation ==
== Motivation ==
This guide will help you on how to use samba on nixos.
This guide will help you on how to use samba on nixos.
== cifs mount ==
The following snippets shows how to mount a CIFS (Windows) share in NixOS.
Replace all <code><FIELDS></code> with concrete values:
<syntaxhighlight lang="nix">
{
  fileSystems."/mnt/share" = {
      device = "//<IP_OR_HOST>/path/to/share";
      fsType = "cifs";
      options = let
        # 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";
      in ["${automount_opts},credentials=/etc/nixos/smb-secrets"];
  };
}
</syntaxhighlight>
Also create /etc/nixos/smb-secrets with the following content (<code>domain=</code> can be optional)
<syntaxhighlight lang="nix">
username=<USERNAME>
domain=<DOMAIN>
password=<PASSWORD>
</syntaxhighlight>


== excerpt of /etc/nixos/configuration.nix ==
== excerpt of /etc/nixos/configuration.nix ==

Revision as of 17:28, 12 September 2017

Motivation

This guide will help you on how to use samba on nixos.

cifs mount

The following snippets shows how to mount a CIFS (Windows) share in NixOS. Replace all <FIELDS> with concrete values:

{
  fileSystems."/mnt/share" = {
      device = "//<IP_OR_HOST>/path/to/share";
      fsType = "cifs";
      options = let
        # 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";

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

Also create /etc/nixos/smb-secrets with the following content (domain= can be optional)

username=<USERNAME>
domain=<DOMAIN>
password=<PASSWORD>

excerpt of /etc/nixos/configuration.nix

services.samba.enable = true;
services.samba.securityType = "share";
services.samba.extraConfig = ''
  workgroup = WORKGROUP
  server string = smbnix
  netbios name = smbnix
  security = share 
  #use sendfile = yes
  #max protocol = smb2

  [rw-files]
    comment = Temporary rw files 
    path = /storage
    read only = no
    writable = yes
    public = yes
'';

If your firewall is enabled, or if you consider enabling it:

networking.firewall.enable = true;
networking.firewall.allowPing = true;
networking.firewall.allowedTCPPorts = [ 445 139 ];
networking.firewall.allowedUDPPorts = [ 137 138 ];

samba should startup afterwards

stopping/restarting the services

# systemctl stop samba
# systemctl start samba
# systemctl restart samba

links