2009-10-12 17:36:19 +01:00
|
|
|
{ config, pkgs, ... }:
|
2008-02-07 12:41:18 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
with pkgs.lib;
|
2008-02-07 12:41:18 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
let
|
2009-03-06 12:26:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
cfg = config.services.vsftpd;
|
|
|
|
|
|
|
|
inherit (pkgs) vsftpd;
|
2009-03-06 12:26:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
yesNoOption = p : name :
|
|
|
|
"${name}=${if p then "YES" else "NO"}";
|
2009-03-06 12:26:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
in
|
2009-04-08 15:01:16 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2008-02-07 12:41:18 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
services.vsftpd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the vsftpd FTP server.";
|
2009-03-06 12:26:43 +00:00
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
anonymousUser = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the anonymous FTP user.";
|
|
|
|
};
|
2009-03-06 12:26:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
anonymousUserHome = mkOption {
|
|
|
|
default = "/home/ftp";
|
|
|
|
description = "Path to anonymous user data.";
|
|
|
|
};
|
2009-03-06 12:26:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
localUsers = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable FTP for local users.";
|
|
|
|
};
|
2009-03-06 12:26:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
writeEnable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether any write activity is permitted to users.";
|
|
|
|
};
|
2009-03-06 12:26:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01: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 12:26:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
###### implementation
|
2009-03-06 12:26:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.extraUsers =
|
|
|
|
[ { name = "vsftpd";
|
2009-05-29 15:25:56 +01:00
|
|
|
uid = config.ids.uids.vsftpd;
|
2009-03-06 12:26:43 +00:00
|
|
|
description = "VSFTPD user";
|
|
|
|
home = "/homeless-shelter";
|
|
|
|
}
|
2009-10-12 17:36:19 +01:00
|
|
|
] ++ pkgs.lib.optional cfg.anonymousUser
|
2009-03-06 12:26:43 +00:00
|
|
|
{ name = "ftp";
|
2009-05-29 15:25:56 +01:00
|
|
|
uid = config.ids.uids.ftp;
|
2009-03-06 12:26:43 +00:00
|
|
|
group = "ftp";
|
2009-10-12 17:36:19 +01:00
|
|
|
description = "Anonymous FTP user";
|
|
|
|
home = cfg.anonymousUserHome;
|
2009-03-06 12:26:43 +00:00
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
users.extraGroups = singleton
|
2009-03-06 12:26:43 +00:00
|
|
|
{ name = "ftp";
|
2009-05-29 15:25:56 +01:00
|
|
|
gid = config.ids.gids.ftp;
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.vsftpd =
|
2009-10-12 17:36:19 +01:00
|
|
|
{ description = "vsftpd server";
|
|
|
|
|
2009-11-06 22:19:17 +00:00
|
|
|
startOn = "started network-interfaces";
|
|
|
|
stopOn = "stopping network-interfaces";
|
2009-10-12 17:36:19 +01: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
|
|
|
|
secure_chroot_dir=/var/ftp/empty
|
|
|
|
EOF
|
|
|
|
|
2010-05-08 20:12:36 +01:00
|
|
|
${if cfg.anonymousUser then ''
|
|
|
|
mkdir -p ${cfg.anonymousUserHome}
|
|
|
|
chown -R ftp:ftp ${cfg.anonymousUserHome}
|
|
|
|
'' else ""}
|
2009-10-12 17:36:19 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
exec = "${vsftpd}/sbin/vsftpd /etc/vsftpd.conf";
|
|
|
|
};
|
2009-03-06 12:26:43 +00:00
|
|
|
|
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2008-02-07 12:41:18 +00:00
|
|
|
}
|