commit 749e09b2d8ecc8e6b8eb4a0abf9723209de19961
parent 7565909e81657fc2b3e50bd4e07b9b730fb563b6
Author: mtmn <miro@haravara.org>
Date: Sun, 3 May 2026 20:35:39 +0200
feat: make static module more dynamic
Diffstat:
4 files changed, 36 insertions(+), 44 deletions(-)
diff --git a/hosts/nixaran/configuration.nix b/hosts/nixaran/configuration.nix
Binary files differ.
diff --git a/hosts/void/overlays/config/shell/rc/void b/hosts/void/overlays/config/shell/rc/void
Binary files differ.
diff --git a/modules/services/napkins.nix b/modules/services/napkins.nix
@@ -1,38 +0,0 @@
-{
- config,
- lib,
- ...
-}: let
- cfg = config.services.haravara.napkins;
-in {
- options.services.haravara.napkins = {
- enable = lib.mkEnableOption "Napkins file server";
- domain = lib.mkOption {
- type = lib.types.str;
- description = "Domain to serve napkins on";
- };
- upstream = lib.mkOption {
- type = lib.types.str;
- default = "https://estri.mtmn.name";
- description = "Upstream host to proxy napkins content from";
- };
- path = lib.mkOption {
- type = lib.types.str;
- default = "/napkins";
- description = "Path prefix on the upstream host";
- };
- };
-
- config = lib.mkIf cfg.enable {
- services.caddy.virtualHosts."${cfg.domain}".extraConfig = ''
- @spa not path_regexp \.[^/]+$
- rewrite @spa ${cfg.path}/index.html
-
- @jsasset path_regexp napkins\.js$
- rewrite @jsasset ${cfg.path}/napkins.js
-
- rewrite * ${cfg.path}{uri}
- reverse_proxy ${cfg.upstream}
- '';
- };
-}
diff --git a/modules/services/static.nix b/modules/services/static.nix
@@ -6,16 +6,18 @@
cfg = config.services.haravara.static;
staticFiles = ../../static;
+
+ localDomains = lib.filterAttrs (_: opt: !opt.s3.enable) cfg.domains;
in {
options.services.haravara.static = {
enable = lib.mkEnableOption "Static site assets deployment";
- # Map of domain name -> directory name under static/
domains = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule {
options = {
dir = lib.mkOption {
type = lib.types.str;
- description = "Directory name in static folder";
+ default = "";
+ description = "Directory name in static folder (not needed when s3.enable = true)";
};
hasRedirect = lib.mkOption {
type = lib.types.bool;
@@ -27,6 +29,18 @@ in {
default = "";
description = "Extra Caddy config appended to the virtual host";
};
+ s3 = {
+ enable = lib.mkEnableOption "Serve from S3 bucket";
+ endpoint = lib.mkOption {
+ type = lib.types.str;
+ description = "S3 upstream host; Caddy rewrites to /<bucket>{uri} and proxies here";
+ };
+ bucket = lib.mkOption {
+ type = lib.types.str;
+ default = "";
+ description = "Bucket name; defaults to the domain name when empty";
+ };
+ };
};
});
};
@@ -40,11 +54,27 @@ in {
(lib.mapAttrsToList (
_: opt: "L+ /var/lib/haravara/static/${opt.dir} - - - - ${staticFiles}/${opt.dir}"
)
- cfg.domains)
+ localDomains)
];
- services.caddy.virtualHosts =
- lib.mapAttrs (domain: opt: {
+ services.caddy.virtualHosts = lib.mapAttrs (domain: opt:
+ if opt.s3.enable
+ then let
+ bucket =
+ if opt.s3.bucket != ""
+ then opt.s3.bucket
+ else domain;
+ in {
+ extraConfig =
+ ''
+ rewrite * /${bucket}{uri}
+ reverse_proxy https://${opt.s3.endpoint} {
+ header_up Host {upstream_hostport}
+ }
+ ''
+ + opt.extraConfig;
+ }
+ else {
extraConfig =
''
handle {
@@ -57,6 +87,6 @@ in {
''
+ opt.extraConfig;
})
- cfg.domains;
+ cfg.domains;
};
}