mkModule various

This commit is contained in:
mjallen18
2025-12-17 12:52:42 -06:00
parent 50345adeb5
commit 96ce0001c5
16 changed files with 462 additions and 636 deletions

View File

@@ -5,24 +5,14 @@
... ...
}: }:
let let
inherit (lib.${namespace}) mkOpt mkReverseProxyOpt; name = "glance";
cfg = config.${namespace}.services.glance; cfg = config.${namespace}.services.${name};
in
with lib;
{
options.${namespace}.services.glance = {
enable = mkEnableOption "glance service";
port = mkOpt types.int 80 "Port for glance to be hosted on"; glanceConfig = lib.${namespace}.mkModule {
inherit config name;
localAddress = mkOpt types.str "127.0.0.1" "local address of the service"; description = "glance";
options = { };
dataDir = mkOpt types.str "" "Path to the data dir"; moduleConfig = {
reverseProxy = mkReverseProxyOpt;
};
config = lib.mkIf cfg.enable {
services.glance = { services.glance = {
enable = true; enable = true;
openFirewall = true; openFirewall = true;
@@ -57,7 +47,7 @@ with lib;
{ {
type = "local"; type = "local";
name = "Jallen-NAS"; name = "Jallen-NAS";
cpu-temp-sensor = "/sys/class/hwmon/hwmon2/temp2_input"; cpu-temp-sensor = "/sys/class/hwmon/hwmon2/temp2_input"; # TODO
mountpoints = { mountpoints = {
"/home" = { "/home" = {
name = "Home"; name = "Home";
@@ -140,7 +130,7 @@ with lib;
allow-insecure = true; allow-insecure = true;
basic-auth = { basic-auth = {
username = "mjallen"; username = "mjallen";
password = "BogieDudie1"; password = "BogieDudie1"; # todo
}; };
} }
{ {
@@ -228,4 +218,8 @@ with lib;
}; };
}; };
}; };
};
in
{
imports = [ glanceConfig ];
} }

View File

@@ -7,18 +7,14 @@
}: }:
with lib; with lib;
let let
cfg = config.${namespace}.services.glances; name = "glances";
in cfg = config.${namespace}.services.${name};
{
imports = [ ./options.nix ];
config = mkIf cfg.enable {
# Open firewall for glances if enabled
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.port ];
allowedUDPPorts = [ cfg.port ];
};
glancesConfig = lib.${namespace}.mkModule {
inherit config name;
description = "Glances system monitoring web server";
options = { };
moduleConfig = {
# Install glances package # Install glances package
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
glances glances
@@ -37,7 +33,7 @@ in
]; ];
script = '' script = ''
glances -w --bind ${cfg.bindAddress} --port ${toString cfg.port} glances -w --bind ${cfg.listenAddress} --port ${toString cfg.port}
''; '';
serviceConfig = { serviceConfig = {
@@ -60,4 +56,8 @@ in
users.groups.glances = { }; users.groups.glances = { };
}; };
};
in
{
imports = [ glancesConfig ];
} }

View File

@@ -1,25 +0,0 @@
{ lib, namespace, ... }:
with lib;
{
options.${namespace}.services.glances = {
enable = mkEnableOption "glances system monitoring service";
port = mkOption {
type = types.port;
default = 61208;
description = "Port for glances web interface";
};
openFirewall = mkOption {
type = types.bool;
default = true;
description = "Whether to open firewall for glances";
};
bindAddress = mkOption {
type = types.str;
default = "0.0.0.0";
description = "Address to bind glances web server to";
};
};
}

View File

@@ -6,16 +6,14 @@
}: }:
with lib; with lib;
let let
# inherit (lib.${namespace}) mkModule mkOpt mkBoolOpt enableForSystem; name = "grafana";
cfg = config.${namespace}.services.grafana; cfg = config.${namespace}.services.${name};
upsUser = "nas-admin";
in
{
options.${namespace}.services.grafana = {
enable = mkEnableOption "enable grafana";
};
config = lib.mkIf cfg.enable { grafanaConfig = lib.${namespace}.mkModule {
inherit config name;
description = "grafana";
options = { };
moduleConfig = {
services = { services = {
prometheus = { prometheus = {
enable = true; enable = true;
@@ -74,7 +72,7 @@ in
enable = true; enable = true;
settings = { settings = {
server = { server = {
http_port = 9999; http_port = cfg.port;
http_addr = "0.0.0.0"; http_addr = "0.0.0.0";
}; };
}; };
@@ -94,10 +92,11 @@ in
}; };
}; };
}; };
# Open firewall ports for Grafana
networking.firewall = {
allowedTCPPorts = [ 9999 ];
allowedUDPPorts = [ 9999 ];
}; };
}; };
upsUser = "nas-admin";
in
{
imports = [ grafanaConfig ];
} }

