1 { lib, pkgs, config, myconfig, ... }:
4 services.pure-ftpd.enable = lib.mkOption {
8 Whether to enable pure-ftpd.
13 config = lib.mkIf config.services.pure-ftpd.enable {
14 security.acme.certs."ftp" = config.services.myCertificates.certConfig // {
15 domain = "eldiron.immae.eu";
17 systemctl restart pure-ftpd.service
19 extraDomains = { "ftp.immae.eu" = null; };
22 nixpkgs.overlays = [ (self: super: {
23 pure-ftpd = self.callPackage ./pure-ftpd.nix {};
28 allowedTCPPorts = [ 21 ];
29 allowedTCPPortRanges = [ { from = 40000; to = 50000; } ];
36 uid = config.ids.uids.ftp;
38 description = "Anonymous FTP user";
39 home = "/homeless-shelter";
43 users.groups.ftp.gid = config.ids.gids.ftp;
45 system.activationScripts.pure-ftpd = ''
46 install -m 0755 -o ftp -g ftp -d /var/lib/ftp
49 systemd.services.pure-ftpd = let
50 ldapConfigFile = pkgs.writeText "pure-ftpd-ldap.conf" ''
51 LDAPServer ${myconfig.env.ftp.ldap.host}
54 LDAPBaseDN ${myconfig.env.ftp.ldap.base}
55 LDAPBindDN ${myconfig.env.ftp.ldap.dn}
56 LDAPBindPW ${myconfig.env.ftp.ldap.password}
58 LDAPForceDefaultUID False
60 LDAPForceDefaultGID False
61 LDAPFilter ${myconfig.env.ftp.ldap.filter}
65 # Pas de possibilité de donner l'Uid/Gid !
66 # Compilé dans pure-ftpd directement avec immaeFtpUid / immaeFtpGid
67 LDAPHomeDir immaeFtpDirectory
69 configFile = pkgs.writeText "pure-ftpd.conf" ''
70 PassivePortRange 40000 50000
73 BrokenClientsCompatibility yes
84 LDAPConfigFile ${ldapConfigFile}
85 LimitRecursion 10000 8
86 AnonymousCanCreateDirs no
94 ProhibitDotFilesWrite no
95 ProhibitDotFilesRead no
97 AnonymousCantUpload no
101 CertFile /var/lib/acme/ftp/full.pem
104 description = "Pure-FTPd server";
105 wantedBy = [ "multi-user.target" ];
106 after = [ "network.target" ];
108 serviceConfig.ExecStart = "${pkgs.pure-ftpd}/bin/pure-ftpd ${configFile}";
109 serviceConfig.Type = "forking";
110 serviceConfig.PIDFile = "/run/pure-ftpd.pid";