summaryrefslogtreecommitdiffstats
path: root/3modules/tv
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-07-16 18:07:20 +0200
committertv <tv@shackspace.de>2015-07-16 18:07:20 +0200
commit90eff048495e9cac767644dac1083374ecc521a1 (patch)
treed02728d5f8cda4b77921e8becc1ee3b841458dad /3modules/tv
parent814eae09ff808eaf50cfb377d07fc9acf868ef52 (diff)
3 tv.nginx: allow multiple server blocks
Diffstat (limited to '3modules/tv')
-rw-r--r--3modules/tv/git.nix2
-rw-r--r--3modules/tv/nginx.nix75
2 files changed, 40 insertions, 37 deletions
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