From 90eff048495e9cac767644dac1083374ecc521a1 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 16 Jul 2015 18:07:20 +0200 Subject: 3 tv.nginx: allow multiple server blocks --- 3modules/tv/git.nix | 2 +- 3modules/tv/nginx.nix | 75 ++++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 37 deletions(-) (limited to '3modules') diff --git a/3modules/tv/git.nix b/3modules/tv/git.nix index 7170d2ebc..caa53d566 100644 --- a/3modules/tv/git.nix +++ b/3modules/tv/git.nix @@ -212,7 +212,7 @@ let tv.nginx = { enable = true; - retiolum-locations = [ + servers.default.locations = [ (nameValuePair "/cgit/" '' include ${pkgs.nginx}/conf/fastcgi_params; fastcgi_param SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi; 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 -- cgit v1.2.3