From 1b40ddcb978dec8cf52a82319f1f8b4e4eedd3f8 Mon Sep 17 00:00:00 2001 From: tdback Date: Sun, 26 Jan 2025 11:31:39 -0500 Subject: containers: reworked each container to be a standalone module --- modules/containers/lubelogger/default.nix | 102 ++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 26 deletions(-) (limited to 'modules/containers/lubelogger') diff --git a/modules/containers/lubelogger/default.nix b/modules/containers/lubelogger/default.nix index 6ff2b0d..c7ca98f 100644 --- a/modules/containers/lubelogger/default.nix +++ b/modules/containers/lubelogger/default.nix @@ -1,34 +1,84 @@ -{ ... }: +{ + config, + lib, + ... +}: +with lib; let - directory = "/opt/lubelogger"; - port = "8889"; + service = "lubelogger"; + cfg = config.modules.containers.${service}; in { - systemd.tmpfiles.rules = builtins.map (x: "d ${x} 0755 share share - -") [ directory ]; + options.modules.containers.${service} = { + enable = mkEnableOption service; + user = mkOption { + default = "share"; + type = types.str; + }; + group = mkOption { + default = "share"; + type = types.str; + }; + port = mkOption { + default = 8889; + type = types.int; + }; + url = mkOption { + default = null; + type = types.str; + }; + configDir = mkOption { + default = "/opt/${service}"; + type = types.str; + }; + }; + + config = mkIf cfg.enable { + users.users.${cfg.user} = { + isSystemUser = true; + group = cfg.group; + }; + + users.groups.${cfg.group} = { }; - virtualisation.oci-containers.containers.lubelogger = { - image = "ghcr.io/hargata/lubelogger:latest"; - autoStart = true; - ports = [ "${port}:8080" ]; - volumes = [ - "${directory}/config:/App/config" - "${directory}/data:/App/data" - "${directory}/translations:/App/wwwroot/translations" - "${directory}/documents:/App/wwwroot/documents" - "${directory}/images:/App/wwwroot/images" - "${directory}/temp:/App/wwwroot/temp" - "${directory}/log:/App/log" - "${directory}/keys:/root/.aspnet/DataProtection-Keys" + networking.firewall.allowedTCPPorts = [ + 80 + 443 ]; - environment = { - LC_ALL = "en_US.UTF-8"; - LANG = "en_US.UTF-8"; - LUBELOGGER_ALLOWED_FILE_EXTENSIONS = "*"; + + services.caddy = { + enable = true; + virtualHosts = { + ${cfg.url}.extraConfig = '' + encode zstd gzip + reverse_proxy http://localhost:${builtins.toString cfg.port} + ''; + }; }; - }; - services.caddy.virtualHosts."garage.brownbread.net".extraConfig = '' - encode zstd gzip - reverse_proxy http://localhost:${port} - ''; + systemd.tmpfiles.rules = builtins.map (f: "d ${f} 0755 ${cfg.user} ${cfg.group} - -") [ + cfg.configDir + ]; + + virtualisation.oci-containers.containers.${service} = { + image = "ghcr.io/hargata/lubelogger:latest"; + autoStart = true; + ports = [ "${builtins.toString cfg.port}:8080" ]; + volumes = [ + "${cfg.configDir}/config:/App/config" + "${cfg.configDir}/data:/App/data" + "${cfg.configDir}/translations:/App/wwwroot/translations" + "${cfg.configDir}/documents:/App/wwwroot/documents" + "${cfg.configDir}/images:/App/wwwroot/images" + "${cfg.configDir}/temp:/App/wwwroot/temp" + "${cfg.configDir}/log:/App/log" + "${cfg.configDir}/keys:/root/.aspnet/DataProtection-Keys" + ]; + environment = { + LC_ALL = "en_US.UTF-8"; + LANG = "en_US.UTF-8"; + LUBELOGGER_ALLOWED_FILE_EXTENSIONS = "*"; + }; + }; + }; } -- cgit v1.2.3