From 7892912f4d6297be9ad6a37c5405d151a2e3219c Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Mon, 11 Nov 2024 15:13:16 -0500 Subject: [PATCH] container exporters --- bin/skyg | 2 +- hosts/hl-bigbox1.nix | 17 ++++++++++------- hosts/hl-minipc1.nix | 9 ++------- hosts/hl-minipc2.nix | 3 +++ hosts/hl-terra1.nix | 2 ++ modules/nixos/common/containers/default.nix | 19 +++++++++++-------- modules/nixos/common/containers/docker.nix | 10 ++++++++++ modules/nixos/common/networking.nix | 7 ++----- modules/nixos/common/ssh-server.nix | 10 ++++------ modules/nixos/server/exporters.nix | 5 ++--- 10 files changed, 47 insertions(+), 37 deletions(-) diff --git a/bin/skyg b/bin/skyg index e90034c..a5518c7 100755 --- a/bin/skyg +++ b/bin/skyg @@ -129,7 +129,7 @@ all_functions=$(list_run_functions) for f in ${all_functions[@]}; do if [ "$1" == "$f" ]; then echo -e "Running ${BLUE_BOLD}$1${NC}" - run-$1 ${@:2} 2>&1 | sed "s/^/\t│ /" + run-$1 ${@:2} ecode=$(echo $?) echo -e "\t└──${NC}DONE ${BLUE_BOLD}$1${NC}" exit $ecode diff --git a/hosts/hl-bigbox1.nix b/hosts/hl-bigbox1.nix index 5dfb0fd..cb3b539 100644 --- a/hosts/hl-bigbox1.nix +++ b/hosts/hl-bigbox1.nix @@ -1,4 +1,4 @@ -{}: +{ user }: { pkgs, config, ... }: { imports = [ ./hl-bigbox1.hardware-configuration.nix ]; @@ -8,9 +8,12 @@ skyg.nixos.server.services.jellyfin.enable = true; skyg.nixos.desktop.kde.enabled = true; skyg.nixos.desktop.enabled = false; - skyg.server.admin.enable = true; - users.users.ari.extraGroups = [ "input" ]; - # firmware updater + skyg.server.admin.enable = true; + skyg.server.exporters.enable = true; + skyg.nixos.common.containers.openMetricsPort = true; + + users.users.ari.extraGroups = [ "input" ]; + # firmware updater services.fwupd.enable = true; virtualisation.docker.enableNvidia = true; hardware.nvidia-container-toolkit.enable = true; @@ -64,8 +67,8 @@ steam-run steamPackages.steamcmd ollama -pkgs.jellyfin - pkgs.jellyfin-web - pkgs.jellyfin-ffmpeg + jellyfin + jellyfin-web + jellyfin-ffmpeg ]; } diff --git a/hosts/hl-minipc1.nix b/hosts/hl-minipc1.nix index 5553c70..b4e794f 100644 --- a/hosts/hl-minipc1.nix +++ b/hosts/hl-minipc1.nix @@ -13,6 +13,8 @@ in skyg.user.enable = true; skyg.nixos.common.ssh-server.enable = true; skyg.server.admin.enable = true; + skyg.server.exporters.enable = true; + skyg.nixos.common.containers.openMetricsPort = true; # Nix Stores services.nix-serve = { @@ -52,12 +54,5 @@ in # Firewall networking.firewall.allowedUDPPorts = openPorts; networking.firewall.allowedTCPPorts = openPorts; - # K8s - services.kubernetes.kubelet.hostname = "minipc1.lab.internal"; - skyg.nixos.server.k8s = { - enable = true; - isMaster = true; - isNode = true; - }; } diff --git a/hosts/hl-minipc2.nix b/hosts/hl-minipc2.nix index f79bee9..2afa199 100644 --- a/hosts/hl-minipc2.nix +++ b/hosts/hl-minipc2.nix @@ -4,6 +4,9 @@ imports = [ ./hl-minipc2.hardware-configuration.nix ]; skyg.user.enable = true; skyg.nixos.common.ssh-server.enable = true; + skyg.server.exporters.enable = true; + skyg.nixos.common.containers.openMetricsPort = true; + # firmware updater services.fwupd.enable = true; # Bootloader. diff --git a/hosts/hl-terra1.nix b/hosts/hl-terra1.nix index e76037c..63cb598 100644 --- a/hosts/hl-terra1.nix +++ b/hosts/hl-terra1.nix @@ -20,6 +20,8 @@ in skyg.user.enable = true; skyg.nixos.common.ssh-server.enable = true; skyg.server.admin.enable = true; + skyg.server.exporters.enable = true; + # firmware updater services.fwupd.enable = true; # Bootloader. diff --git a/modules/nixos/common/containers/default.nix b/modules/nixos/common/containers/default.nix index 14e9b17..1748c0f 100644 --- a/modules/nixos/common/containers/default.nix +++ b/modules/nixos/common/containers/default.nix @@ -1,7 +1,5 @@ { lib, ... }: -with lib; - { imports = [ ./docker.nix @@ -9,18 +7,23 @@ with lib; ]; options = { skyg.nixos.common.containers = { - runtime = mkOption { + runtime = lib.mkOption { description = "Docker vs podman"; - type = types.str; + type = lib.types.str; default = "docker"; }; - enableOnBoot = mkOption { - type = types.bool; + enableOnBoot = lib.mkOption { + type = lib.types.bool; default = false; }; - localDockerRegistries = mkOption { - type = types.listOf types.str; + localDockerRegistries = lib.mkOption { + type = lib.types.listOf lib.types.str; }; + metricsPort = lib.mkOption { + type = lib.types.number; + default = 9323; + }; + openMetricsPort = lib.mkEnableOption "Open container metrics port"; }; }; } diff --git a/modules/nixos/common/containers/docker.nix b/modules/nixos/common/containers/docker.nix index 1f17e08..4e001b3 100644 --- a/modules/nixos/common/containers/docker.nix +++ b/modules/nixos/common/containers/docker.nix @@ -12,10 +12,20 @@ in liveRestore = false; daemon.settings = { insecure-registries = cfg.localDockerRegistries; + metrics-addr = "127.0.0.1:${toString cfg.metricsPort}"; }; }; environment.systemPackages = with pkgs; [ docker-compose ]; users.users.${config.skyg.user.name}.extraGroups = [ "docker" ]; virtualisation.oci-containers.backend = "docker"; + networking.firewall.allowedUDPPorts = + (if cfg.openMetricsPort then [ + cfg.metricsPort + ] else [ ]); + networking.firewall.allowedTCPPorts = + (if cfg.openMetricsPort then [ + cfg.metricsPort + ] else [ ]); + }; } diff --git a/modules/nixos/common/networking.nix b/modules/nixos/common/networking.nix index f3b928a..eebf529 100644 --- a/modules/nixos/common/networking.nix +++ b/modules/nixos/common/networking.nix @@ -1,16 +1,13 @@ { config, lib, ... }: - -with lib; - let cfg = config.skyg.core; in { options = { skyg.core = { - hostName = mkOption { + hostName = lib.mkOption { description = "Machine Hostname"; - type = types.str; + type = lib.types.str; }; }; }; diff --git a/modules/nixos/common/ssh-server.nix b/modules/nixos/common/ssh-server.nix index 24653e1..881f4b1 100644 --- a/modules/nixos/common/ssh-server.nix +++ b/modules/nixos/common/ssh-server.nix @@ -1,21 +1,19 @@ { config, lib, ... }: -with lib; - let cfg = config.skyg.nixos.common.ssh-server; in { options = { skyg.nixos.common.ssh-server = { - enable = mkEnableOption + enable = lib.mkEnableOption "enable ssh server"; - masterPubKey = mkOption { - type = types.str; + masterPubKey = lib.mkOption { + type = lib.types.str; default = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCuatskL9qXvgvS3E8zRwosFnpcN0f8PkKl8syAvpn297V2iPk6mi8yK3EE7xPpxaKKlwUuBHDj3BNUCoLgdRFKUgroRDzr3BMm+gZTHy6CuEZBY9zBRTmH+aOV6FZ96QPW4zba0BW5YPkPNy/FhYibjpXyZ3nX4/LWSbPKQJ7wTnUJZgq4VFmevBOttvhzUJUgTziMFsGXn6I38fAi6LI8qwI+zOOdsNjtKgr/TIlO/7VqcH7GYnQEwlthl577sDd1V6+XWz649qoiBYyq0Ahm09dwYx2iGQwLo8IYFbSy4aJRK/PI0+ytnPBoF5QCl+ILb5E8uV3e6Wb9WpXl9Hv2iLx91/9iq5hykHPnfVtkq3MK0C2vqkvX1qFOIkKM7vmxvXGbaDZDGK3G+/zkQ7GUw8ydbl9wGwE9cKbm9miqs4w2Ry/+3IZasE6G2TI97bSzSYInQd2RwoglqBOaJojbUqgI9wvNdKxGhADNFbZah2+s6SSe1ByQRN3b9wtmqu0= ari@shared"; }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { services.openssh = { enable = true; openFirewall = true; diff --git a/modules/nixos/server/exporters.nix b/modules/nixos/server/exporters.nix index 18ead42..26389e0 100644 --- a/modules/nixos/server/exporters.nix +++ b/modules/nixos/server/exporters.nix @@ -1,14 +1,13 @@ { config, lib, ... }: -with lib; let cfg = config.skyg.server.exporters; in { options = { skyg.server.exporters = { - enable = mkEnableOption + enable = lib.mkEnableOption "Enable Special prom exporters for servers"; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { services.prometheus.exporters = { node = { enable = true;