depot/ops/nixos/default.nix

90 lines
3 KiB
Nix
Raw Normal View History

# SPDX-FileCopyrightText: 2020 Luke Granger-Brown <depot@lukegb.com>
#
# SPDX-License-Identifier: Apache-2.0
{ depot, lib, pkgs, ... }@args:
let
inherit (builtins) foldl' mapAttrs;
baseModule = name: { ... }: {
_module.args = args // {
rebuilder = rebuilder name;
pkgs = lib.mkForce pkgs;
};
};
systemFor = systemName: config:
(depot.third_party.nixeval {
system = builtins.currentSystem;
modules = [ (baseModule systemName) (args: { imports = [ lib/common.nix config ]; }) ];
});
2021-01-30 04:30:05 +00:00
systems = [
"porcorosso"
2021-04-29 12:16:49 +00:00
"howl"
2021-01-30 04:30:05 +00:00
"clouvider-fra01"
"totoro"
"swann"
"clouvider-lon01"
"etheroute-lon01"
"blade-janeway"
"blade-tuvok"
"blade-paris"
"blade-torres"
"blade-chakotay"
"blade-kim"
"frantech-lux01"
"frantech-nyc01"
"frantech-las01"
"bvm-nixosmgmt"
"bvm-twitterchiver"
"bvm-prosody"
"bvm-ipfs"
2021-05-22 21:48:13 +00:00
"bvm-matrix"
2021-05-24 01:32:58 +00:00
"bvm-minecraft"
2021-08-15 22:46:57 +00:00
"bvm-netbox"
2021-09-24 22:50:30 +00:00
"bvm-radius"
2021-12-17 01:28:39 +00:00
"bvm-heptapod"
2021-12-23 04:11:39 +00:00
"bvm-logger"
2022-04-04 19:11:22 +00:00
"bvm-paperless"
2021-01-30 04:30:05 +00:00
];
rebuilder = system: (import ./lib/rebuilder.nix (args // { system = system; }));
systemCfgs = lib.genAttrs systems
(name: import (./. + "/${name}"));
evaledSystems = mapAttrs systemFor systemCfgs;
systemDrvs = mapAttrs (_: sys: sys.config.system.build.toplevel) evaledSystems;
systemTailscaleIPs = lib.mapAttrs' (n: v: lib.nameValuePair v [n]) (lib.filterAttrs (n: v: v != null) (mapAttrs (_: sys: sys.config.my.ip.tailscale) evaledSystems));
systemExporters = let
exportersForSystem = sysName: sys: let
mkExporter = exporterName: exporterPort: let jobName = "${sysName}/exporters/${exporterName}"; in lib.nameValuePair jobName {
job_name = jobName;
static_configs = [{
targets = ["${sysName}:${toString exporterPort}"];
labels = {
system = sysName;
exporter = exporterName;
};
}];
};
stockExporters = lib.mapAttrsToList (exporterName: exporter: mkExporter exporterName exporter.port) (lib.filterAttrs (exporterName: exporter: exporterName != "snmp" && exporter.enable) sys.config.services.prometheus.exporters);
customExporters = lib.mapAttrsToList mkExporter sys.config.my.prometheus.additionalExporterPorts;
in
stockExporters ++ customExporters;
in
builtins.listToAttrs (builtins.concatLists (lib.mapAttrsToList exportersForSystem evaledSystems));
2022-01-01 15:08:52 +00:00
scrapeJournalHosts =
lib.filterAttrs (n: v: v.enable) (lib.mapAttrs (n: v: v.config.my.scrapeJournal) evaledSystems);
netbootSystem = systemFor "netboot" (import ./netboot);
2021-03-18 23:51:38 +00:00
installcdSystem = systemFor "installcd" (import ./installcd);
in systemDrvs // {
2020-11-01 21:39:25 +00:00
systems = systemDrvs;
systemConfigs = evaledSystems;
systemExporters = systemExporters;
tailscaleIPs = systemTailscaleIPs;
2022-01-01 15:08:52 +00:00
scrapeJournalHosts = scrapeJournalHosts;
netboot = netbootSystem.config.system.build.pixiecore;
2021-03-18 23:51:38 +00:00
installcd = installcdSystem.config.system.build.isoImage;
systemPathJSON = pkgs.writeText "systems.json" (builtins.toJSON systemDrvs);
}