1
0
Fork 0

Services: function-ize domain parsing

This commit is contained in:
Aires 2024-09-08 23:47:53 -04:00
parent 10c0e42954
commit fc7889bdf1
7 changed files with 36 additions and 52 deletions

View file

@ -1,8 +1,9 @@
# Modules common to all systems # Modules common to all systems
{ {
pkgs,
config, config,
inputs, inputs,
lib,
pkgs,
... ...
}: }:
@ -15,13 +16,27 @@
zellij # Terminal multiplexer zellij # Terminal multiplexer
]; ];
# Allow packages from the unstable repo by using 'pkgs.unstable'
nixpkgs.overlays = [ nixpkgs.overlays = [
(final: _prev: { (final: _prev: {
# Allow packages from the unstable repo by using 'pkgs.unstable'
unstable = import inputs.nixpkgs-unstable { unstable = import inputs.nixpkgs-unstable {
system = final.system; system = final.system;
config.allowUnfree = true; config.allowUnfree = true;
}; };
# Define custom functions using 'pkgs.util'
util = {
# Parses the domain from a URL
getDomainFromURL =
url:
let
parsedURL = (lib.strings.splitString "." url);
in
builtins.concatStringsSep "." [
(builtins.elemAt parsedURL 1)
(builtins.elemAt parsedURL 2)
];
};
}) })
]; ];

View file

@ -31,14 +31,7 @@ in
services = { services = {
nginx.virtualHosts."${cfg.url}" = { nginx.virtualHosts."${cfg.url}" = {
useACMEHost = useACMEHost = pkgs.util.getDomainFromURL cfg.url;
let
parsedURL = (lib.strings.splitString "." cfg.url);
in
builtins.concatStringsSep "." [
(builtins.elemAt parsedURL 1)
(builtins.elemAt parsedURL 2)
];
forceSSL = true; forceSSL = true;
locations."/" = { locations."/" = {
proxyPass = "http://127.0.0.1:4040"; proxyPass = "http://127.0.0.1:4040";

View file

@ -1,4 +1,9 @@
{ config, lib, ... }: {
config,
lib,
pkgs,
...
}:
let let
cfg = config.aux.system.services.deluge; cfg = config.aux.system.services.deluge;
@ -25,14 +30,7 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
services = { services = {
nginx.virtualHosts."${cfg.url}" = { nginx.virtualHosts."${cfg.url}" = {
useACMEHost = useACMEHost = pkgs.util.getDomainFromURL cfg.url;
let
parsedURL = (lib.strings.splitString "." cfg.url);
in
builtins.concatStringsSep "." [
(builtins.elemAt parsedURL 1)
(builtins.elemAt parsedURL 2)
];
forceSSL = true; forceSSL = true;
locations."/" = { locations."/" = {
proxyPass = "http://127.0.0.1:8112"; proxyPass = "http://127.0.0.1:8112";

View file

@ -72,14 +72,7 @@ in
} // lib.optionalAttrs (cfg.home != null) { stateDir = cfg.home; }; } // lib.optionalAttrs (cfg.home != null) { stateDir = cfg.home; };
nginx.virtualHosts."${cfg.url}" = { nginx.virtualHosts."${cfg.url}" = {
useACMEHost = useACMEHost = pkgs.util.getDomainFromURL cfg.url;
let
parsedURL = (lib.strings.splitString "." cfg.url);
in
builtins.concatStringsSep "." [
(builtins.elemAt parsedURL 1)
(builtins.elemAt parsedURL 2)
];
forceSSL = true; forceSSL = true;
locations."/" = { locations."/" = {
proxyPass = "http://127.0.0.1:3000"; proxyPass = "http://127.0.0.1:3000";

View file

@ -1,4 +1,9 @@
{ config, lib, ... }: {
config,
lib,
pkgs,
...
}:
let let
cfg = config.aux.system.services.home-assistant; cfg = config.aux.system.services.home-assistant;
@ -49,14 +54,7 @@ in
}; };
}; };
nginx.virtualHosts."${cfg.url}" = { nginx.virtualHosts."${cfg.url}" = {
useACMEHost = useACMEHost = pkgs.util.getDomainFromURL cfg.url;
let
parsedURL = (lib.strings.splitString "." cfg.url);
in
builtins.concatStringsSep "." [
(builtins.elemAt parsedURL 1)
(builtins.elemAt parsedURL 2)
];
forceSSL = true; forceSSL = true;
locations."/" = { locations."/" = {
proxyPass = "http://[::1]:8123"; proxyPass = "http://[::1]:8123";

View file

@ -2,6 +2,7 @@
pkgs, pkgs,
config, config,
lib, lib,
self,
... ...
}: }:
let let
@ -34,14 +35,7 @@ in
services = { services = {
nginx.virtualHosts."${cfg.url}" = { nginx.virtualHosts."${cfg.url}" = {
useACMEHost = useACMEHost = pkgs.util.getDomainFromURL cfg.url;
let
parsedURL = (lib.strings.splitString "." cfg.url);
in
builtins.concatStringsSep "." [
(builtins.elemAt parsedURL 1)
(builtins.elemAt parsedURL 2)
];
forceSSL = true; forceSSL = true;
locations."/" = { locations."/" = {
proxyPass = "http://127.0.0.1:8096"; proxyPass = "http://127.0.0.1:8096";

View file

@ -50,14 +50,7 @@ in
(lib.mkIf (cfg.enable && cfg.type == "parent") { (lib.mkIf (cfg.enable && cfg.type == "parent") {
services = { services = {
nginx.virtualHosts."${cfg.url}" = { nginx.virtualHosts."${cfg.url}" = {
useACMEHost = useACMEHost = pkgs.util.getDomainFromURL cfg.url;
let
parsedURL = (lib.strings.splitString "." cfg.url);
in
builtins.concatStringsSep "." [
(builtins.elemAt parsedURL 1)
(builtins.elemAt parsedURL 2)
];
forceSSL = true; forceSSL = true;
basicAuth = { basicAuth = {
"${cfg.auth.user}" = cfg.auth.password; "${cfg.auth.user}" = cfg.auth.password;