moved service config out of host namespace

This commit is contained in:
Leyla Becker 2025-03-22 13:27:04 -05:00
parent c7938c3fe7
commit 597c25b49d
7 changed files with 98 additions and 125 deletions

View file

@ -51,7 +51,6 @@ nix multi user, multi system, configuration with `sops` secret management, `home
- syncthing folder passwords - syncthing folder passwords
- nfs export should be backed by the same values for server and client - nfs export should be backed by the same values for server and client
- move fail2ban configs out of fail2ban.nix and into configs for their respective services - move fail2ban configs out of fail2ban.nix and into configs for their respective services
- move extra custom configuration for services out of host config and instead extend services
## New Features ## New Features
- offline access for nfs mounts (overlay with rsync might be a good option here? https://www.spinics.net/lists/linux-unionfs/msg07105.html note about nfs4 and overlay fs) - offline access for nfs mounts (overlay with rsync might be a good option here? https://www.spinics.net/lists/linux-unionfs/msg07105.html note about nfs4 and overlay fs)
- samba mounts - samba mounts

View file

@ -48,9 +48,6 @@
]; ];
}; };
}; };
fail2ban = {
enable = true;
};
network_storage = { network_storage = {
enable = true; enable = true;
directories = [ directories = [
@ -74,7 +71,7 @@
folder = "media"; folder = "media";
user = "jellyfin"; user = "jellyfin";
group = "jellyfin_media"; group = "jellyfin_media";
bind = config.host.jellyfin.media_directory; bind = config.services.jellyfin.media_directory;
} }
]; ];
nfs = { nfs = {
@ -94,19 +91,6 @@
}; };
}; };
}; };
jellyfin = {
enable = true;
subdomain = "media";
extraSubdomains = ["jellyfin"];
};
forgejo = {
enable = true;
subdomain = "git";
};
searx = {
enable = true;
subdomain = "search";
};
home-assistant = { home-assistant = {
enable = false; enable = false;
subdomain = "home"; subdomain = "home";
@ -114,10 +98,6 @@
adguardhome = { adguardhome = {
enable = false; enable = false;
}; };
immich = {
enable = true;
subdomain = "photos";
};
sync = { sync = {
enable = true; enable = true;
folders = { folders = {
@ -187,6 +167,29 @@
"--accept-dns=false" "--accept-dns=false"
]; ];
}; };
fail2ban.enable = true;
jellyfin = {
enable = true;
subdomain = "media";
extraSubdomains = ["jellyfin"];
};
immich = {
enable = true;
subdomain = "photos";
};
forgejo = {
enable = true;
subdomain = "git";
};
searx = {
enable = true;
subdomain = "search";
};
}; };
# disable computer sleeping # disable computer sleeping

View file

@ -7,11 +7,7 @@
dataFolder = "/var/lib/fail2ban"; dataFolder = "/var/lib/fail2ban";
dataFile = "fail2ban.sqlite3"; dataFile = "fail2ban.sqlite3";
in { in {
options.host.fail2ban = { config = lib.mkIf config.services.fail2ban.enable (lib.mkMerge [
enable = lib.mkEnableOption "should fail 2 ban be enabled on this server";
};
config = lib.mkIf config.host.fail2ban.enable (lib.mkMerge [
{ {
environment.etc = { environment.etc = {
"fail2ban/filter.d/nginx.local".text = lib.mkIf config.services.nginx.enable ( "fail2ban/filter.d/nginx.local".text = lib.mkIf config.services.nginx.enable (
@ -37,7 +33,6 @@ in {
}; };
services.fail2ban = { services.fail2ban = {
enable = true;
maxretry = 5; maxretry = 5;
ignoreIP = [ ignoreIP = [
# Whitelist local networks # Whitelist local networks
@ -90,8 +85,6 @@ in {
]; ];
environment.persistence."/persist/system/root" = { environment.persistence."/persist/system/root" = {
enable = true;
hideMounts = true;
directories = [ directories = [
{ {
directory = dataFolder; directory = dataFolder;

View file

@ -9,8 +9,7 @@
db_user = "forgejo"; db_user = "forgejo";
sshPort = 22222; sshPort = 22222;
in { in {
options.host.forgejo = { options.services.forgejo = {
enable = lib.mkEnableOption "should forgejo be enabled on this computer";
subdomain = lib.mkOption { subdomain = lib.mkOption {
type = lib.types.str; type = lib.types.str;
description = "subdomain of base domain that forgejo will be hosted at"; description = "subdomain of base domain that forgejo will be hosted at";
@ -18,10 +17,10 @@ in {
}; };
}; };
config = lib.mkIf config.host.forgejo.enable (lib.mkMerge [ config = lib.mkIf config.services.forgejo.enable (lib.mkMerge [
{ {
host = { host = {
reverse_proxy.subdomains.${config.host.forgejo.subdomain} = { reverse_proxy.subdomains.${config.services.forgejo.subdomain} = {
target = "http://localhost:${toString forgejoPort}"; target = "http://localhost:${toString forgejoPort}";
}; };
postgres = { postgres = {
@ -34,9 +33,7 @@ in {
}; };
}; };
services = { services.forgejo = {
forgejo = {
enable = true;
database = { database = {
type = "postgres"; type = "postgres";
socket = "/run/postgresql"; socket = "/run/postgresql";
@ -44,7 +41,7 @@ in {
lfs.enable = true; lfs.enable = true;
settings = { settings = {
server = { server = {
DOMAIN = "${config.host.forgejo.subdomain}.${config.host.reverse_proxy.hostname}"; DOMAIN = "${config.services.forgejo.subdomain}.${config.host.reverse_proxy.hostname}";
HTTP_PORT = forgejoPort; HTTP_PORT = forgejoPort;
START_SSH_SERVER = true; START_SSH_SERVER = true;
SSH_LISTEN_PORT = sshPort; SSH_LISTEN_PORT = sshPort;
@ -62,7 +59,6 @@ in {
}; };
}; };
}; };
};
networking.firewall.allowedTCPPorts = [ networking.firewall.allowedTCPPorts = [
config.services.forgejo.settings.server.SSH_LISTEN_PORT config.services.forgejo.settings.server.SSH_LISTEN_PORT

View file

@ -6,8 +6,7 @@
}: let }: let
mediaLocation = "/var/lib/immich"; mediaLocation = "/var/lib/immich";
in { in {
options.host.immich = { options.services.immich = {
enable = lib.mkEnableOption "should immich be enabled on this computer";
subdomain = lib.mkOption { subdomain = lib.mkOption {
type = lib.types.str; type = lib.types.str;
description = "subdomain of base domain that immich will be hosted at"; description = "subdomain of base domain that immich will be hosted at";
@ -15,10 +14,10 @@ in {
}; };
}; };
config = lib.mkIf config.host.immich.enable (lib.mkMerge [ config = lib.mkIf config.services.immich.enable (lib.mkMerge [
{ {
host = { host = {
reverse_proxy.subdomains.${config.host.immich.subdomain} = { reverse_proxy.subdomains.${config.services.immich.subdomain} = {
target = "http://localhost:${toString config.services.immich.port}"; target = "http://localhost:${toString config.services.immich.port}";
websockets.enable = true; websockets.enable = true;
@ -45,12 +44,6 @@ in {
}; };
}; };
services.immich = {
enable = true;
port = 2283;
# redis.enable = false;
};
networking.firewall.interfaces.${config.services.tailscale.interfaceName} = { networking.firewall.interfaces.${config.services.tailscale.interfaceName} = {
allowedUDPPorts = [ allowedUDPPorts = [
config.services.immich.port config.services.immich.port
@ -89,8 +82,6 @@ in {
} }
]; ];
environment.persistence."/persist/system/root" = { environment.persistence."/persist/system/root" = {
enable = true;
hideMounts = true;
directories = [ directories = [
{ {
directory = mediaLocation; directory = mediaLocation;

View file

@ -8,8 +8,7 @@
jellyfin_data_directory = "/var/lib/jellyfin"; jellyfin_data_directory = "/var/lib/jellyfin";
jellyfin_cache_directory = "/var/cache/jellyfin"; jellyfin_cache_directory = "/var/cache/jellyfin";
in { in {
options.host.jellyfin = { options.services.jellyfin = {
enable = lib.mkEnableOption "should jellyfin be enabled on this computer";
subdomain = lib.mkOption { subdomain = lib.mkOption {
type = lib.types.str; type = lib.types.str;
description = "subdomain of base domain that jellyfin will be hosted at"; description = "subdomain of base domain that jellyfin will be hosted at";
@ -27,16 +26,14 @@ in {
}; };
}; };
config = lib.mkIf config.host.jellyfin.enable ( config = lib.mkIf config.services.jellyfin.enable (
lib.mkMerge [ lib.mkMerge [
{ {
services.jellyfin.enable = true;
host.reverse_proxy.subdomains.jellyfin = { host.reverse_proxy.subdomains.jellyfin = {
target = "http://localhost:${toString jellyfinPort}"; target = "http://localhost:${toString jellyfinPort}";
subdomain = config.host.jellyfin.subdomain; subdomain = config.services.jellyfin.subdomain;
extraSubdomains = config.host.jellyfin.extraSubdomains; extraSubdomains = config.services.jellyfin.extraSubdomains;
forwardHeaders.enable = true; forwardHeaders.enable = true;
@ -107,8 +104,6 @@ in {
environment.persistence = { environment.persistence = {
"/persist/system/root" = { "/persist/system/root" = {
enable = true;
hideMounts = true;
directories = [ directories = [
{ {
directory = jellyfin_data_directory; directory = jellyfin_data_directory;
@ -128,7 +123,7 @@ in {
hideMounts = true; hideMounts = true;
directories = [ directories = [
{ {
directory = config.host.jellyfin.media_directory; directory = config.services.jellyfin.media_directory;
user = "jellyfin"; user = "jellyfin";
group = "jellyfin_media"; group = "jellyfin_media";
mode = "1770"; mode = "1770";

View file

@ -4,8 +4,7 @@
inputs, inputs,
... ...
}: { }: {
options.host.searx = { options.services.searx = {
enable = lib.mkEnableOption "should searx be enabled on this computer";
subdomain = lib.mkOption { subdomain = lib.mkOption {
type = lib.types.str; type = lib.types.str;
description = "subdomain of base domain that searx will be hosted at"; description = "subdomain of base domain that searx will be hosted at";
@ -13,7 +12,7 @@
}; };
}; };
config = lib.mkIf config.host.searx.enable { config = lib.mkIf config.services.searx.enable {
sops.secrets = { sops.secrets = {
"services/searx" = { "services/searx" = {
sopsFile = "${inputs.secrets}/defiant-services.yaml"; sopsFile = "${inputs.secrets}/defiant-services.yaml";
@ -21,13 +20,11 @@
}; };
host = { host = {
reverse_proxy.subdomains.searx = { reverse_proxy.subdomains.searx = {
subdomain = config.host.searx.subdomain; subdomain = config.services.searx.subdomain;
target = "http://localhost:${toString config.services.searx.settings.server.port}"; target = "http://localhost:${toString config.services.searx.settings.server.port}";
}; };
}; };
services = { services.searx = {
searx = {
enable = true;
environmentFile = config.sops.secrets."services/searx".path; environmentFile = config.sops.secrets."services/searx".path;
# Rate limiting # Rate limiting
@ -72,5 +69,4 @@
}; };
}; };
}; };
};
} }