chore: nf-fmt-nix

This commit is contained in:
arcnmx 2024-05-17 18:58:32 -07:00
parent 1d806cd552
commit 3099654a97
8 changed files with 297 additions and 257 deletions

View file

@ -1,9 +1,19 @@
{ pkgs, config, lib, access, gensokyo-zone, ... }: let {
pkgs,
config,
lib,
access,
gensokyo-zone,
...
}: let
inherit (gensokyo-zone) systems; inherit (gensokyo-zone) systems;
inherit (lib.attrsets) filterAttrs mapAttrsToList attrNames; inherit (lib.attrsets) filterAttrs mapAttrsToList attrNames;
promtailSystems = filterAttrs (_: system: promtailSystems =
filterAttrs (
_: system:
system.config.exporters.promtail.enable or false system.config.exporters.promtail.enable or false
) systems; )
systems;
inherit (builtins) toJSON; inherit (builtins) toJSON;
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.types) port; inherit (lib.types) port;
@ -27,7 +37,7 @@ in {
configFile = pkgs.writeTextFile { configFile = pkgs.writeTextFile {
name = "config.yaml"; name = "config.yaml";
executable = false; executable = false;
text = (toJSON { text = toJSON {
server = { server = {
http_listen_port = cfg.settings.httpListenPort; http_listen_port = cfg.settings.httpListenPort;
grpc_listen_port = cfg.settings.grpcListenPort; grpc_listen_port = cfg.settings.grpcListenPort;
@ -35,13 +45,16 @@ in {
positions = { positions = {
filename = "/tmp/positions.yaml"; filename = "/tmp/positions.yaml";
}; };
clients = mapAttrsToList (system: systemConfig: { clients =
mapAttrsToList (system: systemConfig: {
url = "${access.getAddressFor system.config.name "local"}:${system.config.exporters.promtail.port}"; url = "${access.getAddressFor system.config.name "local"}:${system.config.exporters.promtail.port}";
}) promtailSystems; })
scrape_configs = mapAttrsToList (system: systemConfig: { promtailSystems;
scrape_configs =
mapAttrsToList (system: systemConfig: {
job_name = "${system.config.name}-journal"; job_name = "${system.config.name}-journal";
journal = { journal = {
max_age = "${24*7}h"; max_age = "${24 * 7}h";
labels = { labels = {
job = "systemd-journal"; job = "systemd-journal";
host = system.config.name; host = system.config.name;
@ -49,12 +62,13 @@ in {
}; };
relabel_configs = [ relabel_configs = [
{ {
source_labels = [ "__journal__systemd_unit" ]; source_labels = ["__journal__systemd_unit"];
target_label = "unit"; target_label = "unit";
} }
]; ];
}) promtailSystems; })
}); promtailSystems;
};
}; };
}; };
}; };

View file

@ -1,20 +1,30 @@
{ access, lib, gensokyo-zone, ... }: let {
access,
lib,
gensokyo-zone,
...
}: let
inherit (gensokyo-zone) systems; inherit (gensokyo-zone) systems;
inherit (lib.attrsets) filterAttrs mapAttrsToList attrNames; inherit (lib.attrsets) filterAttrs mapAttrsToList attrNames;
nodeExporterSystems = filterAttrs (_: system: nodeExporterSystems =
filterAttrs (
_: system:
system.config.exporters.prometheus-exporters-node.enable or false system.config.exporters.prometheus-exporters-node.enable or false
) systems; )
in { systems;
in {
services.prometheus = { services.prometheus = {
#enable = true; #enable = true;
port = 9090; port = 9090;
scrapeConfigs = mapAttrsToList (system: systemConfig: { scrapeConfigs =
mapAttrsToList (system: systemConfig: {
job_name = "${system.config.name}-node-exporter"; job_name = "${system.config.name}-node-exporter";
static_configs = { static_configs = {
targets = [ targets = [
"${access.getAddressFor system.config.name "local"}:${system.config.exporters.prometheus-exporters-node.port}" "${access.getAddressFor system.config.name "local"}:${system.config.exporters.prometheus-exporters-node.port}"
]; ];
}; };
}) nodeExporterSystems; })
nodeExporterSystems;
}; };
} }

View file

@ -1,6 +1,10 @@
{ config, lib, ... }: let {
config,
lib,
...
}: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
in { in {
config = { config = {
services.prometheus.exporters = { services.prometheus.exporters = {
node = mkMerge [ node = mkMerge [

View file

@ -1,4 +1,8 @@
{ config, lib, ... }: let {
config,
lib,
...
}: let
inherit (builtins) toJSON; inherit (builtins) toJSON;
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.types) port; inherit (lib.types) port;

View file

@ -1,9 +1,13 @@
{lib, gensokyo-zone, ...}: let {
lib,
gensokyo-zone,
...
}: let
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault; inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
in { in {
config.exports.services = { config.exports.services = {
prometheus = { config, ... }: { prometheus = {config, ...}: {
id = mkAlmostOptionDefault "prometheus"; id = mkAlmostOptionDefault "prometheus";
nixos = { nixos = {
serviceAttr = "prometheus"; serviceAttr = "prometheus";
@ -19,10 +23,10 @@ in {
protocol = "http"; protocol = "http";
}; };
}; };
prometheus-exporters-node = { config, ... }: { prometheus-exporters-node = {config, ...}: {
id = mkAlmostOptionDefault "prometheus-exporters-node"; id = mkAlmostOptionDefault "prometheus-exporters-node";
nixos = { nixos = {
serviceAttrPath = [ "services" "prometheus" "exporters" "node" ]; serviceAttrPath = ["services" "prometheus" "exporters" "node"];
assertions = mkIf config.enable [ assertions = mkIf config.enable [
(nixosConfig: { (nixosConfig: {
assertion = config.ports.default.port == nixosConfig.services.prometheus.exporters.node.port; assertion = config.ports.default.port == nixosConfig.services.prometheus.exporters.node.port;
@ -35,7 +39,7 @@ in {
protocol = "http"; protocol = "http";
}; };
}; };
grafana = { config, ... }: { grafana = {config, ...}: {
id = mkAlmostOptionDefault "grafana"; id = mkAlmostOptionDefault "grafana";
nixos = { nixos = {
serviceAttr = "grafana"; serviceAttr = "grafana";
@ -51,7 +55,7 @@ in {
protocol = "http"; protocol = "http";
}; };
}; };
loki = { config, ... }: { loki = {config, ...}: {
id = mkAlmostOptionDefault "loki"; id = mkAlmostOptionDefault "loki";
nixos = { nixos = {
serviceAttr = "loki"; serviceAttr = "loki";
@ -67,7 +71,7 @@ in {
protocol = "http"; protocol = "http";
}; };
}; };
promtail = { config, ... }: { promtail = {config, ...}: {
id = mkAlmostOptionDefault "promtail"; id = mkAlmostOptionDefault "promtail";
nixos = { nixos = {
serviceAttr = "promtail"; serviceAttr = "promtail";
@ -84,4 +88,4 @@ in {
}; };
}; };
}; };
} }

View file

@ -1,30 +1,34 @@
# Do not modify this file! It was generated by nixos-generate-config # Do not modify this file! It was generated by nixos-generate-config
# and may be overwritten by future invocations. Please make changes # and may be overwritten by future invocations. Please make changes
# to /etc/nixos/nixos.nix instead. # to /etc/nixos/nixos.nix instead.
{ config, lib, pkgs, modulesPath, ... }:
{ {
imports = config,
[ (modulesPath + "/installer/scan/not-detected.nix") lib,
pkgs,
modulesPath,
...
}: {
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
]; ];
boot.initrd.availableKernelModules = [ "xhci_pci" "nvme" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ]; boot.initrd.availableKernelModules = ["xhci_pci" "nvme" "usb_storage" "sd_mod" "rtsx_pci_sdmmc"];
boot.initrd.kernelModules = [ ]; boot.initrd.kernelModules = [];
boot.kernelModules = [ "kvm-intel" ]; boot.kernelModules = ["kvm-intel"];
boot.extraModulePackages = [ ]; boot.extraModulePackages = [];
fileSystems."/" = fileSystems."/" = {
{ device = "/dev/disk/by-uuid/3331f9a0-6b86-411c-8574-63de28046cf2"; device = "/dev/disk/by-uuid/3331f9a0-6b86-411c-8574-63de28046cf2";
fsType = "ext4"; fsType = "ext4";
}; };
fileSystems."/boot" = fileSystems."/boot" = {
{ device = "/dev/disk/by-uuid/8DC2-0DAE"; device = "/dev/disk/by-uuid/8DC2-0DAE";
fsType = "vfat"; fsType = "vfat";
options = [ "fmask=0022" "dmask=0022" ]; options = ["fmask=0022" "dmask=0022"];
}; };
swapDevices = [ ]; swapDevices = [];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's # (the default) this is the recommended approach. When using systemd-networkd it's