migrated lambdas to setup.nix + lambda for server files

This commit is contained in:
2024-10-02 18:16:06 -06:00
parent 6181709ca3
commit ef00d45148
21 changed files with 118 additions and 347 deletions

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxy,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.audiobookshelf;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.audiobookshelf = setup.mkOptions "audiobookshelf" "audiobooks" 5687;
@@ -18,20 +13,22 @@ in
enable = true;
group = "piracy";
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (proxy {
"/" = {
proxyPass = cfg.local;
extraConfig = ''
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_redirect http:// https://;
'';
};
});
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxy {
"/" = {
proxyPass = cfg.local;
extraConfig = ''
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_redirect http:// https://;
'';
};
}
);
};
};
}

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.bazarr;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.bazarr = setup.mkOptions "bazarr" "subs" config.services.bazarr.listenPort;
@@ -18,7 +13,7 @@ in
group = "piracy";
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
};

View File

@@ -1,14 +1,9 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.flame;
cfgS = config.my.servers.flameSecret;
enable = (cfg.enable || cfgS.enable);
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers = {
@@ -52,8 +47,8 @@ in
};
services.nginx = {
virtualHosts = lib.mkIf (cfg.enableProxy || cfgS.enableProxy) {
"${cfg.host}" = proxyReverse cfg.hostName cfg.port // { };
"${cfgS.host}" = proxyReverse cfgS.hostName cfgS.port // { };
"${cfg.host}" = setup.proxyReverse cfg.hostName cfg.port // { };
"${cfgS.host}" = setup.proxyReverse cfgS.hostName cfgS.port // { };
};
};
};

View File

@@ -1,13 +1,8 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
services = import ./homepage/services.nix { inherit config lib; };
cfg = config.my.servers.homepage;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.homepage = setup.mkOptions "homepage" "home" 8082;
@@ -127,7 +122,7 @@ in
];
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
};

View File

@@ -2,7 +2,6 @@
lib,
config,
pkgs,
setup,
...
}:
let
@@ -19,6 +18,7 @@ let
pkgs.gum
sub-sync
];
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.jellyfin = setup.mkOptions "jellyfin" "flix" 8096;

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.kavita;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.kavita = setup.mkOptions "kavita" "library" config.services.kavita.settings.Port;
@@ -27,7 +22,7 @@ in
tokenKeyFile = config.sops.secrets.kavita-token.path;
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
};

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverseArr,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.lidarr;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.lidarr = setup.mkOptions "lidarr" "music" 8686;
@@ -38,7 +33,7 @@ in
};
};
services.nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverseArr cfg.hostName cfg.port // { }
setup.proxyReverseArr cfg.hostName cfg.port // { }
);
};
}

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.maloja;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.maloja = setup.mkOptions "maloja" "maloja" 42010;
@@ -34,7 +29,7 @@ in
};
};
services.nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
}

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.mealie;
setup = import ../setup.nix { inherit lib config; };
in
{
disabledModules = [ "services/web-apps/mealie.nix" ];
@@ -35,7 +30,7 @@ in
credentialsFile = config.sops.secrets.mealie.path;
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
};

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.metube;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.metube = setup.mkOptions "metube" "bajameesta" 8881;
@@ -25,7 +20,7 @@ in
};
};
services.nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
}

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.microbin;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.microbin = setup.mkOptions "microbin" "copy" 8080;
@@ -26,7 +21,7 @@ in
};
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
};

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.multi-scrobbler;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.multi-scrobbler = setup.mkOptions "multi-scrobbler" "scrobble" 9078;
@@ -35,7 +30,7 @@ in
};
};
services.nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
}

View File

@@ -2,7 +2,6 @@
lib,
config,
pkgs,
setup,
...
}:
let
@@ -17,6 +16,7 @@ let
'';
cfg = config.my.servers.nextcloud;
cfgC = config.my.servers.collabora;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers = {

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverseArr,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.prowlarr;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.prowlarr = setup.mkOptions "prowlarr" "indexer" 9696;
@@ -19,7 +14,7 @@ in
services = {
prowlarr.enable = cfg.enable;
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverseArr cfg.hostName cfg.port // { }
setup.proxyReverseArr cfg.hostName cfg.port // { }
);
};
virtualisation.oci-containers.containers.flaresolverr = lib.mkIf cfg.enable {

View File

@@ -2,11 +2,11 @@
lib,
config,
proxyReverseArr,
setup,
...
}:
let
cfg = config.my.servers.radarr;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.radarr = setup.mkOptions "radarr" "movies" 7878;
@@ -18,7 +18,7 @@ in
group = "piracy";
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverseArr cfg.hostName cfg.port // { }
setup.proxyReverseArr cfg.hostName cfg.port // { }
);
};
};

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.ryot;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.ryot = setup.mkOptions "ryot" "tracker" 8765;
@@ -31,7 +26,7 @@ in
};
};
services.nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
}

View File

@@ -1,47 +0,0 @@
{ lib, config, ... }:
let
mkOptions = name: subdomain: port: {
enable = lib.mkEnableOption "enable";
enableCron = lib.mkEnableOption "enable cronjob";
enableProxy = lib.mkEnableOption "enable reverse proxy";
port = lib.mkOption {
type = lib.types.int;
default = port;
};
name = lib.mkOption {
type = lib.types.str;
default = name;
};
host = lib.mkOption {
type = lib.types.str;
default = "${subdomain}.${config.my.domain}";
};
hostName = lib.mkOption {
type = lib.types.str;
default = config.networking.hostName;
};
url = lib.mkOption {
type = lib.types.str;
default = "https://${config.my.servers.${name}.host}";
};
ip = lib.mkOption {
type = lib.types.str;
default =
if config.my.servers."${name}".isLocal then
config.my.localhost
else
config.my.ips."${config.my.servers.${name}.hostName}";
};
local = lib.mkOption {
type = lib.types.str;
default = "http://${config.my.servers.${name}.ip}:${toString port}";
};
isLocal = lib.mkOption {
type = lib.types.bool;
default = "${config.my.servers.${name}.hostName}" == config.my.mainServer;
};
};
in
{
inherit mkOptions;
}

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.shiori;
setup = import ../setup.nix { inherit lib config; };
in
{
disabledModules = [ "services/web-apps/shiori.nix" ];
@@ -23,7 +18,7 @@ in
databaseUrl = "postgres:///shiori?host=${config.my.postgresSocket}";
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
};

View File

@@ -1,12 +1,7 @@
{
lib,
config,
proxyReverse,
setup,
...
}:
{ lib, config, ... }:
let
cfg = config.my.servers.sonarr;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.sonarr = setup.mkOptions "sonarr" "series" 8989;
@@ -18,7 +13,7 @@ in
group = "piracy";
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
};

View File

@@ -2,12 +2,11 @@
lib,
config,
pkgs,
proxyReverse,
setup,
...
}:
let
cfg = config.my.servers.vaultwarden;
setup = import ../setup.nix { inherit lib config; };
in
{
options.my.servers.vaultwarden = setup.mkOptions "vaultwarden" "vault" 8222;
@@ -33,7 +32,7 @@ in
};
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg.hostName cfg.port // { }
);
};
};