[goatcounter] Fixes instance for blazestar.net

This commit is contained in:
2025-07-14 15:14:13 -07:00
parent 638f34c2d3
commit 8791432964
3 changed files with 173 additions and 36 deletions

View File

@@ -0,0 +1,126 @@
{ config, lib, ... }:
{
options =
with lib;
with types;
{
virtualisation.web-containers = {
enable = mkEnableOption "web containers";
containers = mkOption {
type = lazyAttrsOf (submodule {
options =
let
strOpt = mkOption { type = str; };
intOpt = mkOption { type = int; };
boolOpt = mkOption {
type = bool;
default = false;
};
strList = mkOption {
type = listOf str;
default = [ ];
};
attrOpt = mkOption {
type = attrsOf str;
default = { };
};
in
{
image = strOpt;
hostname = strOpt;
port = intOpt;
homepageOpts = attrOpt;
dependsOn = strList;
domain = strOpt;
volumes = strList;
environment = attrOpt;
environmentFiles = strList;
public = boolOpt;
user = mkOption {
type = nullOr str;
default = null;
};
extraOptions = strList;
oauthProxy = boolOpt;
extraLabels = attrOpt;
};
});
default = { };
description = "";
};
};
};
config = {
virtualisation.oci-containers.containers = lib.mkIf config.virtualisation.web-containers.enable (
let
hostRule = host: domain: "Host(`${host}.${domain}`)";
localNet = "192.168.0.0/16";
dockerNet = "10.88.0.0/16";
localNetRule = "(ClientIP(`${localNet}`) || ClientIP(`${dockerNet}`))";
localHostRule = host: domain: "${localNetRule} && ${hostRule host domain}";
mkContainer =
key:
{
image,
hostname,
port,
homepageOpts,
dependsOn,
domain,
volumes,
environment,
environmentFiles,
public,
user,
extraOptions,
oauthProxy,
extraLabels,
}:
let
fqn = "${hostname}.${domain}";
serviceName = lib.strings.replaceChars [ "." ] [ "-" ] fqn;
routerRule = if public then hostRule hostname domain else localHostRule hostname domain;
homepageLabels =
if homepageOpts == { } then
{ }
else
{
"homepage.group" = "${homepageOpts.group}";
"homepage.name" = "${homepageOpts.name}";
"homepage.icon" = "${homepageOpts.icon}";
"homepage.href" = "https://${fqn}";
"homepage.description" = "${homepageOpts.description}";
};
oauthLabels =
if oauthProxy then
{ "traefik.http.routers.${serviceName}.middlewares" = "oidc-auth@file"; }
else
{ };
in
{
inherit
image
dependsOn
volumes
environment
environmentFiles
user
extraOptions
;
autoStart = true;
labels =
{
"traefik.enable" = "true";
"traefik.http.routers.${serviceName}.rule" = "${routerRule}";
"traefik.http.services.${serviceName}.loadbalancer.server.port" = "${toString port}";
}
// oauthLabels
// homepageLabels
// extraLabels;
};
in
builtins.mapAttrs mkContainer config.virtualisation.web-containers.containers
);
};
}

View File

@@ -81,7 +81,7 @@ in
port = 8080; port = 8080;
volumes = [ volumes = [
"/tank/web/dm.terakoda.com/pb_data:/pb/pb_data" "/tank/web/dm.terakoda.com/pb_data:/pb/pb_data"
"/tank/web/dm.terakoda.com/pb_migrniations:/pb/pb_migrations:ro" "/tank/web/dm.terakoda.com/pb_migrations:/pb/pb_migrations:ro"
]; ];
environment = { }; environment = { };
extraLabels = { extraLabels = {

View File

@@ -1,47 +1,58 @@
{ config, ... }: { config, ... }:
let let
inherit (import ./lib.nix config) inherit (import ./lib.nix config)
mkContainer
terakoda terakoda
blazestar blazestar
hostRule hostRule
; ;
in in
{ {
virtualisation.oci-containers.containers.goatcounter-terakoda = mkContainer { imports = [
image = "arp242/goatcounter"; ../../../features/web-containers.nix
hostName = "goatcounter"; ];
domain = terakoda;
public = true; virtualisation.web-containers = {
port = 8080; enable = true;
volumes = [ containers = {
"goatcounter-data:/home/goatcounter/goatcounter-data" goatcounter-terakoda = {
]; image = "arp242/goatcounter";
extraLabels = { hostname = "goatcounter";
# "traefik.http.middlewares.strip-analytics.stripprefix.prefixes" = "/analytics"; domain = terakoda;
# "traefik.http.routers.www-terakoda-com-goatcounter.middlewares" = "strip-analytics"; public = true;
# Host the script on www.terakoda.com so that it is easy to fetch port = 8080;
"traefik.http.routers.www-terakoda-com-goatcounter.rule" = volumes = [
"PathPrefix(`/count`) && ${hostRule "www" terakoda}"; "goatcounter-data:/home/goatcounter/goatcounter-data"
"traefik.http.routers.www-terakoda-com-goatcounter.service" = "goatcounter"; ];
}; extraLabels = {
}; # "traefik.http.middlewares.strip-analytics.stripprefix.prefixes" = "/analytics";
virtualisation.oci-containers.containers.goatcounter-blazestar = mkContainer { # "traefik.http.routers.www-terakoda-com-goatcounter.middlewares" = "strip-analytics";
image = "arp242/goatcounter"; # Host the script on www.terakoda.com so that it is easy to fetch
hostName = "goatcounter"; "traefik.http.routers.www-terakoda-com-goatcounter.rule" =
domain = blazestar; "PathPrefix(`/count`) && ${hostRule "www" terakoda}";
public = true; "traefik.http.routers.www-terakoda-com-goatcounter.entrypoints" = "websecure";
port = 8080; "traefik.http.routers.www-terakoda-com-goatcounter.service" = "goatcounter-terakoda-com";
volumes = [ };
"goatcounter-data:/home/goatcounter/goatcounter-data" };
];
extraLabels = { goatcounter-blazestar = {
# "traefik.http.middlewares.strip-analytics.stripprefix.prefixes" = "/analytics"; image = "arp242/goatcounter";
# "traefik.http.routers.www-blazestar-net-goatcounter.middlewares" = "strip-analytics"; hostname = "goatcounter";
# Host the script on www.blazestar.net so that it is easy to fetch domain = blazestar;
"traefik.http.routers.www-blazestar-net-goatcounter.rule" = public = true;
"PathPrefix(`/count`) && ${hostRule "www" blazestar}"; port = 8080;
"traefik.http.routers.www-blazestar-net-goatcounter.service" = "goatcounter"; volumes = [
"goatcounter-data-blazestar:/home/goatcounter/goatcounter-data"
];
extraLabels = {
# "traefik.http.middlewares.strip-analytics.stripprefix.prefixes" = "/analytics";
# "traefik.http.routers.www-blazestar-net-goatcounter.middlewares" = "strip-analytics";
# Host the script on www.blazestar.net so that it is easy to fetch
"traefik.http.routers.www-blazestar-net-goatcounter.rule" =
"PathPrefix(`/count`) && ${hostRule "www" blazestar}";
"traefik.http.routers.www-blazestar-net-goatcounter.entrypoints" = "websecure";
"traefik.http.routers.www-blazestar-net-goatcounter.service" = "goatcounter-blazestar-net@docker";
};
};
}; };
}; };
} }