2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-03-06 12:26:50 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2007-05-28 14:09:04 +00:00
|
|
|
|
|
|
|
let
|
2009-04-21 16:30:32 +00:00
|
|
|
cfg = config.services.samba;
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2024-04-08 20:34:05 +00:00
|
|
|
settingsFormat = pkgs.formats.ini { };
|
|
|
|
configFile = settingsFormat.generate "smb.conf" cfg.settings;
|
2014-12-07 20:42:22 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
in
|
2009-04-21 16:30:32 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
{
|
2024-04-08 20:38:07 +00:00
|
|
|
meta = {
|
|
|
|
doc = ./samba.md;
|
|
|
|
maintainers = [ lib.maintainers.anthonyroussel ];
|
|
|
|
};
|
|
|
|
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "samba" "defaultShare" ] "")
|
2020-08-30 11:28:11 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "samba" "syncPasswordsByPam" ] "This option has been removed by upstream, see https://bugzilla.samba.org/show_bug.cgi?id=10669#c10")
|
2024-04-08 20:34:05 +00:00
|
|
|
|
|
|
|
(lib.mkRemovedOptionModule [ "services" "samba" "configText" ] ''
|
|
|
|
Use services.samba.settings instead.
|
|
|
|
|
|
|
|
This is part of the general move to use structured settings instead of raw
|
|
|
|
text for config as introduced by RFC0042:
|
|
|
|
https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md
|
|
|
|
'')
|
|
|
|
(lib.mkRemovedOptionModule [ "services" "samba" "extraConfig" ] "Use services.samba.settings instead.")
|
|
|
|
(lib.mkRenamedOptionModule [ "services" "samba" "invalidUsers" ] [ "services" "samba" "settings" "global" "invalid users" ])
|
|
|
|
(lib.mkRenamedOptionModule [ "services" "samba" "securityType" ] [ "services" "samba" "settings" "global" "security type" ])
|
|
|
|
(lib.mkRenamedOptionModule [ "services" "samba" "shares" ] [ "services" "samba" "settings" ])
|
|
|
|
|
2024-04-08 21:14:53 +00:00
|
|
|
(lib.mkRenamedOptionModule [ "services" "samba" "enableWinbindd" ] [ "services" "samba" "winbindd" "enable" ])
|
|
|
|
(lib.mkRenamedOptionModule [ "services" "samba" "enableNmbd" ] [ "services" "samba" "nmbd" "enable" ])
|
2019-12-10 01:51:19 +00:00
|
|
|
];
|
2009-04-21 16:30:32 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
###### interface
|
2009-04-21 16:30:32 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
options = {
|
|
|
|
services.samba = {
|
2024-04-12 11:55:21 +00:00
|
|
|
enable = lib.mkEnableOption "Samba, the SMB/CIFS protocol";
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2024-04-12 11:55:21 +00:00
|
|
|
package = lib.mkPackageOption pkgs "samba" {
|
|
|
|
example = "samba4Full";
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2009-04-21 16:30:32 +00:00
|
|
|
|
2024-04-12 11:55:21 +00:00
|
|
|
openFirewall = lib.mkEnableOption "opening the default ports in the firewall for Samba";
|
2021-10-16 01:29:55 +00:00
|
|
|
|
2024-04-12 12:07:14 +00:00
|
|
|
smbd = {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Whether to enable Samba's smbd daemon.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = "Extra arguments to pass to the smbd service.";
|
|
|
|
};
|
2024-04-08 21:16:59 +00:00
|
|
|
};
|
|
|
|
|
2024-04-12 12:07:14 +00:00
|
|
|
nmbd = {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Samba's nmbd, which replies to NetBIOS over IP name
|
|
|
|
service requests. It also participates in the browsing protocols
|
|
|
|
which make up the Windows "Network Neighborhood" view.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = "Extra arguments to pass to the nmbd service.";
|
|
|
|
};
|
2017-02-17 17:04:45 +00:00
|
|
|
};
|
|
|
|
|
2024-04-12 12:07:14 +00:00
|
|
|
winbindd = {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Samba's winbindd, which provides a number of services
|
|
|
|
to the Name Service Switch capability found in most modern C libraries,
|
|
|
|
to arbitrary applications via PAM and ntlm_auth and to Samba itself.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = "Extra arguments to pass to the winbindd service.";
|
|
|
|
};
|
2017-02-17 17:04:45 +00:00
|
|
|
};
|
|
|
|
|
2024-04-12 11:55:21 +00:00
|
|
|
nsswins = lib.mkEnableOption ''
|
|
|
|
WINS NSS (Name Service Switch) plug-in.
|
2015-01-03 05:23:01 +00:00
|
|
|
|
2024-04-12 11:55:21 +00:00
|
|
|
Enabling it allows applications to resolve WINS/NetBIOS names (a.k.a.
|
|
|
|
Windows machine names) by transparently querying the winbindd daemon
|
|
|
|
'';
|
2013-08-25 20:12:14 +00:00
|
|
|
|
2024-04-08 20:34:05 +00:00
|
|
|
settings = lib.mkOption {
|
|
|
|
type = lib.types.submodule { freeformType = settingsFormat.type; };
|
2014-12-07 20:42:22 +00:00
|
|
|
default = {};
|
2024-04-08 20:34:05 +00:00
|
|
|
example = {
|
|
|
|
"global" = {
|
|
|
|
"security" = "user";
|
|
|
|
"passwd program" = "/run/wrappers/bin/passwd %u";
|
|
|
|
"invalid users" = "root";
|
|
|
|
};
|
|
|
|
"public" = {
|
|
|
|
"path" = "/srv/public";
|
|
|
|
"read only" = "yes";
|
|
|
|
"browseable" = "yes";
|
|
|
|
"guest ok" = "yes";
|
|
|
|
"comment" = "Public samba share.";
|
|
|
|
};
|
|
|
|
};
|
2015-02-04 19:31:50 +00:00
|
|
|
description = ''
|
2024-04-08 20:34:05 +00:00
|
|
|
Configuration file for the Samba suite in ini format.
|
|
|
|
This file is located in /etc/samba/smb.conf
|
|
|
|
|
|
|
|
Refer to <https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html>
|
|
|
|
for all available options.
|
2020-04-02 05:39:04 +00:00
|
|
|
'';
|
2014-12-07 20:42:22 +00:00
|
|
|
};
|
2009-04-21 16:30:32 +00:00
|
|
|
};
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
###### implementation
|
2009-03-06 12:26:50 +00:00
|
|
|
|
2012-11-30 14:07:39 +00:00
|
|
|
config = mkMerge
|
2017-02-17 17:04:45 +00:00
|
|
|
[ { assertions =
|
2024-04-08 21:14:53 +00:00
|
|
|
[ { assertion = cfg.nsswins -> cfg.winbindd.enable;
|
|
|
|
message = "If services.samba.nsswins is enabled, then services.samba.winbindd.enable must also be enabled";
|
2017-02-17 17:04:45 +00:00
|
|
|
}
|
|
|
|
];
|
2012-11-30 14:07:39 +00:00
|
|
|
}
|
2007-05-28 14:09:04 +00:00
|
|
|
|
2024-04-12 12:07:14 +00:00
|
|
|
(lib.mkIf cfg.enable {
|
2024-06-07 06:43:54 +00:00
|
|
|
environment.etc."samba/smb.conf".source = configFile;
|
2013-10-15 12:47:51 +00:00
|
|
|
|
2024-04-12 12:07:14 +00:00
|
|
|
system.nssModules = optional cfg.nsswins cfg.package;
|
2020-05-05 22:20:30 +00:00
|
|
|
system.nssDatabases.hosts = optional cfg.nsswins "wins";
|
2013-08-25 20:12:14 +00:00
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
systemd = {
|
2024-04-12 12:07:14 +00:00
|
|
|
slices.system-samba = {
|
|
|
|
description = "Samba slice";
|
|
|
|
};
|
2012-12-26 23:54:37 +00:00
|
|
|
targets.samba = {
|
2013-11-09 19:06:01 +00:00
|
|
|
description = "Samba Server";
|
2019-11-08 22:25:55 +00:00
|
|
|
after = [ "network.target" ];
|
2021-02-25 19:09:32 +00:00
|
|
|
wants = [ "network-online.target" ];
|
2012-12-26 23:54:37 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2012-11-30 14:07:39 +00:00
|
|
|
};
|
2019-11-08 22:25:55 +00:00
|
|
|
tmpfiles.rules = [
|
|
|
|
"d /var/lock/samba - - - - -"
|
|
|
|
"d /var/log/samba - - - - -"
|
|
|
|
"d /var/cache/samba - - - - -"
|
|
|
|
"d /var/lib/samba/private - - - - -"
|
|
|
|
];
|
2012-12-26 23:54:37 +00:00
|
|
|
};
|
2007-05-28 14:09:04 +00:00
|
|
|
|
2017-08-11 20:13:33 +00:00
|
|
|
security.pam.services.samba = {};
|
2021-10-16 01:29:55 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2024-07-17 22:02:05 +00:00
|
|
|
# Like other mount* related commands that need the setuid bit, this is
|
|
|
|
# required too.
|
|
|
|
security.wrappers."mount.cifs" = {
|
|
|
|
program = "mount.cifs";
|
|
|
|
source = "${lib.getBin pkgs.cifs-utils}/bin/mount.cifs";
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
setuid = true;
|
|
|
|
};
|
2021-10-16 01:29:55 +00:00
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 139 445 ];
|
|
|
|
networking.firewall.allowedUDPPorts = mkIf cfg.openFirewall [ 137 138 ];
|
2012-11-30 14:07:39 +00:00
|
|
|
})
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2024-09-07 08:16:03 +00:00
|
|
|
(lib.mkIf (cfg.enable && cfg.nmbd.enable) {
|
2024-04-12 12:07:14 +00:00
|
|
|
systemd.services.samba-nmbd = {
|
|
|
|
description = "Samba NMB Daemon";
|
|
|
|
documentation = [ "man:nmbd(8)" "man:samba(7)" "man:smb.conf(5)" ];
|
|
|
|
|
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"network-online.target"
|
|
|
|
];
|
|
|
|
|
|
|
|
partOf = [ "samba.target" ];
|
|
|
|
wantedBy = [ "samba.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
|
|
|
|
environment.LD_LIBRARY_PATH = config.system.nssModules.path;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
ExecStart = "${cfg.package}/sbin/nmbd --foreground --no-process-group ${lib.escapeShellArgs cfg.nmbd.extraArgs}";
|
|
|
|
LimitCORE = "infinity";
|
|
|
|
PIDFile = "/run/samba/nmbd.pid";
|
|
|
|
Slice = "system-samba.slice";
|
|
|
|
Type = "notify";
|
|
|
|
};
|
|
|
|
|
|
|
|
unitConfig.RequiresMountsFor = "/var/lib/samba";
|
|
|
|
|
|
|
|
restartTriggers = [ configFile ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2024-09-07 08:16:03 +00:00
|
|
|
(lib.mkIf (cfg.enable && cfg.smbd.enable) {
|
2024-04-12 12:07:14 +00:00
|
|
|
systemd.services.samba-smbd = {
|
|
|
|
description = "Samba SMB Daemon";
|
|
|
|
documentation = [ "man:smbd(8)" "man:samba(7)" "man:smb.conf(5)" ];
|
|
|
|
|
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"network-online.target"
|
|
|
|
] ++ lib.optionals (cfg.nmbd.enable) [
|
|
|
|
"samba-nmbd.service"
|
|
|
|
] ++ lib.optionals (cfg.winbindd.enable) [
|
|
|
|
"samba-winbindd.service"
|
|
|
|
];
|
|
|
|
|
|
|
|
partOf = [ "samba.target" ];
|
|
|
|
wantedBy = [ "samba.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
|
|
|
|
environment.LD_LIBRARY_PATH = config.system.nssModules.path;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
ExecStart = "${cfg.package}/sbin/smbd --foreground --no-process-group ${lib.escapeShellArgs cfg.smbd.extraArgs}";
|
|
|
|
LimitCORE = "infinity";
|
|
|
|
LimitNOFILE = 16384;
|
|
|
|
PIDFile = "/run/samba/smbd.pid";
|
|
|
|
Slice = "system-samba.slice";
|
|
|
|
Type = "notify";
|
|
|
|
};
|
|
|
|
|
|
|
|
unitConfig.RequiresMountsFor = "/var/lib/samba";
|
|
|
|
|
|
|
|
restartTriggers = [ configFile ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2024-09-07 08:16:03 +00:00
|
|
|
(lib.mkIf (cfg.enable && cfg.winbindd.enable) {
|
2024-04-12 12:07:14 +00:00
|
|
|
systemd.services.samba-winbindd = {
|
|
|
|
description = "Samba Winbind Daemon";
|
|
|
|
documentation = [ "man:winbindd(8)" "man:samba(7)" "man:smb.conf(5)" ];
|
|
|
|
|
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
] ++ lib.optionals (cfg.nmbd.enable) [
|
|
|
|
"samba-nmbd.service"
|
|
|
|
];
|
|
|
|
|
|
|
|
partOf = [ "samba.target" ];
|
|
|
|
wantedBy = [ "samba.target" ];
|
|
|
|
|
|
|
|
environment.LD_LIBRARY_PATH = config.system.nssModules.path;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
ExecStart = "${cfg.package}/sbin/winbindd --foreground --no-process-group ${lib.escapeShellArgs cfg.winbindd.extraArgs}";
|
|
|
|
LimitCORE = "infinity";
|
|
|
|
PIDFile = "/run/samba/winbindd.pid";
|
|
|
|
Slice = "system-samba.slice";
|
|
|
|
Type = "notify";
|
|
|
|
};
|
|
|
|
|
|
|
|
unitConfig.RequiresMountsFor = "/var/lib/samba";
|
|
|
|
|
|
|
|
restartTriggers = [ configFile ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
2007-05-28 14:09:04 +00:00
|
|
|
}
|