From 9290a4e1810dace2a3b31add15c1c48658d5de15 Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Tue, 17 Nov 2026 11:39:03 +0400 Subject: [PATCH] nixos: add comin, hosts pull their configuration from main Each host runs comin, which polls main of this repository every minute, builds nixosConfigurations. on the host and switches to it. A branch testing- on top of main is applied with `test` to that host alone. Prometheus scrapes comin over the private network, and a failing fetch, evaluation, build or switch alerts after 15 minutes. CI still deploys this commit, which starts comin; the CI deploy job and its SSH key go in the next commit, once comin runs on both hosts. Assisted-by: Claude:opus-5-5 --- nixos/flake.lock | 60 +++++++++++++++++++ nixos/flake.nix | 9 +++ .../asxpio-ops/monitoring/alert-rules.yaml | 17 ++++++ nixos/hosts/asxpio-ops/monitoring/default.nix | 4 ++ nixos/modules/comin.nix | 25 ++++++++ 5 files changed, 115 insertions(+) create mode 100644 nixos/modules/comin.nix diff --git a/nixos/flake.lock b/nixos/flake.lock index 4dab583..83498d9 100644 --- a/nixos/flake.lock +++ b/nixos/flake.lock @@ -1,5 +1,44 @@ { "nodes": { + "comin": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": [ + "nixpkgs" + ], + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1784448272, + "narHash": "sha256-zkI/QkILbWpjhBOzF7K/kCVsJfCkBbMO96d5B0abfE4=", + "owner": "nlewo", + "repo": "comin", + "rev": "ed92afc48978fb15a2535ebd5c5f63b3010e3b78", + "type": "github" + }, + "original": { + "owner": "nlewo", + "ref": "v0.14.0", + "repo": "comin", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1765121682, + "narHash": "sha256-4VBOP18BFeiPkyhy9o4ssBNQEvfvv1kXkasAYd0+rrA=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "65f23138d8d09a92e30f1e5c87611b23ef451bf3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1794552581, @@ -34,6 +73,7 @@ }, "root": { "inputs": { + "comin": "comin", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", "sops-nix": "sops-nix" @@ -58,6 +98,26 @@ "repo": "sops-nix", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1770228511, + "narHash": "sha256-wQ6NJSuFqAEmIg2VMnLdCnUc0b7vslUohqqGGD+Fyxk=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "337a4fe074be1042a35086f15481d763b8ddc0e7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/nixos/flake.nix b/nixos/flake.nix index d3dd138..9c1d1b8 100644 --- a/nixos/flake.nix +++ b/nixos/flake.nix @@ -9,6 +9,12 @@ url = "github:Mic92/sops-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + # The deploy agent (modules/comin.nix) + comin = { + url = "github:nlewo/comin/v0.14.0"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = @@ -16,6 +22,7 @@ nixpkgs, nixpkgs-unstable, sops-nix, + comin, ... }: let @@ -26,6 +33,7 @@ specialArgs.unstable = nixpkgs-unstable.legacyPackages.x86_64-linux; modules = [ sops-nix.nixosModules.sops + comin.nixosModules.comin ./modules/hetzner.nix ./modules/base.nix ./modules/shell.nix @@ -33,6 +41,7 @@ ./modules/wireguard.nix ./modules/alert.nix ./modules/backup.nix + ./modules/comin.nix ./modules/monitoring-agent.nix ] ++ modules; diff --git a/nixos/hosts/asxpio-ops/monitoring/alert-rules.yaml b/nixos/hosts/asxpio-ops/monitoring/alert-rules.yaml index 3975bd8..d575b9a 100644 --- a/nixos/hosts/asxpio-ops/monitoring/alert-rules.yaml +++ b/nixos/hosts/asxpio-ops/monitoring/alert-rules.yaml @@ -181,6 +181,23 @@ groups: for: 6h labels: { severity: warning } annotations: { summary: "ejabberd's certificate expires {{ $values.A.Value | printf \"%.0f\" }} days before the one Traefik holds: the push or the reload failed" } + - uid: deploy-failed + title: "Deploy failing" + condition: C + data: + - refId: A + relativeTimeRange: { from: 900, to: 0 } + datasourceUid: prometheus + # comin: fetching main, evaluating, building or switching + model: { refId: A, expr: "max by (host, __name__) ({__name__=~\"comin_last_(fetch|eval|build|deployment)_failed\"})", instant: true, intervalMs: 30000, maxDataPoints: 43200 } + - refId: C + datasourceUid: __expr__ + model: { refId: C, type: threshold, expression: A, conditions: [ { evaluator: { type: gt, params: [0] } } ] } + noDataState: OK + execErrState: Error + for: 15m + labels: { severity: warning } + annotations: { summary: "{{ $labels.host }}: {{ $labels.__name__ }} (comin status on the host)" } - uid: replica-stale title: "Bucket replica stale" condition: C diff --git a/nixos/hosts/asxpio-ops/monitoring/default.nix b/nixos/hosts/asxpio-ops/monitoring/default.nix index 8cf4a04..6c7aac5 100644 --- a/nixos/hosts/asxpio-ops/monitoring/default.nix +++ b/nixos/hosts/asxpio-ops/monitoring/default.nix @@ -128,6 +128,10 @@ in job_name = "alloy"; static_configs = perHost 12345; } + { + job_name = "comin"; + static_configs = perHost 4243; + } { job_name = "traefik"; static_configs = [ diff --git a/nixos/modules/comin.nix b/nixos/modules/comin.nix new file mode 100644 index 0000000..04a290d --- /dev/null +++ b/nixos/modules/comin.nix @@ -0,0 +1,25 @@ +# Deploys: each host pulls main of this repository and switches to +# nixosConfigurations. (comin, polling every minute). CI only +# evaluates. A branch testing- on top of main is applied with +# `test` (not the boot default) to that host alone: try a change there, +# then merge it. `comin status` on the host shows what it is doing. +{ config, ... }: +{ + services.comin = { + enable = true; + remotes = [ + { + name = "origin"; + url = "https://git.asxp.io/asxpi/iac.git"; + } + ]; + repositorySubdir = "nixos"; + # Prometheus on ops scrapes it over the private network + exporter = { + listen_address = config.asxpio.privateIPv4; + port = 4243; + }; + }; + + asxpio.security.ports = [ "tcp/4243/comin" ]; +}