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,11 +1,11 @@
_: { _: {
services.grafana = { services.grafana = {
#enable = true; #enable = true;
settings.server = { settings.server = {
domain = "gensokyo.zone"; domain = "gensokyo.zone";
http_port = 9092; http_port = 9092;
http_addr = "0.0.0.0"; http_addr = "0.0.0.0";
root_url = "https://mon.gensokyo.zone"; root_url = "https://mon.gensokyo.zone";
};
}; };
} };
}

View file

@ -1,61 +1,75 @@
{ 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 =
system.config.exporters.promtail.enable or false filterAttrs (
) systems; _: system:
inherit (builtins) toJSON; system.config.exporters.promtail.enable or false
inherit (lib.options) mkOption; )
inherit (lib.types) port; systems;
cfg = config.services.loki; inherit (builtins) toJSON;
inherit (lib.options) mkOption;
inherit (lib.types) port;
cfg = config.services.loki;
in { in {
options.services.loki.settings = { options.services.loki.settings = {
httpListenPort = mkOption { httpListenPort = mkOption {
type = port; type = port;
description = "Port to listen on over HTTP"; description = "Port to listen on over HTTP";
default = 9093; 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;
});
};
};
}; };
} 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;
};
};
};
};
}

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 =
system.config.exporters.prometheus-exporters-node.enable or false filterAttrs (
) systems; _: system:
in { system.config.exporters.prometheus-exporters-node.enable or false
services.prometheus = { )
#enable = true; systems;
port = 9090; in {
scrapeConfigs = mapAttrsToList (system: systemConfig: { services.prometheus = {
job_name = "${system.config.name}-node-exporter"; #enable = true;
static_configs = { port = 9090;
targets = [ scrapeConfigs =
"${access.getAddressFor system.config.name "local"}:${system.config.exporters.prometheus-exporters-node.port}" mapAttrsToList (system: systemConfig: {
]; job_name = "${system.config.name}-node-exporter";
}; static_configs = {
}) nodeExporterSystems; targets = [
}; "${access.getAddressFor system.config.name "local"}:${system.config.exporters.prometheus-exporters-node.port}"
} ];
};
})
nodeExporterSystems;
};
}

View file

@ -1,53 +1,57 @@
{ config, lib, ... }: let {
inherit (lib.modules) mkIf mkMerge; config,
in { lib,
config = { ...
services.prometheus.exporters = { }: let
node = mkMerge [ inherit (lib.modules) mkIf mkMerge;
{ in {
#enable = true; config = {
port = 9091; services.prometheus.exporters = {
enabledCollectors = [ node = mkMerge [
"nfs" {
]; #enable = true;
} port = 9091;
(mkIf config.services.nfs.server.enable { enabledCollectors = [
enabledCollectors = [ "nfs"
"nfsd" ];
]; }
}) (mkIf config.services.nfs.server.enable {
(mkIf (!config.boot.isContainer) { enabledCollectors = [
enabledCollectors = [ "nfsd"
"nvme" ];
"hwmon" })
]; (mkIf (!config.boot.isContainer) {
}) enabledCollectors = [
{ "nvme"
enabledCollectors = [ "hwmon"
"arp" ];
"boottime" })
"cpu" {
"cpufreq" enabledCollectors = [
"diskstats" "arp"
"dmi" "boottime"
"entropy" "cpu"
"filesystem" "cpufreq"
"netdev" "diskstats"
"systemd" "dmi"
"sysctl" "entropy"
"systemd" "filesystem"
"loadavg" "netdev"
"meminfo" "systemd"
"netstat" "sysctl"
"os" "systemd"
"stat" "loadavg"
"time" "meminfo"
"uname" "netstat"
"vmstat" "os"
"zfs" "stat"
]; "time"
} "uname"
]; "vmstat"
}; "zfs"
];
}
];
}; };
} };
}

View file

@ -1,19 +1,23 @@
{ config, lib, ... }: let {
inherit (builtins) toJSON; config,
inherit (lib.options) mkOption; lib,
inherit (lib.types) port; ...
cfg = config.services.promtail; }: let
inherit (builtins) toJSON;
inherit (lib.options) mkOption;
inherit (lib.types) port;
cfg = config.services.promtail;
in { in {
options.services.promtail.settings = { options.services.promtail.settings = {
httpListenPort = mkOption { httpListenPort = mkOption {
type = port; type = port;
description = "Port to listen on over HTTP"; description = "Port to listen on over HTTP";
default = 9094; default = 9094;
};
}; };
config.services.promtail = { };
extraFlags = [ config.services.promtail = {
"--server.http-listen-port=${cfg.settings.httpListenPort}" extraFlags = [
]; "--server.http-listen-port=${cfg.settings.httpListenPort}"
}; ];
} };
}

View file

@ -1,87 +1,91 @@
{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";
assertions = mkIf config.enable [ assertions = mkIf config.enable [
(nixosConfig: { (nixosConfig: {
assertion = config.ports.default.port == nixosConfig.services.prometheus.port; assertion = config.ports.default.port == nixosConfig.services.prometheus.port;
message = "port mismatch"; 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";
};
};
}; };
} 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";
};
};
};
}

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

View file

@ -88,8 +88,8 @@
# List packages installed in system profile. To search, run: # List packages installed in system profile. To search, run:
# $ nix search wget # $ nix search wget
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
# vim # Do not forget to add an editor to edit nixos.nix! The Nano editor is also installed by default. # vim # Do not forget to add an editor to edit nixos.nix! The Nano editor is also installed by default.
# wget # wget
]; ];
# Some programs need SUID wrappers, can be configured further or are # Some programs need SUID wrappers, can be configured further or are