From 3099654a9716ba55e39ba9c77edf39ea03515a8f Mon Sep 17 00:00:00 2001 From: arcnmx Date: Fri, 17 May 2024 18:58:32 -0700 Subject: [PATCH] chore: nf-fmt-nix --- modules/nixos/monitoring/ingest/grafana.nix | 18 +- modules/nixos/monitoring/ingest/loki.nix | 128 +++++++------ .../nixos/monitoring/ingest/prometheus.nix | 46 +++-- .../nixos/monitoring/source/prometheus.nix | 108 +++++------ modules/nixos/monitoring/source/promtail.nix | 38 ++-- modules/system/exports/monitoring.nix | 170 +++++++++--------- systems/logistics/hardware-configuration.nix | 42 +++-- systems/logistics/nixos.nix | 4 +- 8 files changed, 297 insertions(+), 257 deletions(-) diff --git a/modules/nixos/monitoring/ingest/grafana.nix b/modules/nixos/monitoring/ingest/grafana.nix index d4a05c02..3f99a92b 100644 --- a/modules/nixos/monitoring/ingest/grafana.nix +++ b/modules/nixos/monitoring/ingest/grafana.nix @@ -1,11 +1,11 @@ _: { - services.grafana = { - #enable = true; - settings.server = { - domain = "gensokyo.zone"; - http_port = 9092; - http_addr = "0.0.0.0"; - root_url = "https://mon.gensokyo.zone"; - }; + services.grafana = { + #enable = true; + settings.server = { + domain = "gensokyo.zone"; + http_port = 9092; + http_addr = "0.0.0.0"; + root_url = "https://mon.gensokyo.zone"; }; -} \ No newline at end of file + }; +} diff --git a/modules/nixos/monitoring/ingest/loki.nix b/modules/nixos/monitoring/ingest/loki.nix index fc3a987c..0aedca73 100644 --- a/modules/nixos/monitoring/ingest/loki.nix +++ b/modules/nixos/monitoring/ingest/loki.nix @@ -1,61 +1,75 @@ -{ pkgs, config, lib, access, gensokyo-zone, ... }: let +{ + pkgs, + config, + lib, + access, + gensokyo-zone, + ... +}: let inherit (gensokyo-zone) systems; inherit (lib.attrsets) filterAttrs mapAttrsToList attrNames; - promtailSystems = filterAttrs (_: system: - system.config.exporters.promtail.enable or false - ) systems; - inherit (builtins) toJSON; - inherit (lib.options) mkOption; - inherit (lib.types) port; - cfg = config.services.loki; + promtailSystems = + filterAttrs ( + _: system: + system.config.exporters.promtail.enable or false + ) + systems; + inherit (builtins) toJSON; + inherit (lib.options) mkOption; + inherit (lib.types) port; + cfg = config.services.loki; in { - options.services.loki.settings = { - httpListenPort = mkOption { - type = port; - description = "Port to listen on over HTTP"; - default = 9093; - }; - grpcListenPort = mkOption { - type = port; - description = "Port to listen on over gRPC"; - default = 0; - }; - }; - config = { - services.loki = { - #enable = true; - configFile = pkgs.writeTextFile { - name = "config.yaml"; - executable = false; - text = (toJSON { - server = { - http_listen_port = cfg.settings.httpListenPort; - grpc_listen_port = cfg.settings.grpcListenPort; - }; - positions = { - filename = "/tmp/positions.yaml"; - }; - clients = mapAttrsToList (system: systemConfig: { - url = "${access.getAddressFor system.config.name "local"}:${system.config.exporters.promtail.port}"; - }) promtailSystems; - scrape_configs = mapAttrsToList (system: systemConfig: { - job_name = "${system.config.name}-journal"; - journal = { - max_age = "${24*7}h"; - labels = { - job = "systemd-journal"; - host = system.config.name; - }; - }; - relabel_configs = [ - { - source_labels = [ "__journal__systemd_unit" ]; - target_label = "unit"; - } - ]; - }) promtailSystems; - }); - }; - }; + options.services.loki.settings = { + httpListenPort = mkOption { + type = port; + description = "Port to listen on over HTTP"; + default = 9093; }; -} \ No newline at end of file + grpcListenPort = mkOption { + type = port; + description = "Port to listen on over gRPC"; + default = 0; + }; + }; + config = { + services.loki = { + #enable = true; + configFile = pkgs.writeTextFile { + name = "config.yaml"; + executable = false; + text = toJSON { + server = { + http_listen_port = cfg.settings.httpListenPort; + grpc_listen_port = cfg.settings.grpcListenPort; + }; + positions = { + filename = "/tmp/positions.yaml"; + }; + clients = + mapAttrsToList (system: systemConfig: { + url = "${access.getAddressFor system.config.name "local"}:${system.config.exporters.promtail.port}"; + }) + promtailSystems; + scrape_configs = + mapAttrsToList (system: systemConfig: { + job_name = "${system.config.name}-journal"; + journal = { + max_age = "${24 * 7}h"; + labels = { + job = "systemd-journal"; + host = system.config.name; + }; + }; + relabel_configs = [ + { + source_labels = ["__journal__systemd_unit"]; + target_label = "unit"; + } + ]; + }) + promtailSystems; + }; + }; + }; + }; +} diff --git a/modules/nixos/monitoring/ingest/prometheus.nix b/modules/nixos/monitoring/ingest/prometheus.nix index fb12a3f2..a8eb1b90 100644 --- a/modules/nixos/monitoring/ingest/prometheus.nix +++ b/modules/nixos/monitoring/ingest/prometheus.nix @@ -1,20 +1,30 @@ -{ access, lib, gensokyo-zone, ... }: let +{ + access, + lib, + gensokyo-zone, + ... +}: let inherit (gensokyo-zone) systems; inherit (lib.attrsets) filterAttrs mapAttrsToList attrNames; - nodeExporterSystems = filterAttrs (_: system: - system.config.exporters.prometheus-exporters-node.enable or false - ) systems; - in { - services.prometheus = { - #enable = true; - port = 9090; - scrapeConfigs = mapAttrsToList (system: systemConfig: { - job_name = "${system.config.name}-node-exporter"; - static_configs = { - targets = [ - "${access.getAddressFor system.config.name "local"}:${system.config.exporters.prometheus-exporters-node.port}" - ]; - }; - }) nodeExporterSystems; - }; -} \ No newline at end of file + nodeExporterSystems = + filterAttrs ( + _: system: + system.config.exporters.prometheus-exporters-node.enable or false + ) + systems; +in { + services.prometheus = { + #enable = true; + port = 9090; + scrapeConfigs = + mapAttrsToList (system: systemConfig: { + job_name = "${system.config.name}-node-exporter"; + static_configs = { + targets = [ + "${access.getAddressFor system.config.name "local"}:${system.config.exporters.prometheus-exporters-node.port}" + ]; + }; + }) + nodeExporterSystems; + }; +} diff --git a/modules/nixos/monitoring/source/prometheus.nix b/modules/nixos/monitoring/source/prometheus.nix index eb2da18a..3dbe6350 100644 --- a/modules/nixos/monitoring/source/prometheus.nix +++ b/modules/nixos/monitoring/source/prometheus.nix @@ -1,53 +1,57 @@ -{ config, lib, ... }: let - inherit (lib.modules) mkIf mkMerge; - in { - config = { - services.prometheus.exporters = { - node = mkMerge [ - { - #enable = true; - port = 9091; - enabledCollectors = [ - "nfs" - ]; - } - (mkIf config.services.nfs.server.enable { - enabledCollectors = [ - "nfsd" - ]; - }) - (mkIf (!config.boot.isContainer) { - enabledCollectors = [ - "nvme" - "hwmon" - ]; - }) - { - enabledCollectors = [ - "arp" - "boottime" - "cpu" - "cpufreq" - "diskstats" - "dmi" - "entropy" - "filesystem" - "netdev" - "systemd" - "sysctl" - "systemd" - "loadavg" - "meminfo" - "netstat" - "os" - "stat" - "time" - "uname" - "vmstat" - "zfs" - ]; - } - ]; - }; +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf mkMerge; +in { + config = { + services.prometheus.exporters = { + node = mkMerge [ + { + #enable = true; + port = 9091; + enabledCollectors = [ + "nfs" + ]; + } + (mkIf config.services.nfs.server.enable { + enabledCollectors = [ + "nfsd" + ]; + }) + (mkIf (!config.boot.isContainer) { + enabledCollectors = [ + "nvme" + "hwmon" + ]; + }) + { + enabledCollectors = [ + "arp" + "boottime" + "cpu" + "cpufreq" + "diskstats" + "dmi" + "entropy" + "filesystem" + "netdev" + "systemd" + "sysctl" + "systemd" + "loadavg" + "meminfo" + "netstat" + "os" + "stat" + "time" + "uname" + "vmstat" + "zfs" + ]; + } + ]; }; -} \ No newline at end of file + }; +} diff --git a/modules/nixos/monitoring/source/promtail.nix b/modules/nixos/monitoring/source/promtail.nix index c40eb959..556f368f 100644 --- a/modules/nixos/monitoring/source/promtail.nix +++ b/modules/nixos/monitoring/source/promtail.nix @@ -1,19 +1,23 @@ -{ config, lib, ... }: let - inherit (builtins) toJSON; - inherit (lib.options) mkOption; - inherit (lib.types) port; - cfg = config.services.promtail; +{ + config, + lib, + ... +}: let + inherit (builtins) toJSON; + inherit (lib.options) mkOption; + inherit (lib.types) port; + cfg = config.services.promtail; in { - options.services.promtail.settings = { - httpListenPort = mkOption { - type = port; - description = "Port to listen on over HTTP"; - default = 9094; - }; + options.services.promtail.settings = { + httpListenPort = mkOption { + type = port; + description = "Port to listen on over HTTP"; + default = 9094; }; - config.services.promtail = { - extraFlags = [ - "--server.http-listen-port=${cfg.settings.httpListenPort}" - ]; - }; -} \ No newline at end of file + }; + config.services.promtail = { + extraFlags = [ + "--server.http-listen-port=${cfg.settings.httpListenPort}" + ]; + }; +} diff --git a/modules/system/exports/monitoring.nix b/modules/system/exports/monitoring.nix index 7fd77c57..f93a176f 100644 --- a/modules/system/exports/monitoring.nix +++ b/modules/system/exports/monitoring.nix @@ -1,87 +1,91 @@ -{lib, gensokyo-zone, ...}: let +{ + lib, + gensokyo-zone, + ... +}: let inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault; inherit (lib.modules) mkIf; in { - config.exports.services = { - prometheus = { config, ... }: { - id = mkAlmostOptionDefault "prometheus"; - nixos = { - serviceAttr = "prometheus"; - assertions = mkIf config.enable [ - (nixosConfig: { - assertion = config.ports.default.port == nixosConfig.services.prometheus.port; - message = "port mismatch"; - }) - ]; - }; - ports.default = mapAlmostOptionDefaults { - port = 9090; - protocol = "http"; - }; - }; - prometheus-exporters-node = { config, ... }: { - id = mkAlmostOptionDefault "prometheus-exporters-node"; - nixos = { - serviceAttrPath = [ "services" "prometheus" "exporters" "node" ]; - assertions = mkIf config.enable [ - (nixosConfig: { - assertion = config.ports.default.port == nixosConfig.services.prometheus.exporters.node.port; - message = "port mismatch"; - }) - ]; - }; - ports.default = mapAlmostOptionDefaults { - port = 9091; - protocol = "http"; - }; - }; - grafana = { config, ... }: { - id = mkAlmostOptionDefault "grafana"; - nixos = { - serviceAttr = "grafana"; - assertions = mkIf config.enable [ - (nixosConfig: { - assertion = config.ports.default.port == nixosConfig.services.grafana.settings.server.http_port; - message = "port mismatch"; - }) - ]; - }; - ports.default = mapAlmostOptionDefaults { - port = 9092; - protocol = "http"; - }; - }; - loki = { config, ... }: { - id = mkAlmostOptionDefault "loki"; - nixos = { - serviceAttr = "loki"; - assertions = mkIf config.enable [ - (nixosConfig: { - assertion = config.ports.default.port == nixosConfig.services.loki.settings.httpListenPort; - message = "port mismatch"; - }) - ]; - }; - ports.default = mapAlmostOptionDefaults { - port = 9093; - protocol = "http"; - }; - }; - promtail = { config, ... }: { - id = mkAlmostOptionDefault "promtail"; - nixos = { - serviceAttr = "promtail"; - assertions = mkIf config.enable [ - (nixosConfig: { - assertion = config.ports.default.port == nixosConfig.services.promtail.settings.httpListenPort; - message = "port mismatch"; - }) - ]; - }; - ports.default = mapAlmostOptionDefaults { - port = 9094; - protocol = "http"; - }; - }; + config.exports.services = { + prometheus = {config, ...}: { + id = mkAlmostOptionDefault "prometheus"; + nixos = { + serviceAttr = "prometheus"; + assertions = mkIf config.enable [ + (nixosConfig: { + assertion = config.ports.default.port == nixosConfig.services.prometheus.port; + message = "port mismatch"; + }) + ]; }; - } + ports.default = mapAlmostOptionDefaults { + port = 9090; + protocol = "http"; + }; + }; + prometheus-exporters-node = {config, ...}: { + id = mkAlmostOptionDefault "prometheus-exporters-node"; + nixos = { + serviceAttrPath = ["services" "prometheus" "exporters" "node"]; + assertions = mkIf config.enable [ + (nixosConfig: { + assertion = config.ports.default.port == nixosConfig.services.prometheus.exporters.node.port; + message = "port mismatch"; + }) + ]; + }; + ports.default = mapAlmostOptionDefaults { + port = 9091; + protocol = "http"; + }; + }; + grafana = {config, ...}: { + id = mkAlmostOptionDefault "grafana"; + nixos = { + serviceAttr = "grafana"; + assertions = mkIf config.enable [ + (nixosConfig: { + assertion = config.ports.default.port == nixosConfig.services.grafana.settings.server.http_port; + message = "port mismatch"; + }) + ]; + }; + ports.default = mapAlmostOptionDefaults { + port = 9092; + protocol = "http"; + }; + }; + loki = {config, ...}: { + id = mkAlmostOptionDefault "loki"; + nixos = { + serviceAttr = "loki"; + assertions = mkIf config.enable [ + (nixosConfig: { + assertion = config.ports.default.port == nixosConfig.services.loki.settings.httpListenPort; + message = "port mismatch"; + }) + ]; + }; + ports.default = mapAlmostOptionDefaults { + port = 9093; + protocol = "http"; + }; + }; + promtail = {config, ...}: { + id = mkAlmostOptionDefault "promtail"; + nixos = { + serviceAttr = "promtail"; + assertions = mkIf config.enable [ + (nixosConfig: { + assertion = config.ports.default.port == nixosConfig.services.promtail.settings.httpListenPort; + message = "port mismatch"; + }) + ]; + }; + ports.default = mapAlmostOptionDefaults { + port = 9094; + protocol = "http"; + }; + }; + }; +} diff --git a/systems/logistics/hardware-configuration.nix b/systems/logistics/hardware-configuration.nix index 09b4c3ba..dfc6566e 100644 --- a/systems/logistics/hardware-configuration.nix +++ b/systems/logistics/hardware-configuration.nix @@ -1,30 +1,34 @@ # Do not modify this file! It was generated by ‘nixos-generate-config’ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/nixos.nix instead. -{ config, lib, pkgs, modulesPath, ... }: - { - imports = - [ (modulesPath + "/installer/scan/not-detected.nix") - ]; + config, + 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.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.extraModulePackages = [ ]; + boot.initrd.availableKernelModules = ["xhci_pci" "nvme" "usb_storage" "sd_mod" "rtsx_pci_sdmmc"]; + boot.initrd.kernelModules = []; + boot.kernelModules = ["kvm-intel"]; + boot.extraModulePackages = []; - fileSystems."/" = - { device = "/dev/disk/by-uuid/3331f9a0-6b86-411c-8574-63de28046cf2"; - fsType = "ext4"; - }; + fileSystems."/" = { + device = "/dev/disk/by-uuid/3331f9a0-6b86-411c-8574-63de28046cf2"; + fsType = "ext4"; + }; - fileSystems."/boot" = - { device = "/dev/disk/by-uuid/8DC2-0DAE"; - fsType = "vfat"; - options = [ "fmask=0022" "dmask=0022" ]; - }; + fileSystems."/boot" = { + device = "/dev/disk/by-uuid/8DC2-0DAE"; + fsType = "vfat"; + options = ["fmask=0022" "dmask=0022"]; + }; - swapDevices = [ ]; + swapDevices = []; # 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 diff --git a/systems/logistics/nixos.nix b/systems/logistics/nixos.nix index 21ac530c..0a1b6239 100644 --- a/systems/logistics/nixos.nix +++ b/systems/logistics/nixos.nix @@ -88,8 +88,8 @@ # List packages installed in system profile. To search, run: # $ nix search wget environment.systemPackages = with pkgs; [ - # vim # Do not forget to add an editor to edit nixos.nix! The Nano editor is also installed by default. - # wget + # vim # Do not forget to add an editor to edit nixos.nix! The Nano editor is also installed by default. + # wget ]; # Some programs need SUID wrappers, can be configured further or are