2021-11-20 01:03:57 +01:00
|
|
|
{ zentralwerk, pkgs, config, scrapers, ... }:
|
2020-04-03 22:49:45 +02:00
|
|
|
|
2020-06-04 01:18:06 +02:00
|
|
|
let
|
|
|
|
freifunkNodes = {
|
|
|
|
"1139" = "10.200.4.120";
|
|
|
|
"1884" = "10.200.7.100";
|
|
|
|
"1891" = "10.200.7.107";
|
|
|
|
"1099" = "10.200.4.80";
|
2021-03-06 02:57:35 +01:00
|
|
|
"1864" = "10.200.7.80";
|
2020-06-04 01:18:06 +02:00
|
|
|
};
|
2021-03-28 20:41:22 +02:00
|
|
|
luftqualitaetStations = [ "1672" "1649" "1680" "1639" ];
|
2020-06-04 01:18:06 +02:00
|
|
|
in {
|
2022-06-13 20:32:50 +02:00
|
|
|
c3d2 = {
|
|
|
|
isInHq = false;
|
2022-06-17 00:05:21 +02:00
|
|
|
deployment = {
|
|
|
|
server = "server10";
|
|
|
|
mounts = [ "etc" "home" "var"];
|
|
|
|
};
|
2022-06-13 20:32:50 +02:00
|
|
|
};
|
2020-04-03 22:49:45 +02:00
|
|
|
|
2022-06-17 23:23:08 +02:00
|
|
|
networking.hostName = "scrape";
|
2020-04-04 00:06:59 +02:00
|
|
|
|
2021-07-17 23:17:05 +02:00
|
|
|
users.groups.scrape = {};
|
|
|
|
users.users.scrape = {
|
|
|
|
isNormalUser = true;
|
|
|
|
group = "scrape";
|
2021-09-09 18:22:06 +02:00
|
|
|
# don't make /home/scrape inaccessible by nginx
|
|
|
|
createHome = false;
|
2021-07-17 23:17:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."scrape.hq.c3d2.de" = {
|
|
|
|
default = true;
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
root = config.users.users.scrape.home;
|
2021-11-12 00:24:40 +01:00
|
|
|
extraConfig = ''
|
|
|
|
autoindex on;
|
|
|
|
'';
|
2021-07-17 23:17:05 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
|
|
|
|
2021-02-22 11:45:12 +01:00
|
|
|
systemd.services = let
|
2021-03-06 03:11:43 +01:00
|
|
|
scraperPkgs = import scrapers { inherit pkgs; };
|
2021-03-24 21:11:16 +01:00
|
|
|
makeService = { script, host ? "", user ? "", password ? "" }: {
|
2021-02-22 11:45:12 +01:00
|
|
|
script =
|
2021-10-31 19:00:03 +01:00
|
|
|
"${scraperPkgs."${script}"}/bin/${script} ${host} ${user} ${password}";
|
2021-07-17 23:17:05 +02:00
|
|
|
serviceConfig = {
|
|
|
|
User = config.users.users.scrape.name;
|
|
|
|
Group = config.users.users.scrape.group;
|
|
|
|
};
|
2021-02-22 11:45:12 +01:00
|
|
|
};
|
|
|
|
makeNodeScraper = nodeId: {
|
|
|
|
name = "scrape-node${nodeId}";
|
|
|
|
value = makeService {
|
|
|
|
script = "freifunk_node";
|
2021-10-31 19:00:03 +01:00
|
|
|
host = freifunkNodes."${nodeId}";
|
2020-04-04 04:29:04 +02:00
|
|
|
};
|
2021-02-22 11:45:12 +01:00
|
|
|
};
|
2021-03-28 20:41:22 +02:00
|
|
|
makeLuftScraper = station: {
|
|
|
|
name = "scrape-luftqualitaet${station}";
|
|
|
|
value = makeService {
|
|
|
|
script = "luftqualitaet";
|
|
|
|
host = station;
|
|
|
|
};
|
|
|
|
};
|
2021-02-22 11:45:12 +01:00
|
|
|
in {
|
2021-07-17 23:17:05 +02:00
|
|
|
nginx.serviceConfig.ProtectHome = "read-only";
|
|
|
|
|
2021-02-22 11:45:12 +01:00
|
|
|
scrape-xeri = makeService {
|
|
|
|
script = "xerox";
|
|
|
|
host = "xeri.hq.c3d2.de";
|
2021-03-06 02:57:35 +01:00
|
|
|
inherit (pkgs.scrape-xeri-login) user password;
|
2021-02-22 11:45:12 +01:00
|
|
|
};
|
|
|
|
scrape-roxi = makeService {
|
|
|
|
script = "xerox";
|
|
|
|
host = "roxi.hq.c3d2.de";
|
|
|
|
};
|
|
|
|
scrape-fhem = makeService {
|
|
|
|
script = "fhem";
|
|
|
|
host = "fhem.hq.c3d2.de";
|
2021-03-06 02:57:35 +01:00
|
|
|
inherit (pkgs.scrape-fhem-login) user password;
|
2021-02-22 11:45:12 +01:00
|
|
|
};
|
|
|
|
scrape-matemat = makeService {
|
|
|
|
script = "matemat";
|
|
|
|
host = "matemat.hq.c3d2.de";
|
2021-03-06 02:57:35 +01:00
|
|
|
inherit (pkgs.scrape-matemat-login) user password;
|
2021-02-22 11:45:12 +01:00
|
|
|
};
|
2021-03-24 21:11:16 +01:00
|
|
|
scrape-impfee = makeService {
|
|
|
|
script = "impfee";
|
|
|
|
};
|
2021-07-17 23:17:05 +02:00
|
|
|
scrape-riesa-efau-kalender = {
|
|
|
|
script = ''
|
|
|
|
${scraperPkgs.riesa-efau-kalender}/bin/riesa-efau-kalender > /tmp/riesa-efau-kalender.ics
|
|
|
|
mv /tmp/riesa-efau-kalender.ics ${config.users.users.scrape.home}/
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
User = config.users.users.scrape.name;
|
|
|
|
Group = config.users.users.scrape.group;
|
|
|
|
};
|
|
|
|
};
|
2021-09-08 00:34:26 +02:00
|
|
|
scrape-kreuzchor-termine = {
|
|
|
|
script = ''
|
|
|
|
${scraperPkgs.kreuzchor-termine}/bin/kreuzchor-termine > /tmp/kreuzchor-termine.ics
|
|
|
|
mv /tmp/kreuzchor-termine.ics ${config.users.users.scrape.home}/
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
User = config.users.users.scrape.name;
|
|
|
|
Group = config.users.users.scrape.group;
|
|
|
|
};
|
|
|
|
};
|
2021-09-08 21:12:54 +02:00
|
|
|
scrape-dhmd-veranstaltungen = {
|
|
|
|
script = ''
|
|
|
|
${scraperPkgs.dhmd-veranstaltungen}/bin/dhmd-veranstaltungen > /tmp/dhmd-veranstaltungen.ics
|
|
|
|
mv /tmp/dhmd-veranstaltungen.ics ${config.users.users.scrape.home}/
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
User = config.users.users.scrape.name;
|
|
|
|
Group = config.users.users.scrape.group;
|
|
|
|
};
|
|
|
|
};
|
2021-10-13 17:56:03 +02:00
|
|
|
scrape-mkz-programm = {
|
|
|
|
script = ''
|
|
|
|
${scraperPkgs.mkz-programm}/bin/mkz-programm > /tmp/mkz-programm.ics
|
|
|
|
mv /tmp/mkz-programm.ics ${config.users.users.scrape.home}/
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
User = config.users.users.scrape.name;
|
|
|
|
Group = config.users.users.scrape.group;
|
|
|
|
};
|
|
|
|
};
|
2021-11-12 00:24:27 +01:00
|
|
|
scrape-drk-impfaktionen = {
|
|
|
|
script = ''
|
|
|
|
${scraperPkgs.drk-impfaktionen}/bin/drk-impfaktionen > /tmp/drk-impfaktionen.ics
|
|
|
|
mv /tmp/drk-impfaktionen.ics ${config.users.users.scrape.home}/
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
User = config.users.users.scrape.name;
|
|
|
|
Group = config.users.users.scrape.group;
|
|
|
|
};
|
|
|
|
};
|
2022-02-08 18:38:38 +01:00
|
|
|
scrape-zuendstoffe = {
|
|
|
|
script = ''
|
|
|
|
${scraperPkgs.zuendstoffe}/bin/zuendstoffe > /tmp/zuendstoffe.xml
|
2022-02-08 19:13:58 +01:00
|
|
|
mv /tmp/zuendstoffe.xml ${config.users.users.scrape.home}/
|
2022-02-08 18:38:38 +01:00
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
User = config.users.users.scrape.name;
|
|
|
|
Group = config.users.users.scrape.group;
|
|
|
|
};
|
|
|
|
};
|
2021-02-22 11:45:12 +01:00
|
|
|
} // builtins.listToAttrs
|
2021-03-28 20:41:22 +02:00
|
|
|
(map makeNodeScraper (builtins.attrNames freifunkNodes) ++
|
|
|
|
map makeLuftScraper luftqualitaetStations
|
|
|
|
);
|
2020-06-04 01:18:06 +02:00
|
|
|
|
2021-02-22 11:45:12 +01:00
|
|
|
systemd.timers = let
|
|
|
|
makeTimer = service: interval: {
|
|
|
|
partOf = [ "${service}.service" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig.OnCalendar = interval;
|
|
|
|
};
|
|
|
|
makeNodeScraperTimer = nodeId:
|
|
|
|
let name = "scrape-node${nodeId}";
|
|
|
|
in {
|
|
|
|
inherit name;
|
|
|
|
value = makeTimer name "minutely";
|
2020-06-03 17:20:18 +02:00
|
|
|
};
|
2021-03-28 20:41:22 +02:00
|
|
|
makeLuftScraperTimer = station:
|
|
|
|
let name = "scrape-luftqualitaet${station}";
|
|
|
|
in {
|
|
|
|
inherit name;
|
|
|
|
value = makeTimer name "hourly";
|
|
|
|
};
|
2021-02-22 11:45:12 +01:00
|
|
|
in {
|
|
|
|
scrape-xeri = makeTimer "scrape-xeri.service" "minutely";
|
|
|
|
scrape-roxi = makeTimer "scrape-roxi.service" "minutely";
|
|
|
|
scrape-fhem = makeTimer "scrape-fhem.service" "minutely";
|
|
|
|
scrape-matemat = makeTimer "scrape-matemat.service" "minutely";
|
2021-03-24 21:11:16 +01:00
|
|
|
scrape-impfee = makeTimer "scrape-impfee.service" "minutely";
|
2021-07-17 23:17:05 +02:00
|
|
|
scrape-riesa-efau-kalender = {
|
|
|
|
partOf = [ "scrape-riesa-efau-kalender.service" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig.OnCalendar = "hourly";
|
|
|
|
};
|
2021-09-08 00:34:26 +02:00
|
|
|
scrape-kreuzchor-termine = {
|
|
|
|
partOf = [ "scrape-kreuzchor-termine.service" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig.OnCalendar = "daily";
|
|
|
|
};
|
2021-09-08 21:12:54 +02:00
|
|
|
scrape-dhmd-veranstaltungen = {
|
|
|
|
partOf = [ "scrape-dhmd-veranstaltungen.service" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
2021-09-09 18:22:31 +02:00
|
|
|
timerConfig.OnCalendar = "hourly";
|
2021-09-08 21:12:54 +02:00
|
|
|
};
|
2021-10-13 17:56:03 +02:00
|
|
|
scrape-mkz-programm = {
|
|
|
|
partOf = [ "scrape-mkz-programm.service" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig.OnCalendar = "hourly";
|
|
|
|
};
|
2021-11-12 00:24:27 +01:00
|
|
|
scrape-drk-impfaktionen = {
|
|
|
|
partOf = [ "scrape-drk-impfaktionen.service" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig.OnCalendar = "hourly";
|
|
|
|
};
|
2022-02-08 18:38:38 +01:00
|
|
|
scrape-zuendstoffe = {
|
|
|
|
partOf = [ "scrape-zuendstoffe.service" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig.OnCalendar = "hourly";
|
|
|
|
};
|
2021-02-22 11:45:12 +01:00
|
|
|
} // builtins.listToAttrs
|
2021-03-28 20:41:22 +02:00
|
|
|
(map makeNodeScraperTimer (builtins.attrNames freifunkNodes) ++
|
|
|
|
(map makeLuftScraperTimer luftqualitaetStations)
|
|
|
|
);
|
2020-04-03 22:49:45 +02:00
|
|
|
|
|
|
|
system.stateVersion = "20.03"; # Did you read the comment?
|
|
|
|
}
|