depot/ops/nixos/default.nix

97 lines
3.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, system, ... }@args:
let
inherit (builtins) foldl' mapAttrs;
inherit (lib) filterAttrs;
baseModule = name: { ... }: {
_module.args = args // {
rebuilder = rebuilder name;
pkgs = lib.mkForce pkgs;
};
};
systemFor = systemName: config:
(depot.third_party.nixeval {
inherit system;
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"
2024-03-01 14:23:22 +00:00
"nausicaa"
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"
"oracle-lon01"
2023-01-17 19:36:53 +00:00
"kerrigan"
2023-01-17 22:09:48 +00:00
"cofractal-ams01"
2024-01-15 01:08:01 +00:00
"laputa"
2021-01-30 04:30:05 +00:00
];
rebuilder = system: (import ./lib/rebuilder.nix (args // { system = system; }));
systemCfgs = lib.genAttrs systems
(name: import (./. + "/${name}"));
2022-04-20 22:47:09 +00:00
allEvaledSystems = mapAttrs systemFor systemCfgs;
evaledSystems = lib.filterAttrs (n: v: v.config.my.systemType == system) allEvaledSystems;
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;
};
}];
};
2022-12-29 14:15:58 +00:00
stockExporters = lib.mapAttrsToList (exporterName: exporter: mkExporter exporterName exporter.port) (lib.filterAttrs (exporterName: exporter: exporterName != "unifi-poller" && exporterName != "snmp" && builtins.isAttrs exporter && 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;
2022-04-20 22:47:09 +00:00
systemConfigs = allEvaledSystems;
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);
}