diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-06-06 14:31:16 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-06-06 14:31:24 +0530 |
| commit | 7bcd223aa4537f054eb140c3b5461ee7a4d03b19 (patch) | |
| tree | e79840736e54be4a62f9bad001d8c29875e97c5e /modules/service-router.module.nix | |
| parent | 08d9f9f645080a2b03c608eea6a08fcac8674256 (diff) | |
| download | nixos-config-7bcd223aa4537f054eb140c3b5461ee7a4d03b19.tar.gz nixos-config-7bcd223aa4537f054eb140c3b5461ee7a4d03b19.zip | |
Add sonarr/radarr/prowlarr + add service routing
Diffstat (limited to '')
| -rw-r--r-- | modules/service-router.module.nix | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/modules/service-router.module.nix b/modules/service-router.module.nix new file mode 100644 index 0000000..e1da4fb --- /dev/null +++ b/modules/service-router.module.nix @@ -0,0 +1,34 @@ +{ config, lib, ... }: +with lib; +let + cfg = config.services.service-router; + hostname = name: "${name}.local"; +in { + options.services.service-router = { + enable = mkEnableOption "enable router"; + routes = mkOption { + type = types.attrsOf (types.submodule { options = { + port = mkOption { type = types.int; }; + host = mkOption { type = types.str; default = "127.0.0.1"; }; + protocol = mkOption { type = types.str; default = "http"; }; + }; }); + default = {}; + }; + }; + + config = lib.mkIf cfg.enable { + services.nginx = { + enable = true; + virtualHosts = lib.mapAttrs' (name: val: { + name = hostname name; + value = { + locations."/" = { + proxyPass = "${val.protocol}://${val.host}:${toString val.port}"; + }; + }; + }) cfg.routes; + }; + + networking.hosts."127.0.0.1" = lib.mapAttrsToList (name: _: hostname name) cfg.routes; + }; +} |
