Samba: Difference between revisions

User Authentication: add robust automated authentication example that provides full context and aims to give a basic, typical password-protected folder share
Renamed "services.samba.securityType" to "services.samba.settings.global.security" in the User Authentication section
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
This guide will help you on how to use samba on nixos.
This guide will help you on how to use samba on nixos.
== Usershares ==
You can allow some users to share via samba a given directory simply via a right click in their file browser (tested with Dolphin). For that, first add this configuration (make sure to add your user in the samba group):
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{ pkgs, config, ... }: {
  services.samba = {
    # The full package is needed to register mDNS records (for discoverability), see discussion in
    # https://gist.github.com/vy-let/a030c1079f09ecae4135aebf1e121ea6
    package = pkgs.samba4Full;
    usershares.enable = true;
    enable = true;
    openFirewall = true;
  };
  # To be discoverable with windows
  services.samba-wsdd = {
    enable = true;
    openFirewall = true;
  };
  # Make sure your user is in the samba group
  users.users.YOURUSER = {
    isNormalUser = true;
    extraGroups = [ "samba" ];
  };
}
</nowiki>}}
Then, logout and login (to make sure your group change has been taken into account), open Dolphin, right click on a folder you'd like to share, go to Properties, Tab "Share", and configure it the way you want.


== Server setup ==
== Server setup ==
Line 93: Line 124:
   services.samba = {
   services.samba = {
     enable = true;
     enable = true;
    securityType = "user";
     openFirewall = true;
     openFirewall = true;
     settings.my_share_directory = {
     settings = {
      # ...
      global = {
      "valid users" = "my_user";
        # ...
        "security" = "user";
      };
      my_share_directory = {
        # ...
        "valid users" = "my_user";
      };
     };
     };
   };
   };
Line 316: Line 352:
=== CIFS mount configuration ===
=== CIFS mount configuration ===


The following snippets shows how to mount a CIFS (Windows) share in NixOS.
The following snippets shows how to mount a CIFS (Windows) share in NixOS.  
 
Note the inclusion of the <code>"nofail"</code> option; NixOS will treat CIFS shares like any other mounted drive, and this will allow the system to boot correctly if the mounted NAS is off or if the network is slow to initialize.
 
Replace all <code><FIELDS></code> with concrete values:
Replace all <code><FIELDS></code> with concrete values:


Line 330: Line 369:
       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" "nofail"];
   };
   };
}
}
Line 496: Line 535:
* [https://search.nixos.org/options?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=services.samba Samba Options in NixOS on unstable]
* [https://search.nixos.org/options?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=services.samba Samba Options in NixOS on unstable]
* [https://wiki.archlinux.org/title/Samba Samba in the Arch Linux Wiki]
* [https://wiki.archlinux.org/title/Samba Samba in the Arch Linux Wiki]
* [https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html smb.conf man page]


[[Category:Server]]
[[Category:Server]]
[[Category:Applications]]
[[Category:Applications]]