3 tv.nginx: allow multiple server blocks
This commit is contained in:
parent
814eae09ff
commit
90eff04849
@ -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;
|
||||
'')
|
||||
|
@ -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;
|
||||
'')
|
||||
|
@ -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;
|
||||
|
@ -13,20 +13,26 @@ let
|
||||
api = {
|
||||
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);
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
|
||||
imp = {
|
||||
services.nginx =
|
||||
let
|
||||
name = config.tv.retiolum.name;
|
||||
qname = "${name}.retiolum";
|
||||
in
|
||||
assert config.tv.retiolum.enable;
|
||||
{
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
httpConfig = ''
|
||||
include ${pkgs.nginx}/conf/mime.types;
|
||||
@ -37,20 +43,9 @@ let
|
||||
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;
|
||||
}
|
||||
}
|
||||
${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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user