Move proxies to module

This commit is contained in:
Greg Hellings
2022-04-20 11:11:35 -05:00
parent cb3dad8411
commit 2798392892
6 changed files with 90 additions and 24 deletions
+1
View File
@@ -17,6 +17,7 @@
let
mods = hostname: [
inputs.agenix.nixosModule
./modules
./profiles/base.nix
./hosts/${hostname}
inputs.home-manager.nixosModules.home-manager {
+3 -12
View File
@@ -93,18 +93,9 @@ in
# multiple layers of proxies, then add more of them in the list. The list also accepts subnet notation in case you have
# multiple potentially incoming connections. So you could do "10.88.0.1/24", according to the docs. However, that has not
# worked in my testing, as Home Assistant throws an error on start up saying that value is invalid
services.nginx = {
enable= true;
virtualHosts."smart.thehellings.lan".locations."/" = {
proxyPass = "http://127.0.0.1:8123";
extraConfig = ''
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
'';
};
greg.proxies."smart.thehellings.lan" = {
target = "http://127.0.0.1:8123";
ssl = false;
};
# Ensure that both ports are up and running. We keep 8123 directly open because we are on the LAN and sometimes want to connect
+7 -7
View File
@@ -5,12 +5,12 @@
{ ... }:
{
services.nginx = {
enable = true;
# A proxy front-end for Syncthing
virtualHosts."dns.thehellings.lan" = {
locations."/sync/".proxyPass = "http://127.0.0.1:8384/";
serverAliases = [ "dns" ];
};
greg.proxies."dns.thehellings.lan" = {
target = "http://127.0.0.1:8384/";
ssl = false;
path = "/sync/";
};
# The module doesn't handle this
services.nginx.virtualHosts."dns.thehellings.lan".serverAliases = [ "dns" ];
}
+7
View File
@@ -0,0 +1,7 @@
{ ... }:
{
imports = [
./proxy.nix
];
}
+72
View File
@@ -0,0 +1,72 @@
{ config, lib, pkgs, ... }:
let
cfg = config.greg.proxies;
makeHost = name: dest: {
forceSSL = dest.ssl;
enableACME = dest.ssl;
locations."${dest.path}" = {
proxyPass = dest.target;
extraConfig = ''
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
'';
};
};
in with lib; {
options = {
greg.proxies = mkOption {
default = {};
example = literalExpression ''
{ host-name = {
target = proxyLocation;
ssl = true;
};
'';
description = ''
Quick and simple Nginx proxy configurations.
Use this to configure a very simple proxy that does not
need any extra customization options other than SSL
enablement.
'';
type = with types; attrsOf (submodule (
{ name, config, options, ... }:
{
options = {
target = mkOption {
type = types.str;
description = ''The destination that is being proxied.'';
example = "http://localhost:8080";
};
ssl = mkOption {
type = types.bool;
description = "Whether to enable SSL in front of the proxy";
default = false;
};
path = mkOption {
type = types.str;
description = "The path prefix for this proxy";
default = "/";
};
};
}));
};
};
config.services.nginx = mkIf ( ( attrValues cfg ) != [] ) {
enable = true;
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
virtualHosts = mapAttrs makeHost cfg;
};
}
-5
View File
@@ -76,11 +76,6 @@ in
path = "/home/greg/drive";
devices = syncs;
};
"pifvm-wdsh9" = {
enable = true;
path = "/home/greg/.ssh";
devices = syncs;
};
};
};