2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
2008-02-07 13:41:18 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
with pkgs.lib;
|
2008-02-07 13:41:18 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
let
|
2009-03-06 13:26:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
cfg = config.services.vsftpd;
|
|
|
|
|
|
|
|
inherit (pkgs) vsftpd;
|
2009-03-06 13:26:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
yesNoOption = p : name :
|
|
|
|
"${name}=${if p then "YES" else "NO"}";
|
2009-03-06 13:26:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
in
|
2009-04-08 16:01:16 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2008-02-07 13:41:18 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
services.vsftpd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the vsftpd FTP server.";
|
2009-03-06 13:26:43 +01:00
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
anonymousUser = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the anonymous FTP user.";
|
|
|
|
};
|
2009-03-06 13:26:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
anonymousUserHome = mkOption {
|
|
|
|
default = "/home/ftp";
|
|
|
|
description = "Path to anonymous user data.";
|
|
|
|
};
|
2009-03-06 13:26:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
localUsers = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable FTP for local users.";
|
|
|
|
};
|
2009-03-06 13:26:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
writeEnable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether any write activity is permitted to users.";
|
|
|
|
};
|
2009-03-06 13:26:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
anonymousUploadEnable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether any uploads are permitted to anonymous users.";
|
|
|
|
};
|
|
|
|
|
|
|
|
anonymousMkdirEnable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether mkdir is permitted to anonymous users.";
|
|
|
|
};
|
|
|
|
|
|
|
|
chrootlocalUser = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether local users are confined to their home directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
userlistEnable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether users are included.";
|
|
|
|
};
|
|
|
|
|
|
|
|
userlistDeny = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether users are excluded.";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-03-06 13:26:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
2009-03-06 13:26:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.extraUsers =
|
|
|
|
[ { name = "vsftpd";
|
2009-05-29 16:25:56 +02:00
|
|
|
uid = config.ids.uids.vsftpd;
|
2009-03-06 13:26:43 +01:00
|
|
|
description = "VSFTPD user";
|
|
|
|
home = "/homeless-shelter";
|
|
|
|
}
|
2009-10-12 18:36:19 +02:00
|
|
|
] ++ pkgs.lib.optional cfg.anonymousUser
|
2009-03-06 13:26:43 +01:00
|
|
|
{ name = "ftp";
|
2009-05-29 16:25:56 +02:00
|
|
|
uid = config.ids.uids.ftp;
|
2009-03-06 13:26:43 +01:00
|
|
|
group = "ftp";
|
2009-10-12 18:36:19 +02:00
|
|
|
description = "Anonymous FTP user";
|
|
|
|
home = cfg.anonymousUserHome;
|
2009-03-06 13:26:43 +01:00
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
users.extraGroups = singleton
|
2009-03-06 13:26:43 +01:00
|
|
|
{ name = "ftp";
|
2009-05-29 16:25:56 +02:00
|
|
|
gid = config.ids.gids.ftp;
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.vsftpd =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ description = "vsftpd server";
|
|
|
|
|
2009-11-06 23:19:17 +01:00
|
|
|
startOn = "started network-interfaces";
|
|
|
|
stopOn = "stopping network-interfaces";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
# !!! Why isn't this generated in the normal way?
|
|
|
|
cat > /etc/vsftpd.conf <<EOF
|
|
|
|
${yesNoOption cfg.anonymousUser "anonymous_enable"}
|
|
|
|
${yesNoOption cfg.localUsers "local_enable"}
|
|
|
|
${yesNoOption cfg.writeEnable "write_enable"}
|
|
|
|
${yesNoOption cfg.anonymousUploadEnable "anon_upload_enable"}
|
|
|
|
${yesNoOption cfg.anonymousMkdirEnable "anon_mkdir_write_enable"}
|
|
|
|
${yesNoOption cfg.chrootlocalUser "chroot_local_user"}
|
|
|
|
${yesNoOption cfg.userlistEnable "userlist_enable"}
|
|
|
|
${yesNoOption cfg.userlistDeny "userlist_deny"}
|
|
|
|
background=NO
|
|
|
|
listen=YES
|
|
|
|
nopriv_user=vsftpd
|
2011-07-28 11:42:20 +02:00
|
|
|
secure_chroot_dir=/var/empty
|
2009-10-12 18:36:19 +02:00
|
|
|
EOF
|
|
|
|
|
2010-05-08 21:12:36 +02:00
|
|
|
${if cfg.anonymousUser then ''
|
2011-07-28 11:42:20 +02:00
|
|
|
mkdir -p -m 555 ${cfg.anonymousUserHome}
|
2010-05-08 21:12:36 +02:00
|
|
|
chown -R ftp:ftp ${cfg.anonymousUserHome}
|
|
|
|
'' else ""}
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
exec = "${vsftpd}/sbin/vsftpd /etc/vsftpd.conf";
|
|
|
|
};
|
2009-03-06 13:26:43 +01:00
|
|
|
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-02-07 13:41:18 +01:00
|
|
|
}
|