This commit is contained in:
mjallen18
2025-12-14 21:50:50 -06:00
parent 0012a019fc
commit 34539045e5
41 changed files with 164 additions and 251 deletions

View File

@@ -1,4 +1,4 @@
{ inputs }:
{ inputs, lib, namespace }:
let
inherit (inputs.nixpkgs.lib)
mapAttrs
@@ -28,23 +28,69 @@ rec {
name,
description ? "",
options ? { },
config ? { },
moduleConfig ? { },
domain ? "services",
config
}:
{ lib, ... }:
let
cfg = config.${namespace}.${domain}.${name};
# Create reverse proxy configuration using mkReverseProxy
reverseProxyConfig = lib.${namespace}.mkReverseProxy {
inherit name;
subdomain = cfg.reverseProxy.subdomain;
url = "http://${config.${namespace}.network.ipv4.address}:${toString cfg.port}"; # TODO: address
middlewares = cfg.reverseProxy.middlewares;
};
defaultConfig = {
${namespace}.services.traefik = lib.mkIf cfg.reverseProxy.enable {
reverseProxies = [ reverseProxyConfig ];
};
users = lib.mkIf cfg.createUser {
users.${name} = {
isSystemUser = true;
group = name;
home = cfg.configDir;
};
groups.${name} = { };
};
systemd.tmpfiles.rules = [
"d ${cfg.configDir} 0700 ${name} ${name} - -"
"d ${cfg.configDir}/server-files 0700 ${name} ${name} - -"
"d ${cfg.configDir}/user-files 0700 ${name} ${name} - -"
];
} // moduleConfig;
in
{ config, lib, ... }:
{
options.mjallen.${name} = lib.mkOption {
options.${namespace}.${domain}.${name} = lib.mkOption {
type = lib.types.submodule {
options = {
enable = lib.mkEnableOption description;
port = mkOpt types.int 80 "Port for ${name} to be hosted on";
configDir = mkOpt types.str "/media/nas/main/nix-app-data/${name}" "Path to the config dir";
dataDir = mkOpt types.str "/media/nas/main/${name}" "Path to the data dir";
createUser = mkBoolOpt false "create a user for this module/service";
reverseProxy = mkReverseProxyOpt;
}
// options;
};
default = { };
};
config = lib.mkIf config.mjallen.${name}.enable config;
config = lib.mkIf cfg.enable defaultConfig;
};
# container
mkContainer =
{
name,