From 4a6c4ac3a3cebf6557109c90918f71a0dcb70caf Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Tue, 17 Nov 2026 12:19:50 +0400 Subject: [PATCH] services: serve the blog from its flake, beside the container The blog's repository now exports the built site and a module serving it from an nginx virtual host. services runs it on :8081 next to the container on ops; Traefik does not route to it yet. Routes get an optional priority, so the new route can take over from the container's labels (1000) without removing them first. nginx now reloads for a changed virtual host instead of restarting. Assisted-by: Claude:opus-5-5 --- nixos/flake.lock | 22 +++++++++++++++++++ nixos/flake.nix | 11 +++++++++- nixos/hosts/asxpio-ops/traefik.nix | 28 ++++++++++++++++++------- nixos/hosts/asxpio-services/apps.nix | 13 ++++++++++++ nixos/hosts/asxpio-services/default.nix | 1 + 5 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 nixos/hosts/asxpio-services/apps.nix diff --git a/nixos/flake.lock b/nixos/flake.lock index 8ccef71..3979be2 100644 --- a/nixos/flake.lock +++ b/nixos/flake.lock @@ -1,5 +1,26 @@ { "nodes": { + "blog": { + "inputs": { + "nixpkgs": [ + "nixpkgs-unstable" + ] + }, + "locked": { + "lastModified": 1794903473, + "narHash": "sha256-dixOsoH2a1UbhFwQvlGNG2Bg8hvZWn3VIKxnfQAcEI4=", + "ref": "main", + "rev": "f4c1887a42cc190f2d535eb4273f7d3533c8ef16", + "revCount": 23, + "type": "git", + "url": "https://git.asxp.io/asxpi/blog" + }, + "original": { + "ref": "main", + "type": "git", + "url": "https://git.asxp.io/asxpi/blog" + } + }, "comin": { "inputs": { "flake-compat": "flake-compat", @@ -94,6 +115,7 @@ }, "root": { "inputs": { + "blog": "blog", "comin": "comin", "crawler-alert": "crawler-alert", "nixpkgs": "nixpkgs", diff --git a/nixos/flake.nix b/nixos/flake.nix index 0985d69..9c119e9 100644 --- a/nixos/flake.nix +++ b/nixos/flake.nix @@ -15,6 +15,11 @@ inputs.nixpkgs.follows = "nixpkgs"; inputs.treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; }; + # The apps, each from its own repository (hosts/asxpio-services/apps.nix) + blog = { + url = "git+https://git.asxp.io/asxpi/blog?ref=main"; + inputs.nixpkgs.follows = "nixpkgs-unstable"; # only HTML ships + }; # services.crawler-alert (hosts/asxpio-ops/crawler.nix) crawler-alert = { url = "git+https://git.asxp.io/asxpi/traefik-crawlers-statistics?ref=main"; @@ -29,6 +34,7 @@ sops-nix, comin, crawler-alert, + blog, ... }: let @@ -79,7 +85,10 @@ ./hosts/asxpio-ops crawler-alert.nixosModules.default ]; - asxpio-services = mkHost [ ./hosts/asxpio-services ]; + asxpio-services = mkHost [ + ./hosts/asxpio-services + blog.nixosModules.default + ]; }; }; } diff --git a/nixos/hosts/asxpio-ops/traefik.nix b/nixos/hosts/asxpio-ops/traefik.nix index a432c1d..3c3da31 100644 --- a/nixos/hosts/asxpio-ops/traefik.nix +++ b/nixos/hosts/asxpio-ops/traefik.nix @@ -35,6 +35,12 @@ in type = lib.types.listOf lib.types.str; default = [ ]; }; + # Above the app containers' labels (1000) while a service + # takes over from its container + priority = lib.mkOption { + type = lib.types.nullOr lib.types.int; + default = null; + }; }; } ); @@ -43,7 +49,9 @@ in config = { sops.secrets."traefik/letsencrypt_email" = { }; sops.templates."traefik.env".content = '' - TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_EMAIL=${config.sops.placeholder."traefik/letsencrypt_email"} + TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_EMAIL=${ + config.sops.placeholder."traefik/letsencrypt_email" + } ''; services.traefik = { @@ -169,13 +177,17 @@ in tls.certResolver = "letsencrypt"; }; } - // lib.mapAttrs (name: r: { - rule = lib.concatMapStringsSep " || " (h: "Host(`${h}`)") r.hosts; - entryPoints = [ "websecure" ]; - service = name; - inherit (r) middlewares; - tls.certResolver = "letsencrypt"; - }) config.asxpio.routes; + // lib.mapAttrs ( + name: r: + { + rule = lib.concatMapStringsSep " || " (h: "Host(`${h}`)") r.hosts; + entryPoints = [ "websecure" ]; + service = name; + inherit (r) middlewares; + tls.certResolver = "letsencrypt"; + } + // lib.optionalAttrs (r.priority != null) { inherit (r) priority; } + ) config.asxpio.routes; services = { garage-web.loadBalancer.servers = [ { url = "http://127.0.0.1:3902"; } ]; diff --git a/nixos/hosts/asxpio-services/apps.nix b/nixos/hosts/asxpio-services/apps.nix new file mode 100644 index 0000000..6955b6d --- /dev/null +++ b/nixos/hosts/asxpio-services/apps.nix @@ -0,0 +1,13 @@ +# The apps, built from their own repositories' flakes (inputs in +# ../../flake.nix) and served here; Traefik on asxpio-ops routes to them +# over the private network (asxpio.routes there). A release is a bump of +# the app's input in flake.lock. +{ ... }: +{ + # A new or changed virtual host reloads nginx instead of restarting it + services.nginx.enableReload = true; + + services.blog.enable = true; # :8081 + + asxpio.security.ports = [ "tcp/8081/nginx" ]; +} diff --git a/nixos/hosts/asxpio-services/default.nix b/nixos/hosts/asxpio-services/default.nix index 82be0ff..4252d72 100644 --- a/nixos/hosts/asxpio-services/default.nix +++ b/nixos/hosts/asxpio-services/default.nix @@ -3,6 +3,7 @@ { imports = [ ./acme-forward.nix + ./apps.nix ./minecraft.nix ./replica.nix ./runner.nix