3 tv.nginx: allow multiple server blocks

This commit is contained in:
tv 2015-07-16 18:07:20 +02:00
parent 814eae09ff
commit 90eff04849
4 changed files with 42 additions and 39 deletions

View File

@ -32,7 +32,7 @@ with lib;
imports = [ ../../3modules/tv/nginx.nix ]; imports = [ ../../3modules/tv/nginx.nix ];
tv.nginx = { tv.nginx = {
enable = true; enable = true;
retiolum-locations = [ servers.default.locations = [
(nameValuePair "~ ^/~(.+?)(/.*)?\$" '' (nameValuePair "~ ^/~(.+?)(/.*)?\$" ''
alias /home/$1/public_html$2; alias /home/$1/public_html$2;
'') '')

View File

@ -133,7 +133,7 @@ with lib;
imports = [ ../../3modules/tv/nginx.nix ]; imports = [ ../../3modules/tv/nginx.nix ];
tv.nginx = { tv.nginx = {
enable = true; enable = true;
retiolum-locations = [ servers.default.locations = [
(nameValuePair "~ ^/~(.+?)(/.*)?\$" '' (nameValuePair "~ ^/~(.+?)(/.*)?\$" ''
alias /home/$1/public_html$2; alias /home/$1/public_html$2;
'') '')

View File

@ -212,7 +212,7 @@ let
tv.nginx = { tv.nginx = {
enable = true; enable = true;
retiolum-locations = [ servers.default.locations = [
(nameValuePair "/cgit/" '' (nameValuePair "/cgit/" ''
include ${pkgs.nginx}/conf/fastcgi_params; include ${pkgs.nginx}/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi; fastcgi_param SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi;

View File

@ -13,20 +13,26 @@ let
api = { api = {
enable = mkEnableOption "tv.nginx"; enable = mkEnableOption "tv.nginx";
retiolum-locations = mkOption { 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); type = with types; listOf (attrsOf str);
default = []; };
};
default = {};
}; };
}; };
imp = { imp = {
services.nginx = services.nginx = {
let
name = config.tv.retiolum.name;
qname = "${name}.retiolum";
in
assert config.tv.retiolum.enable;
{
enable = true; enable = true;
httpConfig = '' httpConfig = ''
include ${pkgs.nginx}/conf/mime.types; include ${pkgs.nginx}/conf/mime.types;
@ -37,20 +43,9 @@ let
server { server {
listen 80 default_server; listen 80 default_server;
server_name _; server_name _;
location / {
return 404; return 404;
} }
} ${concatStrings (mapAttrsToList (_: to-server) cfg.servers)}
server {
listen 80;
server_name ${name} ${qname};
${indent (concatStrings (map to-location cfg.retiolum-locations))}
location / {
return 404;
}
}
''; '';
}; };
}; };
@ -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 in
out out