Skip to content

Instantly share code, notes, and snippets.

@caadar
Created October 13, 2019 06:38
Show Gist options
  • Save caadar/40644e9dc296dea9c90e459020f1edec to your computer and use it in GitHub Desktop.
Save caadar/40644e9dc296dea9c90e459020f1edec to your computer and use it in GitHub Desktop.
Pure-FTPd with uploadscript on NixOS
#!/run/current-system/sw/bin/bash
SCANNED="$1"
AFFIX="${1##*.}"
DATESTAMP=$(date '+%Y%m%d')
TIMESTAMP=$(date '+%H%M%S')
mv "${SCANNED}" "/home/user/${DATESTAMP}..scan-${TIMESTAMP}.${AFFIX}"
{ config, pkgs, ... }:
let uploadScript = "/etc/nixos/pkgs/pure-ftpd/ftp-uploadscript.sh";
in {
nixpkgs.config.packageOverrides = pkgs:
{ pure-ftpd = pkgs.pure-ftpd.overrideAttrs (oldAttrs: {
configureFlags = [ "--with-uploadscript" ];});
};
users.groups.ftp.gid = config.ids.gids.ftp;
users.users.ftp = {
uid = config.ids.uids.ftp;
group = "ftp";
description = "Anonymous FTP user";
home = "/home/ftp";
};
users.users.scr.extraGroups = [ "ftp" ];
systemd.services.pure-ftpd = {
description = "Pure-FTPd Server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig.ExecStart = "${pkgs.pure-ftpd}/bin/pure-ftpd --daemonize --anonymousonly --anonymouscancreatedirs --uploadscript --passiveportrange 30000:50000";
serviceConfig.Type = "forking";
serviceConfig.Restart = "always";
};
systemd.services.pure-uploadscript = {
description = "Pure-FTPd helper";
wantedBy = [ "multi-user.target" ];
requires = [ "pure-ftpd.service" ];
after = [ "pure-ftpd.service" ];
serviceConfig.ConditionPathExists = uploadScript;
serviceConfig.ExecStart = "${pkgs.pure-ftpd}/bin/pure-uploadscript -B -r ${uploadScript}";
serviceConfig.Type = "forking";
serviceConfig.Restart = "always";
};
networking.firewall.allowedTCPPortRanges = [ { from = 30000; to = 50000; } ];
networking.firewall.allowedUDPPortRanges = [ { from = 30000; to = 50000; } ];
networking.firewall.allowedTCPPorts = [ 21 ];
networking.firewall.allowedUDPPorts = [ 21 ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment