2009-03-06 13:26:50 +01:00
|
|
|
{pkgs, config, ...}:
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
let
|
|
|
|
inherit (pkgs.lib) mkOption mkIf;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services = {
|
|
|
|
samba = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to enable the samba server. (to communicate with, and provide windows shares)
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
###### implementation
|
2007-05-28 16:09:04 +02:00
|
|
|
|
|
|
|
let
|
2007-05-28 17:39:25 +02:00
|
|
|
|
2007-06-08 17:41:12 +02:00
|
|
|
user = "smbguest";
|
|
|
|
group = "smbguest";
|
2008-01-14 12:24:36 +01:00
|
|
|
|
2009-03-29 23:43:40 +02:00
|
|
|
#smbConfig = ./smb.conf ;
|
|
|
|
|
|
|
|
smbConfig = pkgs.substituteAll {
|
|
|
|
src = ./smb.conf;
|
|
|
|
inherit samba;
|
|
|
|
};
|
2008-01-14 12:24:36 +01:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
inherit (pkgs) samba;
|
|
|
|
|
2007-05-28 16:09:04 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
|
2007-06-08 17:41:12 +02:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
|
|
|
|
mkIf config.services.samba.enable {
|
|
|
|
require = [
|
|
|
|
options
|
2007-06-10 22:13:12 +02:00
|
|
|
];
|
2007-05-28 16:09:04 +02:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
users = {
|
|
|
|
extraUsers = [
|
|
|
|
{ name = user;
|
|
|
|
description = "Samba service user";
|
|
|
|
group = group;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
extraGroups = [
|
|
|
|
{ name = group;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
services = {
|
|
|
|
extraJobs = [{
|
|
|
|
name = "samba";
|
|
|
|
job = ''
|
2007-05-28 16:09:04 +02:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
description "Samba Service"
|
2007-05-28 16:09:04 +02:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
start on network-interfaces/started
|
|
|
|
stop on network-interfaces/stop
|
2007-05-28 16:09:04 +02:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
start script
|
2008-01-14 12:24:36 +01:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
if ! test -d /home/smbd ; then
|
|
|
|
mkdir -p /home/smbd
|
|
|
|
chown ${user} /home/smbd
|
|
|
|
chmod a+rwx /home/smbd
|
|
|
|
fi
|
2008-01-14 12:24:36 +01:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
if ! test -d /var/samba ; then
|
|
|
|
mkdir -p /var/samba/locks /var/samba/cores/nmbd /var/samba/cores/smbd /var/samba/cores/winbindd
|
|
|
|
fi
|
2007-05-28 16:09:04 +02:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
${samba}/sbin/nmbd -D -s ${smbConfig} &
|
|
|
|
${samba}/sbin/smbd -D -s ${smbConfig} &
|
2009-04-08 16:01:16 +02:00
|
|
|
${samba}/sbin/winbindd -s ${smbConfig} &
|
2008-01-16 22:56:31 +01:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
ln -fs ${smbConfig} /var/samba/config
|
2007-05-28 16:09:04 +02:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
end script
|
2007-05-28 16:09:04 +02:00
|
|
|
|
2009-04-08 16:01:16 +02:00
|
|
|
respawn ${samba}/sbin/nmbd -D -s ${smbConfig} &; ${samba}/sbin/smbd -D -s ${smbConfig} &; ${samba}/sbin/winbindd &
|
2007-05-28 16:09:04 +02:00
|
|
|
|
2009-03-06 13:26:50 +01:00
|
|
|
'';
|
|
|
|
}];
|
|
|
|
};
|
2007-05-28 16:09:04 +02:00
|
|
|
}
|