208 lines
6.4 KiB
Nix
208 lines
6.4 KiB
Nix
{ pkgs, config, scrapers, ... }:
|
|
|
|
let
|
|
freifunkNodes = {
|
|
"1139" = "10.200.4.120";
|
|
"1884" = "10.200.7.100";
|
|
"1891" = "10.200.7.107";
|
|
"1099" = "10.200.4.80";
|
|
"1864" = "10.200.7.80";
|
|
};
|
|
luftqualitaetStations = [ "1672" "1649" "1680" "1639" ];
|
|
in {
|
|
c3d2.isInHq = false;
|
|
|
|
networking.hostName = "scrape";
|
|
networking.interfaces.eth0.ipv4.addresses = [{
|
|
address = "172.20.73.32";
|
|
prefixLength = 26;
|
|
}];
|
|
networking.defaultGateway = "172.20.73.1";
|
|
# Required for deployment
|
|
services.openssh.enable = true;
|
|
|
|
users.groups.scrape = {};
|
|
users.users.scrape = {
|
|
isNormalUser = true;
|
|
group = "scrape";
|
|
# don't make /home/scrape inaccessible by nginx
|
|
createHome = false;
|
|
};
|
|
|
|
services.nginx = {
|
|
enable = true;
|
|
recommendedProxySettings = true;
|
|
virtualHosts."scrape.hq.c3d2.de" = {
|
|
default = true;
|
|
forceSSL = true;
|
|
enableACME = true;
|
|
root = config.users.users.scrape.home;
|
|
};
|
|
};
|
|
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
|
|
|
systemd.services = let
|
|
scraperPkgs = import scrapers { inherit pkgs; };
|
|
makeService = { script, host ? "", user ? "", password ? "" }: {
|
|
script =
|
|
"${scraperPkgs."${script}"}/bin/${script} ${host} ${user} ${password}";
|
|
serviceConfig = {
|
|
User = config.users.users.scrape.name;
|
|
Group = config.users.users.scrape.group;
|
|
};
|
|
};
|
|
makeNodeScraper = nodeId: {
|
|
name = "scrape-node${nodeId}";
|
|
value = makeService {
|
|
script = "freifunk_node";
|
|
host = freifunkNodes."${nodeId}";
|
|
};
|
|
};
|
|
makeLuftScraper = station: {
|
|
name = "scrape-luftqualitaet${station}";
|
|
value = makeService {
|
|
script = "luftqualitaet";
|
|
host = station;
|
|
};
|
|
};
|
|
in {
|
|
nginx.serviceConfig.ProtectHome = "read-only";
|
|
|
|
scrape-xeri = makeService {
|
|
script = "xerox";
|
|
host = "xeri.hq.c3d2.de";
|
|
inherit (pkgs.scrape-xeri-login) user password;
|
|
};
|
|
scrape-roxi = makeService {
|
|
script = "xerox";
|
|
host = "roxi.hq.c3d2.de";
|
|
};
|
|
scrape-fhem = makeService {
|
|
script = "fhem";
|
|
host = "fhem.hq.c3d2.de";
|
|
inherit (pkgs.scrape-fhem-login) user password;
|
|
};
|
|
scrape-matemat = makeService {
|
|
script = "matemat";
|
|
host = "matemat.hq.c3d2.de";
|
|
inherit (pkgs.scrape-matemat-login) user password;
|
|
};
|
|
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}/
|
|
'';
|
|
serviceConfig = {
|
|
User = config.users.users.scrape.name;
|
|
Group = config.users.users.scrape.group;
|
|
};
|
|
};
|
|
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;
|
|
};
|
|
};
|
|
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;
|
|
};
|
|
};
|
|
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;
|
|
};
|
|
};
|
|
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;
|
|
};
|
|
};
|
|
} // builtins.listToAttrs
|
|
(map makeNodeScraper (builtins.attrNames freifunkNodes) ++
|
|
map makeLuftScraper luftqualitaetStations
|
|
);
|
|
|
|
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";
|
|
};
|
|
makeLuftScraperTimer = station:
|
|
let name = "scrape-luftqualitaet${station}";
|
|
in {
|
|
inherit name;
|
|
value = makeTimer name "hourly";
|
|
};
|
|
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";
|
|
scrape-impfee = makeTimer "scrape-impfee.service" "minutely";
|
|
scrape-riesa-efau-kalender = {
|
|
partOf = [ "scrape-riesa-efau-kalender.service" ];
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig.OnCalendar = "hourly";
|
|
};
|
|
scrape-kreuzchor-termine = {
|
|
partOf = [ "scrape-kreuzchor-termine.service" ];
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig.OnCalendar = "daily";
|
|
};
|
|
scrape-dhmd-veranstaltungen = {
|
|
partOf = [ "scrape-dhmd-veranstaltungen.service" ];
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig.OnCalendar = "hourly";
|
|
};
|
|
scrape-mkz-programm = {
|
|
partOf = [ "scrape-mkz-programm.service" ];
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig.OnCalendar = "hourly";
|
|
};
|
|
scrape-drk-impfaktionen = {
|
|
partOf = [ "scrape-drk-impfaktionen.service" ];
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig.OnCalendar = "hourly";
|
|
};
|
|
} // builtins.listToAttrs
|
|
(map makeNodeScraperTimer (builtins.attrNames freifunkNodes) ++
|
|
(map makeLuftScraperTimer luftqualitaetStations)
|
|
);
|
|
|
|
# This value determines the NixOS release with which your system is to be
|
|
# compatible, in order to avoid breaking some software such as database
|
|
# servers. You should change this only after NixOS release notes say you
|
|
# should.
|
|
system.stateVersion = "20.03"; # Did you read the comment?
|
|
}
|