tools/nginx: init

This commit is contained in:
Max Headroom 2021-10-16 17:03:53 +02:00
parent ec023a1744
commit 12fff68eef
2 changed files with 49 additions and 0 deletions

View file

@ -3,6 +3,7 @@ let toolsets = {
identity = import ./identity.nix { inherit toolsets; };
networks = import ./networks.nix { inherit toolsets; };
nginx = import ./nginx.nix { inherit toolsets; };
};
in toolsets // {
all = args: (builtins.mapAttrs (_: x: x args) toolsets) // { inherit (toolsets) meta; };

48
tools/nginx.nix Normal file
View file

@ -0,0 +1,48 @@
# internal interface
{ toolsets }:
# external interface
{ config ? null, lib ? null, domain ? toolsets.meta.domain, ... }:
let
tools = (self: {
inherit domain;
mappers = {
mapSubdomains = with lib; mapAttrs' (k: v: nameValuePair "${k}.${domain}" v);
};
vhosts = with self.vhosts; {
basic = {
forceSSL = true;
enableACME = true;
};
redirect = target: basic // {
locations."/".return = "301 ${target}";
};
proxy = target: basic // {
locations."/".proxyPass = target;
};
static = root: basic // {
inherit root;
};
indexedStatic = root: (static root) // {
extraConfig = "autoindex on;";
};
simplePHP = root: (static root) // {
locations."~ \.php$".extraConfig = ''
fastcgi_pass unix:${config.services.phpfpm.pools.www.socket};
fastcgi_index index.php;
'';
};
};
}) tools;
in tools