View File

@@ -6,17 +6,21 @@
}: }:
with lib; with lib;
let let
inherit (lib.${namespace}) mkOpt mkReverseProxyOpt; name = "headscale";
cfg = config.${namespace}.services.headscale; cfg = config.${namespace}.services.${name};
headscaleConfig = { headscaleConfig = lib.${namespace}.mkModule {
inherit config name;
description = "headscale";
options = { };
moduleConfig = {
services.headscale = { services.headscale = {
enable = true; enable = true;
address = "0.0.0.0"; address = cfg.listenAddress;
port = cfg.port; port = cfg.port;
settings = { settings = {
server_url = "https://headscale.mjallen.dev:443"; server_url = "https://headscale.mjallen.dev:443";
database.sqlite.path = "${cfg.dataDir}/db.sqlite"; database.sqlite.path = "${cfg.configDir}/headscale/db.sqlite";
dns = { dns = {
nameservers.global = [ nameservers.global = [
"1.1.1.1" "1.1.1.1"
@@ -29,34 +33,8 @@ let
# oidc # oidc
}; };
}; };
# Create reverse proxy configuration using mkReverseProxy
reverseProxyConfig = lib.${namespace}.mkReverseProxy {
name = "headscale";
subdomain = cfg.reverseProxy.subdomain;
url = "http://${cfg.localAddress}:${toString cfg.port}";
middlewares = cfg.reverseProxy.middlewares;
}; };
fullConfig = {
"${namespace}".services.traefik = lib.mkIf cfg.reverseProxy.enable {
reverseProxies = [ reverseProxyConfig ];
};
}
// headscaleConfig;
in in
{ {
options.${namespace}.services.headscale = { imports = [ headscaleConfig ];
enable = mkEnableOption "headscale service";
port = mkOpt types.int 8080 "Port for headscale to be hosted on";
localAddress = mkOpt types.str "127.0.0.1" "local address of the service";
dataDir = mkOpt types.str "" "Path to the data dir";
reverseProxy = mkReverseProxyOpt;
};
config = mkIf cfg.enable fullConfig;
} }

View File

@@ -6,26 +6,25 @@
}: }:
with lib; with lib;
let let
cfg = config.${namespace}.services.immich; name = "immich";
cfg = config.${namespace}.services.${name};
immichPort = 2283;
dataDir = "/media/nas/main/photos";
dbPassword = config.sops.secrets."jallen-nas/immich/db-password".path; dbPassword = config.sops.secrets."jallen-nas/immich/db-password".path;
in
{
imports = [ ./options.nix ];
config = mkIf cfg.enable { immichConfig = lib.${namespace}.mkModule {
inherit config name;
description = "immich";
options = { };
moduleConfig = {
# Enable immich service # Enable immich service
services.immich = { services.immich = {
enable = true; enable = true;
port = immichPort; port = cfg.port;
openFirewall = true; openFirewall = true;
secretsFile = dbPassword; secretsFile = dbPassword;
mediaLocation = dataDir; mediaLocation = "${cfg.dataDir}/photos";
environment = { environment = {
IMMICH_HOST = lib.mkForce "0.0.0.0"; IMMICH_HOST = lib.mkForce cfg.listenAddress;
IMMICH_TRUSTED_PROXIES = "10.0.1.3"; IMMICH_TRUSTED_PROXIES = "10.0.1.3";
TZ = "America/Chicago"; TZ = "America/Chicago";
}; };
@@ -35,4 +34,8 @@ in
}; };
}; };
}; };
};
in
{
imports = [ immichConfig ];
} }

View File

@@ -1,7 +0,0 @@
{ lib, namespace, ... }:
with lib;
{
options.${namespace}.services.immich = {
enable = mkEnableOption "enable immich";
};
}

View File

@@ -6,19 +6,25 @@
}: }:
with lib; with lib;
let let
cfg = config.${namespace}.services.jellyfin; name = "jellyfin";
in cfg = config.${namespace}.services.${name};
{
imports = [ ./options.nix ];
config = mkIf cfg.enable { jellyfinConfig = lib.${namespace}.mkModule {
inherit config name;
description = "jellyfin";
options = { };
moduleConfig = {
services.jellyfin = { services.jellyfin = {
enable = true; enable = true;
openFirewall = true; openFirewall = cfg.openFirewall;
user = "nix-apps"; user = "nix-apps";
group = "jallen-nas"; group = "jallen-nas";
dataDir = "/media/nas/main/nix-app-data/jellyfin"; dataDir = "${cfg.configDir}/jellyfin";
# cacheDir = "/cache"; # cacheDir = "/cache";
}; };
}; };
};
in
{
imports = [ jellyfinConfig ];
} }

