nix-config/hosts/containers/scrape/default.nix

91 lines
2.7 KiB
Nix

{ config, pkgs, lib, modulesPath, ... }:
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";
};
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 krops
services.openssh.enable = true;
environment.systemPackages = [ pkgs.git ];
systemd.services = let
scrapers = import (pkgs.fetchgit {
url = "https://gitea.c3d2.de/astro/scrapers.git";
rev = "77c864b4d7e1ef4075ed115b036791c75176bef7";
sha256 = "1rj4dyn89zqyfaiv2ffi6g4x86l2xfgybyy5hlvxzgcabwaxdjyh";
}) { inherit pkgs; };
makeService = { script, host, user ? "", password ? "" }: {
script =
"${scrapers.${script}}/bin/${script} ${host} ${user} ${password}";
};
makeNodeScraper = nodeId: {
name = "scrape-node${nodeId}";
value = makeService {
script = "freifunk_node";
host = freifunkNodes.${nodeId};
};
};
in {
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;
};
} // builtins.listToAttrs
(map makeNodeScraper (builtins.attrNames freifunkNodes));
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";
};
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";
} // builtins.listToAttrs
(map makeNodeScraperTimer (builtins.attrNames freifunkNodes));
# 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?
}