Finish modularising config

There are still some things I want to change, but at least there aren't two systems now.
This commit is contained in:
Charlotte Van Petegem 2021-06-27 00:11:23 +02:00
parent 9f04c5d815
commit 0df4d5654f
No known key found for this signature in database
GPG key ID: 019E764B7184435A
68 changed files with 860 additions and 1441 deletions

66
modules/deluge-server.nix Normal file
View file

@ -0,0 +1,66 @@
{ config, lib, pkgs, ... }:
{
options.chvp.deluge-server = {
enable = lib.mkOption {
default = false;
example = true;
};
count = lib.mkOption {
default = 1;
example = 6;
};
};
config = lib.mkIf config.chvp.deluge-server.enable {
chvp.nginx.hosts = builtins.genList
(n: {
fqdn = "del${toString (n + 1)}.vanpetegem.me";
basicProxy = "http://localhost:${toString (8112 + n)}";
})
config.chvp.deluge-server.count;
networking.firewall = {
allowedTCPPortRanges = [
{ from = 60000; to = 60000 + config.chvp.deluge-server.count - 1; }
{ from = 58846; to = 58846 + config.chvp.deluge-server.count - 1; }
];
};
systemd.services = builtins.foldl' (x: y: x // y) { } (builtins.genList
(n:
let num = toString (n + 1); in
{
"del${num}" = {
after = [ "network.target" ];
description = "Deluge daemon ${num}";
wantedBy = [ "multi-user.target" ];
path = [ pkgs.deluge ];
serviceConfig = {
ExecStart = ''
${pkgs.deluge}/bin/deluged --do-not-daemonize --config /data/var/lib/deluge/del${toString (n + 1)}
'';
Restart = "on-success";
User = "charlotte";
Group = "users";
UMask = "022";
};
};
"del${num}-web" = {
after = [ "network.target" "del${num}.service" ];
requires = [ "del${num}.service" ];
description = "Deluge Web UI for daemon ${num}";
wantedBy = [ "multi-user.target" ];
path = [ pkgs.deluge ];
serviceConfig = {
ExecStart = ''
${pkgs.deluge}/bin/deluge-web --do-not-daemonize --config /data/var/lib/deluge/del${toString (n + 1)} --port ${toString (8112 + n)}
'';
User = "charlotte";
Group = "users";
};
};
})
config.chvp.deluge-server.count);
};
}