View File

@@ -1,7 +0,0 @@
{ lib, namespace, ... }:
with lib;
{
options.${namespace}.services.jellyfin = {
enable = mkEnableOption "enable jellyfin";
};
}

View File

@@ -6,44 +6,36 @@
}: }:
with lib; with lib;
let let
inherit (lib.${namespace}) mkOpt; name = "jellyseerr";
cfg = config.${namespace}.services.jellyseerr; cfg = config.${namespace}.services.${name};
in
{
options.${namespace}.services.jellyseerr = {
enable = mkEnableOption "enable jellyseerr";
port = mkOpt types.int 5055 "jellyseerr port"; jellyseerrConfig = lib.${namespace}.mkModule {
inherit config name;
dataDir = mkOpt types.str "" "data dir"; description = "jellyseerr";
}; options = { };
moduleConfig = {
config = mkIf cfg.enable {
# Enable jellyseerr service # Enable jellyseerr service
services.jellyseerr = { services.jellyseerr = {
enable = true; enable = true;
port = cfg.port; port = cfg.port;
openFirewall = true; openFirewall = cfg.openFirewall;
configDir = cfg.dataDir; configDir = "${cfg.configDir}/jellyseerr";
}; };
systemd.services = { systemd.services = {
jellyseerr = { jellyseerr = {
serviceConfig = { serviceConfig = {
WorkingDirectory = lib.mkForce cfg.dataDir; WorkingDirectory = lib.mkForce "${cfg.configDir}/jellyseerr";
StateDirectory = lib.mkForce cfg.dataDir; StateDirectory = lib.mkForce "${cfg.configDir}/jellyseerr";
StateDirectoryMode = lib.mkForce 700; StateDirectoryMode = lib.mkForce 700;
DynamicUser = lib.mkForce false; DynamicUser = lib.mkForce false;
ProtectSystem = lib.mkForce null; ProtectSystem = lib.mkForce null;
}; };
}; };
}; };
users.users.jellyseerr = {
isSystemUser = true;
group = "jellyseerr";
home = cfg.dataDir;
}; };
users.groups.jellyseerr = { };
}; };
in
{
imports = [ jellyseerrConfig ];
} }

View File

@@ -1,83 +0,0 @@
{
config,
lib,
namespace,
...
}:
with lib;
let
cfg = config.${namespace}.services.jellyseerr;
jellyseerrPort = 5055;
dataDir = "/var/lib/private/jellyseerr";
in
{
imports = [ ./options.nix ];
config = mkIf cfg.enable {
containers.jellyseerr = {
autoStart = true;
privateNetwork = true;
hostAddress = "10.0.1.3";
localAddress = "10.0.1.52";
hostAddress6 = "fc00::1";
localAddress6 = "fc00::4";
bindMounts = {
${dataDir} = {
hostPath = "/media/nas/main/nix-app-data/jellyseerr";
isReadOnly = false;
};
};
config =
{
lib,
...
}:
{
# Enable jellyseerr service
services.jellyseerr = {
enable = true;
port = jellyseerrPort;
# package = package;
openFirewall = true;
};
networking = {
firewall = {
enable = true;
allowedTCPPorts = [ jellyseerrPort ];
};
# Use systemd-resolved inside the container
# Workaround for bug https://github.com/NixOS/nixpkgs/issues/162686
useHostResolvConf = lib.mkForce false;
};
# Create and set permissions for required directories
system.activationScripts.jellyseerr-dirs = ''
mkdir -p /var/lib/private/jellyseerr
chown -R jellyseerr:jellyseerr /var/lib/private/jellyseerr
chmod -R 775 /var/lib/private/jellyseerr
ln -sf /var/lib/private/jellyseerr /var/lib/jellyfin
'';
services.resolved.enable = true;
system.stateVersion = "23.11";
};
};
networking.nat = {
forwardPorts = [
{
destination = "10.0.1.52:5055";
sourcePort = jellyseerrPort;
}
];
};
};
}

