2020-04-27 23:39:02 +02:00
|
|
|
{ lib, pkgs, config, ... }:
|
|
|
|
|
|
|
|
# a very simple dms setup which.
|
|
|
|
# I have a brother ADS-1600W scanner, which is configured to send all
|
|
|
|
# PDFs to this machine in /home/ftp-upload/input
|
|
|
|
# from there the dms.py scans them and makes them searchable.
|
|
|
|
|
|
|
|
let
|
|
|
|
dms = pkgs.fetchgit {
|
|
|
|
url = "https://github.com/mrVanDalo/dms.git";
|
2021-02-09 08:29:55 +01:00
|
|
|
rev = "2f5c44f017bdfd8abfe908d419ef26bac300f809";
|
|
|
|
sha256 = "0dxhk1ah6wwbsxyk4hd32rz7886w7r5gfy16485gjbvky1qsi8gd";
|
2020-04-27 23:39:02 +02:00
|
|
|
};
|
|
|
|
in {
|
|
|
|
|
|
|
|
# setup ftp
|
|
|
|
services.vsftpd = {
|
|
|
|
enable = true;
|
|
|
|
userlist = [ "ftp-upload" ];
|
|
|
|
userlistEnable = true;
|
|
|
|
localUsers = true;
|
|
|
|
writeEnable = true;
|
2020-05-09 01:49:13 +02:00
|
|
|
extraConfig = ''
|
|
|
|
# additional ports for directory list and stuff
|
|
|
|
pasv_min_port=4242
|
|
|
|
pasv_max_port=4243
|
|
|
|
'';
|
2020-04-27 23:39:02 +02:00
|
|
|
};
|
|
|
|
networking.firewall.allowedTCPPortRanges = [
|
|
|
|
{
|
2020-05-09 01:49:13 +02:00
|
|
|
# ftp: additional ports for directory list and stuff
|
|
|
|
from = 4242;
|
|
|
|
to = 4243;
|
2020-04-27 23:39:02 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
# ftp
|
|
|
|
from = 20;
|
|
|
|
to = 21;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# create user
|
|
|
|
users.users.ftp-upload = {
|
|
|
|
passwordFile = toString <secrets/ftp/password>;
|
|
|
|
isNormalUser = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
# create dms service
|
|
|
|
systemd.services.dms = {
|
|
|
|
enable = true;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [
|
|
|
|
(pkgs.python3.withPackages (ps: with ps; [ flask ]))
|
2020-05-09 01:49:13 +02:00
|
|
|
pkgs.imagemagickBig
|
|
|
|
(pkgs.pdfsandwich.override { imagemagick = pkgs.imagemagickBig; })
|
2020-04-27 23:39:02 +02:00
|
|
|
pkgs.poppler_utils
|
|
|
|
pkgs.which
|
|
|
|
pkgs.netpbm
|
2020-05-09 01:49:13 +02:00
|
|
|
pkgs.gawk
|
2020-07-11 18:04:05 +02:00
|
|
|
pkgs.bash
|
2020-04-27 23:39:02 +02:00
|
|
|
];
|
|
|
|
serviceConfig = { User = "ftp-upload"; };
|
|
|
|
preStart = ''
|
|
|
|
if [[ ! -L /home/ftp-upload/db/SOURCE_DIR ]]
|
|
|
|
then
|
|
|
|
rm -rf /home/ftp-upload/db/SOURCE_DIR
|
|
|
|
mkdir -p /home/ftp-upload/db
|
|
|
|
mkdir -p /home/ftp-upload/input
|
|
|
|
ln -s /home/ftp-upload/input /home/ftp-upload/db/SOURCE_DIR
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
script = ''
|
|
|
|
DMSDATA=/home/ftp-upload/db \
|
|
|
|
FLASK_APP=${dms}/dms.py \
|
|
|
|
flask run --host 0.0.0.0 \
|
|
|
|
"$@"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# host nginx setup
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts = {
|
|
|
|
"dms.pepe.private" = {
|
2020-07-11 18:55:41 +02:00
|
|
|
serverAliases =
|
|
|
|
[ "pdf.pepe.private" "docs.pepe.private" "dms.pepe.lan" ];
|
2020-04-27 23:39:02 +02:00
|
|
|
locations."/" = { proxyPass = "http://localhost:5000"; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# add documents to backup
|
2020-09-04 00:49:35 +02:00
|
|
|
backup.dirs = [ "/home/ftp-upload/db" ];
|
2020-04-27 23:39:02 +02:00
|
|
|
|
|
|
|
}
|