diff options
Diffstat (limited to '3modules/tv/nginx.nix')
-rw-r--r-- | 3modules/tv/nginx.nix | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/3modules/tv/nginx.nix b/3modules/tv/nginx.nix index 93cd88aac..dfb4d6947 100644 --- a/3modules/tv/nginx.nix +++ b/3modules/tv/nginx.nix @@ -13,46 +13,41 @@ let api = { enable = mkEnableOption "tv.nginx"; - retiolum-locations = mkOption { - type = with types; listOf (attrsOf str); - default = []; + servers = mkOption { + type = with types; attrsOf optionSet; + options = singleton { + server-names = mkOption { + type = with types; listOf str; + default = [ + "${config.networking.hostName}" + "${config.networking.hostName}.retiolum" + ]; + }; + locations = mkOption { + type = with types; listOf (attrsOf str); + }; + }; + default = {}; }; }; imp = { - services.nginx = - let - name = config.tv.retiolum.name; - qname = "${name}.retiolum"; - in - assert config.tv.retiolum.enable; - { - enable = true; - httpConfig = '' - include ${pkgs.nginx}/conf/mime.types; - default_type application/octet-stream; - sendfile on; - keepalive_timeout 65; - gzip on; - server { - listen 80 default_server; - server_name _; - location / { - return 404; - } - } - server { - listen 80; - server_name ${name} ${qname}; - - ${indent (concatStrings (map to-location cfg.retiolum-locations))} - - location / { - return 404; - } - } - ''; - }; + services.nginx = { + enable = true; + httpConfig = '' + include ${pkgs.nginx}/conf/mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + gzip on; + server { + listen 80 default_server; + server_name _; + return 404; + } + ${concatStrings (mapAttrsToList (_: to-server) cfg.servers)} + ''; + }; }; @@ -64,6 +59,14 @@ let } ''; + to-server = { server-names, locations, ... }: '' + server { + listen 80; + server_name ${toString server-names}; + ${indent (concatStrings (map to-location locations))} + } + ''; + in out |