Build the site as a Nix package, with a NixOS module to serve it
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:
parent
bac90e46ec
commit
f4c1887a42
3 changed files with 68 additions and 9 deletions
|
|
@ -26,8 +26,8 @@ jobs:
|
|||
- name: Checkout
|
||||
uses: actions/checkout@v7.0.1
|
||||
|
||||
- name: Build site
|
||||
run: nix develop -c zola build
|
||||
- name: Build site (the package nginx serves)
|
||||
run: nix build .#default
|
||||
|
||||
build:
|
||||
runs-on: arch-latest
|
||||
|
|
|
|||
|
|
@ -24,5 +24,5 @@ jobs:
|
|||
- name: Checkout
|
||||
uses: actions/checkout@v7.0.1
|
||||
|
||||
- name: Build site
|
||||
run: nix develop -c zola build
|
||||
- name: Build site (the package nginx serves)
|
||||
run: nix build .#default
|
||||
|
|
|
|||
69
flake.nix
69
flake.nix
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue