services: serve the blog from its flake, beside the container
All checks were successful
nixos / nixos (push) Successful in 22s

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
This commit is contained in:
Sergei Poljanski 2026-11-17 12:19:50 +04:00
commit 4a6c4ac3a3
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
5 changed files with 66 additions and 9 deletions

22
nixos/flake.lock generated
View file

@ -1,5 +1,26 @@
{ {
"nodes": { "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": { "comin": {
"inputs": { "inputs": {
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
@ -94,6 +115,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"blog": "blog",
"comin": "comin", "comin": "comin",
"crawler-alert": "crawler-alert", "crawler-alert": "crawler-alert",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",

View file

@ -15,6 +15,11 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
inputs.treefmt-nix.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) # services.crawler-alert (hosts/asxpio-ops/crawler.nix)
crawler-alert = { crawler-alert = {
url = "git+https://git.asxp.io/asxpi/traefik-crawlers-statistics?ref=main"; url = "git+https://git.asxp.io/asxpi/traefik-crawlers-statistics?ref=main";
@ -29,6 +34,7 @@
sops-nix, sops-nix,
comin, comin,
crawler-alert, crawler-alert,
blog,
... ...
}: }:
let let
@ -79,7 +85,10 @@
./hosts/asxpio-ops ./hosts/asxpio-ops
crawler-alert.nixosModules.default crawler-alert.nixosModules.default
]; ];
asxpio-services = mkHost [ ./hosts/asxpio-services ]; asxpio-services = mkHost [
./hosts/asxpio-services
blog.nixosModules.default
];
}; };
}; };
} }

View file

@ -35,6 +35,12 @@ in
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
default = [ ]; 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 = { config = {
sops.secrets."traefik/letsencrypt_email" = { }; sops.secrets."traefik/letsencrypt_email" = { };
sops.templates."traefik.env".content = '' 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 = { services.traefik = {
@ -169,13 +177,17 @@ in
tls.certResolver = "letsencrypt"; tls.certResolver = "letsencrypt";
}; };
} }
// lib.mapAttrs (name: r: { // lib.mapAttrs (
rule = lib.concatMapStringsSep " || " (h: "Host(`${h}`)") r.hosts; name: r:
entryPoints = [ "websecure" ]; {
service = name; rule = lib.concatMapStringsSep " || " (h: "Host(`${h}`)") r.hosts;
inherit (r) middlewares; entryPoints = [ "websecure" ];
tls.certResolver = "letsencrypt"; service = name;
}) config.asxpio.routes; inherit (r) middlewares;
tls.certResolver = "letsencrypt";
}
// lib.optionalAttrs (r.priority != null) { inherit (r) priority; }
) config.asxpio.routes;
services = { services = {
garage-web.loadBalancer.servers = [ { url = "http://127.0.0.1:3902"; } ]; garage-web.loadBalancer.servers = [ { url = "http://127.0.0.1:3902"; } ];

View file

@ -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" ];
}

View file

@ -3,6 +3,7 @@
{ {
imports = [ imports = [
./acme-forward.nix ./acme-forward.nix
./apps.nix
./minecraft.nix ./minecraft.nix
./replica.nix ./replica.nix
./runner.nix ./runner.nix