diff --git a/nixos/access/mpd.nix b/nixos/access/mpd.nix new file mode 100644 index 00000000..2ef154e9 --- /dev/null +++ b/nixos/access/mpd.nix @@ -0,0 +1,73 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkDefault; + name.shortServer = mkDefault "radio"; + upstreamName = "radio'access"; + upstreamHigh = "${upstreamName}'high"; + upstreamLow = "${upstreamName}'low"; +in { + config.services.nginx = { + upstreams' = { + ${upstreamHigh} = { + servers.service = { + #accessService.system = "shanghai"; + addr = "shanghai.local.cutie.moe"; + port = 32101; + }; + }; + ${upstreamLow} = { + servers.service = { + #accessService.system = "shanghai"; + addr = "shanghai.local.cutie.moe"; + port = 32102; + }; + }; + }; + virtualHosts = let + copyFromVhost = mkDefault "mpd"; + extraConfig = '' + proxy_buffering off; + ''; + locations = { + "/low" = { + inherit extraConfig; + proxy = { + enable = true; + upstream = mkDefault upstreamLow; + }; + }; + "/high" = { + inherit extraConfig; + proxy = { + enable = true; + upstream = mkDefault upstreamHigh; + }; + }; + "/" = { + extraConfig = '' + rewrite ^.*$ /high last; + return 404; + ''; + }; + }; + in { + mpd = { + inherit name locations; + proxy.upstream = mkDefault upstreamName; + }; + mpd'local = { + inherit name locations; + ssl.cert = { + inherit copyFromVhost; + }; + proxy = { + inherit copyFromVhost; + }; + local.enable = mkDefault true; + }; + }; + }; +} diff --git a/systems/hakurei/nixos.nix b/systems/hakurei/nixos.nix index 28498930..3d733243 100644 --- a/systems/hakurei/nixos.nix +++ b/systems/hakurei/nixos.nix @@ -43,6 +43,7 @@ in { nixos.access.loki nixos.access.kitchencam nixos.access.moonraker + nixos.access.mpd nixos.access.openwebrx nixos.access.deluge nixos.access.home-assistant @@ -268,6 +269,14 @@ in { virtualHosts.moonraker'local.allServerNames ]; }; + radio = { + inherit (nginx) group; + domain = virtualHosts.mpd.serverName; + extraDomainNames = mkMerge [ + virtualHosts.mpd.otherServerNames + virtualHosts.mpd'local.allServerNames + ]; + }; webrx = { inherit (nginx) group; domain = virtualHosts.openwebrx.serverName; @@ -400,6 +409,7 @@ in { kitchencam.ssl.cert.enable = true; moonraker.ssl.cert.enable = true; openwebrx.ssl.cert.enable = true; + mpd.ssl.cert.enable = true; deluge.ssl.cert.enable = true; invidious = { ssl.cert.enable = true; diff --git a/tf/cloudflare_records.tf b/tf/cloudflare_records.tf index 6cbb903d..41aff54a 100644 --- a/tf/cloudflare_records.tf +++ b/tf/cloudflare_records.tf @@ -29,6 +29,7 @@ module "hakurei_system_records" { "mqtt", "kitchen", "print", + "radio", "webrx", "deluge", "home", @@ -48,6 +49,7 @@ module "hakurei_system_records" { "mqtt", "kitchen", "print", + "radio", "webrx", "syncplay", "yt",