Build the site as a Nix package, with a NixOS module to serve it
All checks were successful
Test / check (push) Successful in 6s
Build and Deploy to Production / check (push) Successful in 6s
Build and Deploy to Production / build (push) Successful in 9s
Build and Deploy to Production / deploy (push) Successful in 27s

packages.default is the built site; nixosModules.default (services.blog)
serves it from an nginx virtual host on a port, for Traefik to proxy.
The servers will take it from here instead of the container image. CI
now builds the package, so a change that breaks it never reaches main.

The container deploy stays until the NixOS service has taken over.

Assisted-by: Claude:opus-5-5
This commit is contained in:
Sergei Poljanski 2026-11-17 12:17:53 +04:00
commit f4c1887a42
Signed by: asxpi
GPG key ID: 4F8851660FA4121B

View file

@ -5,17 +5,76 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
outputs =
{ self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
inherit (nixpkgs) lib;
in
{
devShells.${system}.default = pkgs.mkShell {
buildInputs = [
pkgs.zola
];
# The built site: the files nginx serves
packages.${system}.default = pkgs.stdenvNoCC.mkDerivation {
pname = "blog";
version = self.shortRev or self.dirtyShortRev or "dev";
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./config.toml
./content
./static
./templates
];
};
nativeBuildInputs = [ pkgs.zola ];
# zola 0.23 builds its HTTP client at start and panics without
# CA certificates, though the site fetches nothing
env.SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
buildPhase = "zola build --output-dir $out";
dontInstall = true;
};
# services.blog: an nginx virtual host serving the site on a port;
# TLS and the public name are the proxy's (Traefik on asxpio-ops)
nixosModules.default =
{ config, lib, ... }:
let
cfg = config.services.blog;
in
{
options.services.blog = {
enable = lib.mkEnableOption "blog.asxp.io";
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${system}.default;
defaultText = lib.literalExpression "the blog flake's package";
};
port = lib.mkOption {
type = lib.types.port;
default = 8081;
};
};
config = lib.mkIf cfg.enable {
services.nginx = {
enable = true;
virtualHosts."blog.asxp.io" = {
listen = [
{
addr = "0.0.0.0";
inherit (cfg) port;
}
];
root = cfg.package;
extraConfig = "error_page 404 /404.html;";
locations."/".tryFiles = "$uri $uri/ =404";
locations."~* \\.(css|png|svg|xml|ico)$".extraConfig = "expires 1h;";
};
};
};
};
devShells.${system}.default = pkgs.mkShell {
buildInputs = [ pkgs.zola ];
shellHook = ''
echo "blog dev shell ready"
echo " zola serve - live-reload preview on http://127.0.0.1:1111"