# SPDX-FileCopyrightText: 2020 Luke Granger-Brown # # 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 ]; }) ]; }); systems = [ "porcorosso" "howl" "nausicaa" "clouvider-fra01" "totoro" "swann" "clouvider-lon01" "etheroute-lon01" "frantech-lux01" "frantech-nyc01" "frantech-las01" "bvm-nixosmgmt" "bvm-twitterchiver" "bvm-prosody" "bvm-ipfs" "bvm-matrix" "bvm-minecraft" "bvm-netbox" "bvm-radius" "bvm-heptapod" "bvm-logger" "bvm-paperless" "oracle-lon01" "kerrigan" "cofractal-ams01" "laputa" "rexxar" ]; rebuilder = system: (import ./lib/rebuilder.nix (args // { system = system; })); systemCfgs = lib.genAttrs systems (name: import (./. + "/${name}")); 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; }; }]; }; allowStockExporters = { unifi-poller = false; snmp = false; minio = false; }; stockExporters = lib.mapAttrsToList (exporterName: exporter: mkExporter exporterName exporter.port) (lib.filterAttrs (exporterName: exporter: (allowStockExporters.${exporterName} or true) && 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)); scrapeJournalHosts = lib.filterAttrs (n: v: v.enable) (lib.mapAttrs (n: v: v.config.my.scrapeJournal) evaledSystems); netbootSystem = systemFor "netboot" (import ./netboot); installcdSystem = systemFor "installcd" (import ./installcd); in systemDrvs // { systems = systemDrvs; systemConfigs = allEvaledSystems; systemExporters = systemExporters; tailscaleIPs = systemTailscaleIPs; scrapeJournalHosts = scrapeJournalHosts; netboot = netbootSystem.config.system.build.pixiecore; installcd = installcdSystem.config.system.build.isoImage; systemPathJSON = pkgs.writeText "systems.json" (builtins.toJSON systemDrvs); }