create nginx magic module
This commit is contained in:
parent
1894b8c5e8
commit
a774b1cd2b
12 changed files with 111 additions and 64 deletions
|
@ -1,3 +1,3 @@
|
|||
{ ... }: {
|
||||
imports = [ ./meta.nix ./dns.nix ./flood.nix ./gnome ./unpackerr.nix ./vault.nix ];
|
||||
imports = [ ./meta.nix ./nginx.nix ./dns.nix ./flood.nix ./gnome ./unpackerr.nix ./vault.nix ];
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ let
|
|||
};
|
||||
port = mkOption {
|
||||
type = types.int;
|
||||
default = 80;
|
||||
example = 4242;
|
||||
description = ''
|
||||
The port under which the service runs on the host
|
||||
|
@ -21,6 +22,7 @@ let
|
|||
};
|
||||
in {
|
||||
options.meta = {
|
||||
|
||||
exposes = mkOption {
|
||||
type = with types; attrsOf (submodule exposesOpts);
|
||||
description = ''
|
||||
|
@ -37,6 +39,5 @@ in {
|
|||
};
|
||||
|
||||
config = {
|
||||
|
||||
};
|
||||
}
|
||||
|
|
32
nixos/common/modules/nginx.nix
Normal file
32
nixos/common/modules/nginx.nix
Normal file
|
@ -0,0 +1,32 @@
|
|||
{ lib, hosts, config, ... }:
|
||||
with lib;
|
||||
let cfg = config.services.v.nginx;
|
||||
in {
|
||||
options.services.v.nginx.generateVirtualHosts =
|
||||
mkEnableOption "generate vhosts";
|
||||
|
||||
config = let
|
||||
|
||||
proxy = url: {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations."/" = {
|
||||
proxyPass = url;
|
||||
proxyWebsockets = true;
|
||||
};
|
||||
};
|
||||
|
||||
hosts' =
|
||||
filter (hasAttr "exposes") (attrValues hosts.${config.networking.domain});
|
||||
exposes = { ip, exposes, ... }:
|
||||
map ({ domain, port ? 80}: { inherit ip domain port; }) (attrValues exposes);
|
||||
mkVhost = { ip, domain, port}: {
|
||||
"${domain}" = proxy "http://${ip}:${toString port}";
|
||||
};
|
||||
vhosts = foldr (el: acc: acc // mkVhost el) { } (concatMap exposes hosts');
|
||||
in mkIf cfg.generateVirtualHosts {
|
||||
|
||||
services.nginx.virtualHosts = vhosts;
|
||||
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue