nix-config/hosts/scrape/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

353 lines
11 KiB
Nix
Raw Normal View History

2024-04-15 21:39:21 +02:00
{ lib, config, pkgs, scrapers, ... }:
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-12-21 19:43:47 +01:00
c3d2.deployment.server = "server10";
2023-09-03 23:01:16 +02:00
microvm.mem = 1024;
networking.hostName = "scrape";
users.groups.scrape = {};
users.users.scrape = {
isNormalUser = true;
group = "scrape";
# don't make /home/scrape inaccessible by nginx
createHome = false;
};
services.nginx = {
enable = true;
virtualHosts."scrape.hq.c3d2.de" = {
default = true;
forceSSL = true;
enableACME = true;
2024-05-05 14:55:41 +02:00
locations."/".root = config.users.users.scrape.home;
2021-11-12 00:24:40 +01:00
extraConfig = ''
autoindex on;
'';
};
};
2024-04-15 21:39:21 +02:00
sops = {
defaultSopsFile = ./secrets.yaml;
secrets = {
"scrape/matemat/user".owner = config.users.users.scrape.name;
"scrape/matemat/password".owner = config.users.users.scrape.name;
"scrape/xeri/user".owner = config.users.users.scrape.name;
"scrape/xeri/password".owner = config.users.users.scrape.name;
};
};
2021-02-22 11:45:12 +01:00
systemd.services = let
2022-12-27 02:24:01 +01:00
serviceConfig = {
User = config.users.users.scrape.name;
Group = config.users.users.scrape.group;
};
scraperPkgs = import scrapers { inherit pkgs; };
2024-04-15 21:39:21 +02:00
makeService = {
script,
host ? "",
userFile ? "",
passwordFile ? ""
}: {
script = "${lib.getExe scraperPkgs."${script}"} ${host} ${lib.optionalString (userFile != "") ''"$(cat ${userFile})"''} ${lib.optionalString (passwordFile != "") ''"$(cat ${passwordFile})"''}";
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
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}";
};
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 {
nginx.serviceConfig.ProtectHome = "read-only";
2021-02-22 11:45:12 +01:00
scrape-xeri = makeService {
script = "xerox";
host = "xeri.hq.c3d2.de";
2024-04-15 21:39:21 +02:00
userFile = config.sops.secrets."scrape/xeri/user".path;
2024-04-15 23:11:19 +02:00
passwordFile = config.sops.secrets."scrape/xeri/password".path;
2021-02-22 11:45:12 +01:00
};
scrape-roxi = makeService {
script = "xerox";
host = "roxi.hq.c3d2.de";
};
scrape-matemat = makeService {
script = "matemat";
host = "matemat.hq.c3d2.de";
2024-04-15 21:39:21 +02:00
userFile = config.sops.secrets."scrape/matemat/user".path;
2024-04-15 23:11:19 +02:00
passwordFile = config.sops.secrets."scrape/matemat/password".path;
2021-02-22 11:45:12 +01:00
};
2021-03-24 21:11:16 +01:00
scrape-impfee = makeService {
script = "impfee";
};
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}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
};
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}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
2021-09-08 00:34:26 +02:00
};
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}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
2021-09-08 21:12:54 +02:00
};
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}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
2021-10-13 17:56:03 +02:00
};
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}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
2021-11-12 00:24:27 +01:00
};
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
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
2022-02-08 18:38:38 +01:00
};
scrape-dresden-versammlungen = {
script = ''
${scraperPkgs.dresden-versammlungen}/bin/dresden-versammlungen > /tmp/dresden-versammlungen.ics
mv /tmp/dresden-versammlungen.ics ${config.users.users.scrape.home}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
};
scrape-azconni = {
script = ''
${scraperPkgs.azconni}/bin/azconni > /tmp/azconni.ics
mv /tmp/azconni.ics ${config.users.users.scrape.home}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
};
2022-07-14 20:38:48 +02:00
scrape-kunsthaus = {
script = ''
${scraperPkgs.kunsthaus}/bin/kunsthaus > /tmp/kunsthaus.ics
mv /tmp/kunsthaus.ics ${config.users.users.scrape.home}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
2022-07-14 20:38:48 +02:00
};
scrape-hfmdd = {
script = ''
${scraperPkgs.hfmdd}/bin/hfmdd > /tmp/hfmdd.ics
mv /tmp/hfmdd.ics ${config.users.users.scrape.home}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
};
scrape-hfbk-dresden = {
script = ''
${scraperPkgs.hfbk-dresden}/bin/hfbk-dresden > /tmp/hfbk-dresden.ics
mv /tmp/hfbk-dresden.ics ${config.users.users.scrape.home}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
};
scrape-staatsoperette = {
script = ''
${scraperPkgs.staatsoperette}/bin/staatsoperette > /tmp/staatsoperette.ics
mv /tmp/staatsoperette.ics ${config.users.users.scrape.home}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
};
2022-07-16 03:11:27 +02:00
scrape-tjg-dresden = {
script = ''
${scraperPkgs.tjg-dresden}/bin/tjg-dresden > /tmp/tjg-dresden.ics
mv /tmp/tjg-dresden.ics ${config.users.users.scrape.home}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
2022-07-16 03:11:27 +02:00
};
scrape-dresden-kulturstadt = {
script = ''
${scraperPkgs.dresden-kulturstadt}/bin/dresden-kulturstadt > /tmp/dresden-kulturstadt.ics
mv /tmp/dresden-kulturstadt.ics ${config.users.users.scrape.home}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
};
2022-10-11 02:03:24 +02:00
scrape-nabu = {
script = ''
${scraperPkgs.nabu}/bin/nabu > /tmp/nabu.ics
mv /tmp/nabu.ics ${config.users.users.scrape.home}/
'';
2022-12-27 02:24:01 +01:00
inherit serviceConfig;
2022-10-11 02:03:24 +02:00
};
2023-01-12 19:33:02 +01:00
scrape-museen-dresden = {
script = ''
${scraperPkgs.museen-dresden}/bin/museen-dresden > /tmp/museen-dresden.ics
mv /tmp/museen-dresden.ics ${config.users.users.scrape.home}/
'';
inherit serviceConfig;
};
2023-01-12 20:39:02 +01:00
scrape-criticalmass = {
script = ''
${scraperPkgs.criticalmass}/bin/criticalmass > /tmp/criticalmass.ics
mv /tmp/criticalmass.ics ${config.users.users.scrape.home}/
'';
inherit serviceConfig;
};
2023-01-12 20:56:09 +01:00
scrape-kosmotique = {
script = ''
${scraperPkgs.kosmotique}/bin/kosmotique > /tmp/kosmotique.ics
mv /tmp/kosmotique.ics ${config.users.users.scrape.home}/
'';
inherit serviceConfig;
};
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";
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" ];
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";
};
scrape-dresden-versammlungen = {
partOf = [ "scrape-dresden-versammlungen.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
scrape-azconni = {
partOf = [ "scrape-azconni.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
2022-07-14 20:38:48 +02:00
scrape-kunsthaus = {
partOf = [ "scrape-kunsthaus.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
scrape-hfmdd = {
partOf = [ "scrape-hfmdd.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
scrape-hfbk-dresden = {
partOf = [ "scrape-hfbk-dresden.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
scrape-staatsoperette = {
partOf = [ "scrape-staatsoperette.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
2022-07-16 03:11:27 +02:00
scrape-tjg-dresden = {
partOf = [ "scrape-tjg-dresden.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
scrape-dresden-kulturstadt = {
partOf = [ "scrape-dresden-kulturstadt.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
2022-10-11 02:03:24 +02:00
scrape-nabu = {
partOf = [ "scrape-nabu.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
2023-01-12 19:33:02 +01:00
scrape-museen-dresden = {
partOf = [ "scrape-museen-dresden.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
2023-01-12 20:39:02 +01:00
scrape-criticalmass = {
partOf = [ "scrape-criticalmass.service" ];
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = "hourly";
};
2023-01-12 20:56:09 +01:00
scrape-kosmotique = {
partOf = [ "scrape-kosmotique.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)
);
2022-12-27 02:24:01 +01:00
system.stateVersion = "20.03";
}