View File

@@ -1,7 +0,0 @@
{ lib, namespace, ... }:
with lib;
{
options.${namespace}.services.jellyseerr = {
enable = mkEnableOption "enable jellyseerr";
};
}

View File

@@ -6,22 +6,24 @@
}: }:
with lib; with lib;
let let
cfg = config.${namespace}.services.lubelogger; name = "lubelogger";
in cfg = config.${namespace}.services.${name};
{
imports = [ ./options.nix ];
config = mkIf cfg.enable { lubeloggerConfig = lib.${namespace}.mkModule {
inherit config name;
description = "lubelogger";
options = { };
moduleConfig = {
virtualisation.oci-containers.containers.lubelogger = { virtualisation.oci-containers.containers.lubelogger = {
autoStart = true; autoStart = true;
image = "ghcr.io/hargata/lubelogger"; image = "ghcr.io/hargata/lubelogger";
ports = [ "${toString cfg.port}:8080" ]; ports = [ "${toString cfg.port}:8080" ];
volumes = [ volumes = [
"/media/nas/main/nix-app-data/lubelogger:/App/data" "${cfg.configDir}/lubelogger:/App/data"
"/media/nas/main/nix-app-data/lubelogger/keys:/root/.aspnet/DataProtection-Keys" "${cfg.configDir}/lubelogger/keys:/root/.aspnet/DataProtection-Keys"
]; ];
environmentFiles = [ environmentFiles = [
"/media/nas/main/nix-app-data/lubelogger/lubelogger.env" "${cfg.configDir}/lubelogger/lubelogger.env"
]; ];
environment = { environment = {
PUID = toString config.users.users.nix-apps.uid; PUID = toString config.users.users.nix-apps.uid;
@@ -29,11 +31,9 @@ in
TZ = "America/Chicago"; TZ = "America/Chicago";
}; };
}; };
# Open firewall for lubelogger if enabled
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.port ];
allowedUDPPorts = [ cfg.port ];
}; };
}; };
in
{
imports = [ lubeloggerConfig ];
} }

View File

@@ -1,19 +0,0 @@
{ lib, namespace, ... }:
with lib;
{
options.${namespace}.services.lubelogger = {
enable = mkEnableOption "enable lubelogger";
port = mkOption {
type = types.port;
default = 6754;
description = "Port for lubelogger web interface";
};
openFirewall = mkOption {
type = types.bool;
default = true;
description = "Whether to open firewall for lubelogger";
};
};
}

View File

@@ -81,28 +81,27 @@ in
glances = { glances = {
enable = true; enable = true;
port = 61208; port = 61208;
bindAddress = "0.0.0.0"; createUser = true;
}; };
headscale = { headscale = {
enable = false; enable = false;
port = 2112; port = 2112;
dataDir = "/media/nas/main/nix-app-data/headscale"; reverseProxy.enable = true;
reverseProxy = { };
immich = {
enable = true; enable = true;
subdomain = "headscale"; port = 2283;
middlewares = [
"crowdsec"
"whitelist-geoblock"
];
}; };
};
immich = enabled;
jellyfin = enabled; jellyfin = enabled;
jellyseerr = { jellyseerr = {
enable = true; enable = true;
dataDir = "/media/nas/main/nix-app-data/jellyseerr"; port = 5055;
createUser = true;
};
lubelogger = {
enable = true;
port = 6754;
}; };
lubelogger = enabled;
manyfold = enabled; manyfold = enabled;
matrix = { matrix = {
enable = true; enable = true;

View File

@@ -227,7 +227,10 @@ in
# ################################################### # ###################################################
services = { services = {
grafana = enabled; grafana = {
enable = true;
port = 9999;
};
}; };
# ################################################### # ###################################################