2009-10-12 17:36:19 +01:00
|
|
|
{ config, pkgs, ... }:
|
2009-03-06 12:26:50 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
with pkgs.lib;
|
2007-05-28 15:09:04 +01:00
|
|
|
|
|
|
|
let
|
2009-04-21 17:30:32 +01:00
|
|
|
|
|
|
|
cfg = config.services.samba;
|
2007-05-28 16:39:25 +01:00
|
|
|
|
2007-06-08 16:41:12 +01:00
|
|
|
user = "smbguest";
|
|
|
|
group = "smbguest";
|
2009-03-29 22:43:40 +01:00
|
|
|
|
2009-04-21 17:30:32 +01:00
|
|
|
logDir = "/var/log/samba";
|
|
|
|
privateDir = "/var/samba/private";
|
|
|
|
|
2009-03-06 12:26:50 +00:00
|
|
|
inherit (pkgs) samba;
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
setupScript =
|
|
|
|
''
|
|
|
|
mkdir -p /var/lock
|
|
|
|
|
|
|
|
if ! test -d /home/smbd ; then
|
|
|
|
mkdir -p /home/smbd
|
|
|
|
chown ${user} /home/smbd
|
|
|
|
chmod a+rwx /home/smbd
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! test -d /var/samba ; then
|
|
|
|
mkdir -p /var/samba/locks /var/samba/cores/nmbd /var/samba/cores/smbd /var/samba/cores/winbindd
|
|
|
|
fi
|
|
|
|
|
|
|
|
passwdFile="$(sed -n 's/^.*smb[ ]\+passwd[ ]\+file[ ]\+=[ ]\+\(.*\)/\1/p' /nix/store/nnmrqalldfv2vkwy6qpg340rv7w34lmp-smb.conf)"
|
|
|
|
if [ -n "$passwdFile" ]; then
|
|
|
|
echo 'INFO: creating directory containing passwd file'
|
|
|
|
mkdir -p "$(dirname "$passwdFile")"
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p ${logDir}
|
|
|
|
mkdir -p ${privateDir}
|
|
|
|
|
|
|
|
# The following line is to trigger a restart of the daemons when
|
|
|
|
# the configuration changes:
|
|
|
|
# ${configFile}
|
|
|
|
'';
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "smb.conf"
|
|
|
|
''
|
|
|
|
[ global ]
|
|
|
|
log file = ${logDir}/log.%m
|
|
|
|
private dir = ${privateDir}
|
|
|
|
${optionalString cfg.syncPasswordsByPam "pam password change = true"}
|
2007-05-28 15:09:04 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
daemonJob = appName: args:
|
|
|
|
{ name = "samba-${appName}";
|
|
|
|
description = "Samba Service daemon ${appName}";
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
startOn = "samba/started";
|
|
|
|
stopOn = "samba-control/stop";
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
exec = "${samba}/sbin/${appName} ${args}";
|
|
|
|
};
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
in
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
{
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
###### interface
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
options = {
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
# !!! clean up the descriptions.
|
|
|
|
|
|
|
|
services.samba = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to enable the samba server. (to communicate with, and provide windows shares)
|
|
|
|
use start / stop samba-control to start/stop all daemons.
|
|
|
|
smbd and nmbd are not shutdown correctly yet. so just pkill them and restart those jobs.
|
|
|
|
";
|
|
|
|
};
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
syncPasswordsByPam = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
enabling this will add a line directly after pam_unix.so.
|
|
|
|
Whenever a password is changed the samba password will be updated as well.
|
|
|
|
However you still yave to add the samba password once using smbpasswd -a user
|
|
|
|
If you don't want to maintain an extra pwd database you still can send plain text
|
|
|
|
passwords which is not secure.
|
|
|
|
";
|
|
|
|
};
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
# !!! Bad default.
|
|
|
|
default = ''
|
|
|
|
# [global] continuing global section here, section is started by nix to set pids etc
|
|
|
|
|
|
|
|
smb passwd file = /etc/samba/passwd
|
|
|
|
|
|
|
|
# is this useful ?
|
|
|
|
domain master = auto
|
|
|
|
|
|
|
|
encrypt passwords = Yes
|
|
|
|
client plaintext auth = No
|
|
|
|
|
|
|
|
# yes: if you use this you probably also want to enable syncPasswordsByPam
|
|
|
|
# no: You can still use the pam password database. However
|
|
|
|
# passwords will be sent plain text on network (discouraged)
|
|
|
|
|
|
|
|
workgroup = Users
|
|
|
|
server string = %h
|
|
|
|
comment = Samba
|
|
|
|
log file = /var/log/samba/log.%m
|
|
|
|
log level = 10
|
|
|
|
max log size = 50000
|
|
|
|
security = user
|
|
|
|
|
|
|
|
client lanman auth = Yes
|
|
|
|
dns proxy = no
|
|
|
|
invalid users = root
|
|
|
|
passdb backend = tdbsam
|
|
|
|
passwd program = /usr/bin/passwd %u
|
|
|
|
'';
|
|
|
|
|
|
|
|
description = "
|
|
|
|
additional global section and extra section lines go in here.
|
|
|
|
";
|
|
|
|
};
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
configFile = mkOption {
|
|
|
|
description = "
|
|
|
|
internal use to pass filepath to samba pam module
|
|
|
|
";
|
|
|
|
};
|
2009-04-21 17:30:32 +01:00
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
|
|
|
|
2007-05-28 15:09:04 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
###### implementation
|
2009-03-06 12:26:50 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
config = mkIf config.services.samba.enable {
|
2007-05-28 15:09:04 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
users.extraUsers = singleton
|
2009-03-06 12:26:50 +00:00
|
|
|
{ name = user;
|
|
|
|
description = "Samba service user";
|
|
|
|
group = group;
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups = singleton
|
2009-03-06 12:26:50 +00:00
|
|
|
{ name = group;
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2009-03-06 12:26:50 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
# always provide a smb.conf to shut up programs like smbclient and smbspool.
|
|
|
|
environment.etc = mkAlways (singleton
|
|
|
|
{ source =
|
|
|
|
if cfg.enable then configFile
|
|
|
|
else pkgs.writeText "smb-dummy.conf" "# Samba is disabled.";
|
|
|
|
target = "samba/smb.conf";
|
|
|
|
});
|
|
|
|
|
|
|
|
# Dummy job to start the real Samba daemons (nmbd, smbd, winbindd).
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.sambaControl =
|
2009-10-12 17:36:19 +01:00
|
|
|
{ name = "samba";
|
|
|
|
description = "Samba server";
|
2009-04-21 17:30:32 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
startOn = "network-interfaces/started";
|
|
|
|
stopOn = "network-interfaces/stop";
|
2007-05-28 15:09:04 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
preStart = setupScript;
|
|
|
|
};
|
2007-05-28 15:09:04 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
# nmbd says "standard input is not a socket, assuming -D option",
|
|
|
|
# but using -i makes it stay in foreground (?)
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.nmbd = daemonJob "nmbd" " -i -F";
|
2007-05-28 15:09:04 +01:00
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.smbd = daemonJob "smbd" " -i -F";
|
2007-05-28 15:09:04 +01:00
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.winbindd = daemonJob "winbindd" " -F";
|
2007-05-28 15:09:04 +01:00
|
|
|
|
2009-03-06 12:26:50 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2007-05-28 15:09:04 +01:00
|
|
|
}
|