summaryrefslogtreecommitdiffstats
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
parent814eae09ff808eaf50cfb377d07fc9acf868ef52 (diff)
3 tv.nginx: allow multiple server blocks
-rw-r--r--1systems/tv/nomic.nix2
-rw-r--r--1systems/tv/wu.nix2
-rw-r--r--3modules/tv/git.nix2
-rw-r--r--3modules/tv/nginx.nix75
4 files changed, 42 insertions, 39 deletions
diff --git a/1systems/tv/nomic.nix b/1systems/tv/nomic.nix
index 1696c509a..b6235297f 100644
--- a/1systems/tv/nomic.nix
+++ b/1systems/tv/nomic.nix
@@ -32,7 +32,7 @@ with lib;
imports = [ ../../3modules/tv/nginx.nix ];
tv.nginx = {
enable = true;
- retiolum-locations = [
+ servers.default.locations = [
(nameValuePair "~ ^/~(.+?)(/.*)?\$" ''
alias /home/$1/public_html$2;
'')
diff --git a/1systems/tv/wu.nix b/1systems/tv/wu.nix
index 572416b33..d64f1bf0b 100644
--- a/1systems/tv/wu.nix
+++ b/1systems/tv/wu.nix
@@ -133,7 +133,7 @@ with lib;
imports = [ ../../3modules/tv/nginx.nix ];
tv.nginx = {
enable = true;
- retiolum-locations = [
+ servers.default.locations = [
(nameValuePair "~ ^/~(.+?)(/.*)?\$" ''
alias /home/$1/public_html$2;
'')
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