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

105 lines
3.1 KiB
Nix

{ config, pkgs, lib, modulesPath, ... }:
let
freifunkNodes = {
"1139" = "10.200.4.120";
"1487" = "10.200.5.213";
"1884" = "10.200.7.100";
"1891" = "10.200.7.107";
"1768" = "10.200.6.239";
"1176" = "10.200.7.80";
"1099" = "10.200.4.80";
};
in {
imports = [
(modulesPath + "/profiles/minimal.nix")
../../../lib
../../../lib/lxc-container.nix
../../../lib/shared.nix
];
c3d2 = {
isInHq = false;
hq.interface = "eth0";
enableHail = 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 (
builtins.fetchGit { url = "https://gitea.c3d2.de/astro/scrapers.git"; }
) {
inherit pkgs;
};
makeService = { script, host, user ? "", password ? "" }: {
script = "${scrapers.${script}}/bin/${script} ${host} ${user} ${password}";
};
xeriLogin = import <secrets/hosts/scrape/xeri.nix>;
fhemLogin = import <secrets/hosts/scrape/fhem.nix>;
matematLogin = import <secrets/hosts/scrape/matemat.nix>;
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 (xeriLogin) user password;
};
scrape-roxi = makeService {
script = "xerox";
host = "roxi.hq.c3d2.de";
};
scrape-fhem = makeService {
script = "fhem";
host = "fhem.hq.c3d2.de";
inherit (fhemLogin) user password;
};
scrape-matemat = makeService {
script = "matemat";
host = "matemat.hq.c3d2.de";
inherit (matematLogin) 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?
}