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

91 lines
2.7 KiB
Nix
Raw Normal View History

2020-08-04 17:15:07 +02:00
{ config, pkgs, lib, modulesPath, ... }:
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
};
in {
2021-03-06 02:57:35 +01:00
c3d2.isInHq = false;
networking.hostName = "scrape";
2021-02-22 11:45:12 +01:00
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 ];
2021-02-22 11:45:12 +01:00
systemd.services = let
2021-03-06 02:57:35 +01:00
scrapers = import (pkgs.fetchgit {
2021-02-22 11:45:12 +01:00
url = "https://gitea.c3d2.de/astro/scrapers.git";
2021-03-06 02:57:35 +01:00
rev = "77c864b4d7e1ef4075ed115b036791c75176bef7";
sha256 = "1rj4dyn89zqyfaiv2ffi6g4x86l2xfgybyy5hlvxzgcabwaxdjyh";
2021-02-22 11:45:12 +01:00
}) { 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};
};
2021-02-22 11:45:12 +01:00
};
in {
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
};
} // builtins.listToAttrs
(map makeNodeScraper (builtins.attrNames freifunkNodes));
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-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";
} // 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?
}