The NixOS wiki is outdated and is being shut down. If you wish to add or improve NixOS documentation, please grab a ticket from the Move the wiki! milestone.

Samba

From Nix Wiki
(Redirected from Samba on nix)
Jump to: navigation, search

motivation

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

excerpt of /etc/nixos/configuration.nix

  services.samba = {
    enable = true;
    shares = {
      data =
        { path = "/srv/data";
          "read only" = "yes";
          browseable = "yes";
          "guest ok" = "no";
          "valid users" = "myuser";
        };
    };
    extraConfig = ''
    guest account = nobody
    map to guest = bad user
    '';
  };

To setup a public share, try this magic:

  services.samba = {
    enable = true;
    shares = {
      Videos =
        { path = "/home/me/Videos";
          "read only" = "yes";
          browseable = "yes";
          "guest ok" = "yes";
        };
    };
    extraConfig = ''
    guest account = smbguest
    map to guest = bad user
    '';
  };
  # create the smbguest user, otherwise connections will fail
  users.users.smbguest = 
    { name = "smbguest";
      uid  = config.ids.uids.smbguest;
      description = "smb guest user";
    };
  };

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

  networking.firewall.enable = true;
  networking.firewall.allowPing = true;
  networking.firewall.allowedTCPPorts = [ 445 139 ];
  networking.firewall.allowedUDPPorts = [ 137 138 ];
Note: In order to affect your system by your nix-language-specific changes you have to evaluate it, run (as root):
   $ nixos-rebuild switch

samba should startup afterwards

stopping/restarting the services

 systemctl restart samba
 systemctl start samba
 systemctl stop samba
 journalctl -u samba -f
systemctl | grep -i samb
samba-nmbd.service                                                                                      loaded active running   Samba Service Daemon nmbd
samba-smbd.service                                                                                      loaded active running   Samba Service Daemon smbd
samba-winbindd.service                                                                                  loaded active running   Samba Service Daemon winbindd
samba.target                                                                                            loaded active active    Samba Server

links

Category:Services