refactor: separate module options into options.nix

This commit is contained in:
Kiana Sheibani 2024-11-20 02:23:20 -05:00
parent cb94d7c6fb
commit c978882918
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 90 additions and 86 deletions

View file

@ -1,96 +1,55 @@
{ config, lib, ... }: { config, lib, ... }:
{ let
options.aether = { cfg = config.aether.forgejo;
inherit (import ../options.nix { inherit lib; }) domain https acmeEmail; forgejo = config.services.forgejo;
srv = forgejo.settings.server;
in {
imports = [ ./options.nix ];
forgejo = { # Web server
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. 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 { security.acme.acceptTerms = config.aether.https;
type = lib.types.str; security.acme.defaults.email = cfg.acmeEmail;
default = "git";
description = ''
The user to run Forgejo with.
'';
};
createUser = lib.mkOption { networking.firewall.allowedTCPPorts =
type = lib.types.bool; [ 80 ] ++ lib.optional config.aether.https 443;
default = true;
description = ''
Whether to create the Forgejo user automatically.
'';
};
templates = lib.mkOption { # Forgejo
type = lib.types.nullOr lib.types.path;
default = null; services.forgejo = {
description = '' enable = true;
A directory of templates for customizing Forgejo's appearance. 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 = systemd.tmpfiles.rules =
let lib.optional
cfg = config.aether.forgejo; (!(builtins.isNull cfg.templates))
forgejo = config.services.forgejo; "L+ ${cfg.stateDir}/custom/templates - - - - ${cfg.templates}";
srv = forgejo.settings.server; }
in { // lib.mkIf cfg.createUser {
# Web server users.users.${forgejo.user} = {
home = forgejo.stateDir;
services.nginx.enable = true; useDefaultShell = true;
services.nginx.virtualHosts.${srv.DOMAIN} = { group = forgejo.group;
forceSSL = config.aether.https; isSystemUser = true;
enableACME = config.aether.https; };
extraConfig = '' users.groups.${forgejo.group} = {};
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} = {};
};
} }

View file

@ -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.
'';
};
};
};
}