web-redirect: init new service for simple domain redirects

This commit is contained in:
Katherina Walshe-Grey 2025-03-17 02:25:28 +00:00
parent addbf7ac3e
commit 55000c365a
4 changed files with 42 additions and 19 deletions

View file

@ -61,15 +61,10 @@
enable = true; enable = true;
domain = "actual.unspecified.systems"; domain = "actual.unspecified.systems";
}; };
fountain.services.web-redirect = {
services.nginx = {
enable = true; enable = true;
virtualHosts = { domains = {
"actual.qenya.tel" = { "actual.qenya.tel" = "actual.unspecified.systems";
forceSSL = true;
enableACME = true;
locations."/".return = "301 https://actual.unspecified.systems$request_uri";
};
}; };
}; };

View file

@ -40,20 +40,17 @@
enable = true; enable = true;
domain = "git.unspecified.systems"; domain = "git.unspecified.systems";
}; };
fountain.services.web-redirect = {
enable = true;
domains = {
"git.katherina.rocks" = "git.unspecified.systems";
"git.qenya.tel" = "git.unspecified.systems";
};
};
services.nginx = { services.nginx = {
enable = true; enable = true;
virtualHosts = { virtualHosts = {
"git.katherina.rocks" = {
forceSSL = true;
enableACME = true;
locations."/".return = "301 https://git.unspecified.systems$request_uri";
};
"git.qenya.tel" = {
forceSSL = true;
enableACME = true;
locations."/".return = "301 https://git.unspecified.systems$request_uri";
};
"birdsong.network" = { "birdsong.network" = {
forceSSL = true; forceSSL = true;
enableACME = true; enableACME = true;

View file

@ -8,5 +8,6 @@
./navidrome.nix ./navidrome.nix
./pipewire-low-latency.nix ./pipewire-low-latency.nix
./remote-builder.nix ./remote-builder.nix
./web-redirect.nix
]; ];
} }

30
services/web-redirect.nix Normal file
View file

@ -0,0 +1,30 @@
{ config, lib, pkgs, ... }:
let
inherit (lib) mkIf mkOption mkEnableOption types;
cfg = config.fountain.services.web-redirect;
in
{
options.fountain.services.web-redirect = {
enable = mkEnableOption "Module to do simple 301 redirects from one domain to another";
domains = mkOption {
type = types.attrsOf types.str;
description = "Mapping from source domain to destination domain";
};
};
config = mkIf cfg.enable {
services.nginx = {
enable = true;
virtualHosts = builtins.mapAttrs
(name: value: {
forceSSL = true;
enableACME = true;
locations."/".return = "301 https://${value}$request_uri";
})
cfg.domains;
};
networking.firewall.allowedTCPPorts = [ 80 443 ];
};
}