aboutsummaryrefslogtreecommitdiff
path: root/nixos/shared
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2026-10-17 11:14:02 +0200
committerMartin Fischer <martin@push-f.com>2026-10-18 07:25:43 +0200
commit9237328fb09b2c18365bb5fcef1c4596d77973a9 (patch)
tree55bbfd35140871166a52bbf01bb658c03ca127d6 /nixos/shared
parentf29ddff912ddcd58a4726736702b24655505ce09 (diff)
refactor: make server packages buildable via packages.*
Diffstat (limited to 'nixos/shared')
-rw-r--r--nixos/shared/alloy-nix-config/alloy_nix_config.go129
-rw-r--r--nixos/shared/alloy-nix-config/default.nix8
-rw-r--r--nixos/shared/alloy-nix-config/go.mod3
-rw-r--r--nixos/shared/prometheus-sql-exporter/default.nix18
-rw-r--r--nixos/shared/prometheus-sql-exporter/service.nix39
-rw-r--r--nixos/shared/prometheus-storagebox-exporter/default.nix22
-rw-r--r--nixos/shared/prometheus-storagebox-exporter/service.nix33
7 files changed, 0 insertions, 252 deletions
diff --git a/nixos/shared/alloy-nix-config/alloy_nix_config.go b/nixos/shared/alloy-nix-config/alloy_nix_config.go
deleted file mode 100644
index 4b6eb63..0000000
--- a/nixos/shared/alloy-nix-config/alloy_nix_config.go
+++ /dev/null
@@ -1,129 +0,0 @@
-package main
-
-import (
- "encoding/json"
- "fmt"
- "maps"
- "os"
- "slices"
- "strconv"
- "strings"
-)
-
-func main() {
- if len(os.Args) != 3 {
- fmt.Fprintf(os.Stderr, "usage: %s <json_path> <out_path>\n", os.Args[0])
- os.Exit(1)
- }
-
- jsonPath := os.Args[1]
- outPath := os.Args[2]
-
- jsonData, err := os.ReadFile(jsonPath)
- if err != nil {
- fmt.Fprintf(os.Stderr, "error reading file %s: %v\n", jsonPath, err)
- os.Exit(1)
- }
-
- // It would be nice to preserve the order of blocks ... except that we can't
- // because Nix already doesn't preserve the order of attribute sets.
- var config map[string]any
- if err := json.Unmarshal(jsonData, &config); err != nil {
- fmt.Fprintf(os.Stderr, "error parsing JSON: %v\n", err)
- os.Exit(1)
- }
-
- result := formatConfig(config)
-
- if err := os.WriteFile(outPath, []byte(result), 0644); err != nil {
- fmt.Fprintf(os.Stderr, "error writing file %s: %v\n", outPath, err)
- os.Exit(1)
- }
-}
-
-func formatConfig(config map[string]any) string {
- var s strings.Builder
-
- for _, blockName := range slices.Sorted(maps.Keys(config)) {
- labels := config[blockName]
-
- if labelsMap, ok := labels.(map[string]any); ok {
- for label, block := range labelsMap {
- if blockMap, ok := block.(map[string]any); ok {
- s.WriteString(formatBlock(blockName, label, blockMap, 0))
- }
- }
- }
- }
-
- return s.String()
-}
-
-func formatBlock(blockName string, label string, block map[string]any, indent int) string {
- var s strings.Builder
-
- s.WriteString(strings.Repeat(" ", indent))
- s.WriteString(blockName)
- if label != "" {
- s.WriteString(fmt.Sprintf(` %s`, strconv.Quote(label)))
- }
- s.WriteString(" {\n")
-
- var blocks []any
- if blocksValue, exists := block["blocks"]; exists {
- if blocksList, ok := blocksValue.([]any); ok {
- blocks = blocksList
- }
- delete(block, "blocks")
- }
-
- for _, key := range slices.Sorted(maps.Keys(block)) {
- s.WriteString(strings.Repeat(" ", indent+1))
- s.WriteString(fmt.Sprintf("%s = %s\n", key, formatValue(block[key])))
- }
-
- for _, blockItem := range blocks {
- if blockMap, ok := blockItem.(map[string]any); ok {
- var name string
- if nameValue, exists := blockMap["name"]; exists {
- if nameStr, ok := nameValue.(string); ok {
- name = nameStr
- }
- delete(blockMap, "name")
- }
-
- s.WriteString(formatBlock(name, "", blockMap, indent+1))
- }
- }
-
- s.WriteString(strings.Repeat(" ", indent))
- s.WriteString("}\n")
-
- return s.String()
-}
-
-func formatValue(value any) string {
- switch v := value.(type) {
- case string:
- return strconv.Quote(v)
- case map[string]any:
- if ref, exists := v["$ref"]; exists {
- if refStr, ok := ref.(string); ok {
- return refStr
- }
- }
- var parts []string
- for _, name := range slices.Sorted(maps.Keys(v)) {
- parts = append(parts, fmt.Sprintf("%s=%s,", name, formatValue(v[name])))
- }
- return "{" + strings.Join(parts, " ") + "}"
- case []any:
- var parts []string
- for _, item := range v {
- parts = append(parts, formatValue(item))
- }
- return "[" + strings.Join(parts, ", ") + "]"
- default:
- return fmt.Sprintf("%v", v)
- }
-}
diff --git a/nixos/shared/alloy-nix-config/default.nix b/nixos/shared/alloy-nix-config/default.nix
deleted file mode 100644
index d4efe02..0000000
--- a/nixos/shared/alloy-nix-config/default.nix
+++ /dev/null
@@ -1,8 +0,0 @@
-{ pkgs ? import <nixpkgs> {} }:
-
-pkgs.buildGoModule {
- pname = "alloy-nix-config";
- version = "git";
- src = ./.;
- vendorHash = null;
-}
diff --git a/nixos/shared/alloy-nix-config/go.mod b/nixos/shared/alloy-nix-config/go.mod
deleted file mode 100644
index 2916089..0000000
--- a/nixos/shared/alloy-nix-config/go.mod
+++ /dev/null
@@ -1,3 +0,0 @@
-module push-f.com/alloy-nix-config
-
-go 1.24.5
diff --git a/nixos/shared/prometheus-sql-exporter/default.nix b/nixos/shared/prometheus-sql-exporter/default.nix
deleted file mode 100644
index e049396..0000000
--- a/nixos/shared/prometheus-sql-exporter/default.nix
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- lib,
- buildGoModule,
- sources,
-}:
-buildGoModule {
- pname = "sql_exporter";
- version = sources.prometheus-sql-exporter.version;
- src = sources.prometheus-sql-exporter;
- vendorHash = "sha256-eZxxmqoiXPdjZs/lwbzvWco9mDFy0zmpGDcqTIyWbK4=";
-
- meta = with lib; {
- description = "Database-agnostic SQL exporter for Prometheus";
- mainProgram = "sql_exporter";
- homepage = "https://github.com/burningalchemist/sql_exporter";
- license = licenses.mit;
- };
-}
diff --git a/nixos/shared/prometheus-sql-exporter/service.nix b/nixos/shared/prometheus-sql-exporter/service.nix
deleted file mode 100644
index 3bbf5c2..0000000
--- a/nixos/shared/prometheus-sql-exporter/service.nix
+++ /dev/null
@@ -1,39 +0,0 @@
-# TODO: submit burningalchemist's sql_exporter to nixpkgs
-{ config, lib, pkgs, sources, ... }:
-
-let
- sqlExporter = pkgs.callPackage ./default.nix { inherit sources; };
- cfg = config.services.prometheus-sql-exporter;
- configFile = builtins.toFile "config.yaml" (builtins.toJSON cfg.config);
- validateConfig = file:
- pkgs.runCommand "validate-config"
- {
- nativeBuildInputs = [sqlExporter];
- }
- ''
- sql_exporter -config.check -config.file "${file}"
- ln -s "${file}" "$out"
- '';
-in
-{
- options.services.prometheus-sql-exporter = {
- enable = lib.mkEnableOption "sql-exporter";
- port = lib.mkOption {
- type = lib.types.int;
- };
- config = lib.mkOption {
- type = (pkgs.formats.json {}).type;
- };
- };
-
- config = lib.mkIf cfg.enable {
- systemd.services.prometheus-sql-exporter = {
- serviceConfig = {
- ExecStart = "${sqlExporter}/bin/sql_exporter -config.file ${validateConfig configFile} -web.listen-address :${toString cfg.port}";
- DynamicUser = "true";
- User = "prometheus-sql-exporter";
- };
- wantedBy = ["multi-user.target"];
- };
- };
-}
diff --git a/nixos/shared/prometheus-storagebox-exporter/default.nix b/nixos/shared/prometheus-storagebox-exporter/default.nix
deleted file mode 100644
index d4fd13e..0000000
--- a/nixos/shared/prometheus-storagebox-exporter/default.nix
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- lib,
- buildGoModule,
- sources,
-}:
-buildGoModule {
- pname = "storagebox_exporter";
- version = sources.prometheus-storagebox-exporter.version;
- src = sources.prometheus-storagebox-exporter;
- vendorHash = "sha256-3aBklYmPHELcLG+3sOEDd9qkrJyDrC52LfhOOY/6sOc=";
-
- meta = with lib; {
- description = "Modern Prometheus exporter for Hetzner Storage Box with comprehensive metrics";
- mainProgram = "prometheus-storagebox-exporter";
- homepage = "https://github.com/crstian19/prometheus-storagebox-exporter";
- license = licenses.mit;
- };
-
- postPatch = ''
- substituteInPlace go.mod --replace 'go 1.25.5' 'go 1.25.4'
- '';
-}
diff --git a/nixos/shared/prometheus-storagebox-exporter/service.nix b/nixos/shared/prometheus-storagebox-exporter/service.nix
deleted file mode 100644
index 1d3cff5..0000000
--- a/nixos/shared/prometheus-storagebox-exporter/service.nix
+++ /dev/null
@@ -1,33 +0,0 @@
-# TODO: submit Christian's storagebox exporter to nixpkgs
-{ config, lib, pkgs, sources, ... }:
-
-let
- storageboxExporter = pkgs.callPackage ./default.nix { inherit sources; };
- cfg = config.services.prometheus-storagebox-exporter;
-in
-{
- options.services.prometheus-storagebox-exporter = {
- enable = lib.mkEnableOption "storagebox-exporter";
- port = lib.mkOption {
- type = lib.types.int;
- };
- hetznerTokenFile = lib.mkOption {
- type = lib.types.path;
- };
- };
-
- config = lib.mkIf cfg.enable {
- systemd.services.storagebox-exporter = {
- serviceConfig = {
- ExecStart = "${storageboxExporter}/bin/prometheus-storagebox-exporter";
- DynamicUser = "true";
- LoadCredential = "hetznerToken:${cfg.hetznerTokenFile}";
- };
- environment = {
- HETZNER_TOKEN_FILE = "%d/hetznerToken";
- LISTEN_ADDRESS = ":${toString cfg.port}";
- };
- wantedBy = ["multi-user.target"];
- };
- };
-}