From c97888291800fe21ac6133aa88960d3d34631bd9 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 20 Nov 2024 02:23:20 -0500 Subject: [PATCH] refactor: separate module options into `options.nix` --- modules/forgejo/default.nix | 131 +++++++++++++----------------------- modules/forgejo/options.nix | 45 +++++++++++++ 2 files changed, 90 insertions(+), 86 deletions(-) create mode 100644 modules/forgejo/options.nix diff --git a/modules/forgejo/default.nix b/modules/forgejo/default.nix index 20e19ae..981dc46 100644 --- a/modules/forgejo/default.nix +++ b/modules/forgejo/default.nix @@ -1,96 +1,55 @@ { config, lib, ... }: -{ - options.aether = { - inherit (import ../options.nix { inherit lib; }) domain https acmeEmail; +let + cfg = config.aether.forgejo; + forgejo = config.services.forgejo; + srv = forgejo.settings.server; +in { + imports = [ ./options.nix ]; - forgejo = { - subdomain = lib.mkOption { - type = lib.types.nullOr lib.types.str; - default = "git"; - description = '' - The subdomain to host the Forgejo instance under. + # Web server - If null, then Forgejo is hosted at the domain itself. - ''; - }; + services.nginx.enable = true; + services.nginx.virtualHosts.${srv.DOMAIN} = { + forceSSL = config.aether.https; + enableACME = config.aether.https; + extraConfig = '' + client_max_body_size 512M; + ''; + locations."/".proxyPass = "http://localhost:${builtins.toString srv.HTTP_PORT}"; + }; - user = lib.mkOption { - type = lib.types.str; - default = "git"; - description = '' - The user to run Forgejo with. - ''; - }; + security.acme.acceptTerms = config.aether.https; + security.acme.defaults.email = cfg.acmeEmail; - createUser = lib.mkOption { - type = lib.types.bool; - default = true; - description = '' - Whether to create the Forgejo user automatically. - ''; - }; + networking.firewall.allowedTCPPorts = + [ 80 ] ++ lib.optional config.aether.https 443; - templates = lib.mkOption { - type = lib.types.nullOr lib.types.path; - default = null; - description = '' - A directory of templates for customizing Forgejo's appearance. - ''; - }; + # Forgejo + + services.forgejo = { + enable = true; + user = cfg.user; + group = forgejo.user; + database.user = forgejo.user; + + settings.server = { + DOMAIN = lib.optionalString (!(builtins.isNull cfg.subdomain)) "${cfg.subdomain}." + + config.aether.domain; + ROOT_URL = "https://${srv.DOMAIN}/"; }; }; - config = - let - cfg = config.aether.forgejo; - forgejo = config.services.forgejo; - srv = forgejo.settings.server; - in { - # Web server - - services.nginx.enable = true; - services.nginx.virtualHosts.${srv.DOMAIN} = { - forceSSL = config.aether.https; - enableACME = config.aether.https; - extraConfig = '' - client_max_body_size 512M; - ''; - locations."/".proxyPass = "http://localhost:${builtins.toString srv.HTTP_PORT}"; - }; - - security.acme.acceptTerms = config.aether.https; - security.acme.defaults.email = cfg.acmeEmail; - - networking.firewall.allowedTCPPorts = - [ 80 ] ++ lib.optional config.aether.https; - - # Forgejo - - services.forgejo = { - enable = true; - user = cfg.user; - group = forgejo.user; - database.user = forgejo.user; - - settings.server = { - DOMAIN = lib.optionalString (!(builtins.isNull cfg.subdomain)) "${cfg.subdomain}." - + config.aether.domain; - ROOT_URL = "https://${srv.DOMAIN}/"; - }; - }; - - systemd.tmpfiles.rules = - lib.optional - (!(builtins.isNull cfg.templates)) - "L+ ${cfg.stateDir}/custom/templates - - - - ${cfg.templates}"; - } - // lib.mkIf cfg.createUser { - users.users.${forgejo.user} = { - home = forgejo.stateDir; - useDefaultShell = true; - group = forgejo.group; - isSystemUser = true; - }; - users.groups.${forgejo.group} = {}; - }; + systemd.tmpfiles.rules = + lib.optional + (!(builtins.isNull cfg.templates)) + "L+ ${cfg.stateDir}/custom/templates - - - - ${cfg.templates}"; +} +// lib.mkIf cfg.createUser { + users.users.${forgejo.user} = { + home = forgejo.stateDir; + useDefaultShell = true; + group = forgejo.group; + isSystemUser = true; + }; + users.groups.${forgejo.group} = {}; } diff --git a/modules/forgejo/options.nix b/modules/forgejo/options.nix new file mode 100644 index 0000000..9b392af --- /dev/null +++ b/modules/forgejo/options.nix @@ -0,0 +1,45 @@ +args@{ config, lib, ... }: +{ + options.aether = { + inherit (import ../options.nix args) + domain + https + acmeEmail; + + forgejo = { + subdomain = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = "git"; + description = '' + The subdomain to host the Forgejo instance under. + + If null, then Forgejo is hosted at the domain itself. + ''; + }; + + user = lib.mkOption { + type = lib.types.str; + default = "git"; + description = '' + The user to run Forgejo with. + ''; + }; + + createUser = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Whether to create the Forgejo user automatically. + ''; + }; + + templates = lib.mkOption { + type = lib.types.nullOr lib.types.path; + default = null; + description = '' + A directory of templates for customizing Forgejo's appearance. + ''; + }; + }; + }; +}