2021-01-31 17:46:46 +01:00
|
|
|
# A low-ressource, full-featured git forge.
|
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.my.services.gitea;
|
|
|
|
in
|
|
|
|
{
|
2021-02-03 12:09:54 +01:00
|
|
|
options.my.services.gitea = with lib; {
|
|
|
|
enable = mkEnableOption "Gitea";
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
2021-02-18 01:18:01 +01:00
|
|
|
default = 3042;
|
2021-02-03 12:09:54 +01:00
|
|
|
example = 8080;
|
|
|
|
description = "Internal port";
|
|
|
|
};
|
2022-04-08 20:49:48 +02:00
|
|
|
mail = {
|
|
|
|
enable = mkEnableOption {
|
|
|
|
description = "mailer configuration";
|
|
|
|
};
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "smtp.example.com:465";
|
|
|
|
description = "Host for the mail account";
|
|
|
|
};
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "gitea@example.com";
|
|
|
|
description = "User for the mail account";
|
|
|
|
};
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "/run/secrets/gitea-mail-password.txt";
|
|
|
|
description = "Password for the mail account";
|
|
|
|
};
|
|
|
|
type = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "smtp";
|
|
|
|
example = "smtp";
|
|
|
|
description = "Password for the mail account";
|
|
|
|
};
|
|
|
|
tls = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
example = false;
|
|
|
|
description = "Use TLS for connection";
|
|
|
|
};
|
|
|
|
};
|
2021-01-31 17:46:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2021-08-24 23:05:10 +02:00
|
|
|
services.gitea =
|
|
|
|
let
|
2022-04-08 20:49:48 +02:00
|
|
|
inherit (config.networking) domain;
|
|
|
|
giteaDomain = "gitea.${domain}";
|
2021-08-24 23:05:10 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
enable = true;
|
2021-02-03 12:09:54 +01:00
|
|
|
|
2021-08-24 23:05:10 +02:00
|
|
|
appName = "Ambroisie's forge";
|
|
|
|
httpPort = cfg.port;
|
|
|
|
domain = giteaDomain;
|
|
|
|
rootUrl = "https://${giteaDomain}";
|
2021-02-03 12:09:54 +01:00
|
|
|
|
2021-08-24 23:05:10 +02:00
|
|
|
user = "git";
|
|
|
|
lfs.enable = true;
|
2021-02-03 12:09:54 +01:00
|
|
|
|
2021-08-24 23:05:10 +02:00
|
|
|
useWizard = false;
|
2021-02-03 12:09:54 +01:00
|
|
|
|
2021-08-24 23:05:10 +02:00
|
|
|
database = {
|
|
|
|
type = "postgres"; # Automatic setup
|
|
|
|
user = "git"; # User needs to be the same as gitea user
|
|
|
|
};
|
2021-02-07 21:43:15 +01:00
|
|
|
|
2021-08-24 23:05:10 +02:00
|
|
|
# NixOS module uses `gitea dump` to backup repositories and the database,
|
|
|
|
# but it produces a single .zip file that's not very backup friendly.
|
|
|
|
# I configure my backup system manually below.
|
|
|
|
dump.enable = false;
|
2022-04-08 20:49:48 +02:00
|
|
|
|
|
|
|
mailerPasswordFile = lib.mkIf cfg.mail.enable cfg.mail.passwordFile;
|
|
|
|
|
|
|
|
settings = {
|
|
|
|
mailer = lib.mkIf cfg.mail.enable {
|
|
|
|
ENABLED = true;
|
|
|
|
HOST = cfg.mail.host;
|
|
|
|
FROM = cfg.mail.user;
|
|
|
|
USER = cfg.mail.user;
|
|
|
|
MAILER_TYPE = cfg.mail.type;
|
|
|
|
IS_TLS_ENABLED = cfg.mail.tls;
|
|
|
|
};
|
2022-08-31 17:19:58 +02:00
|
|
|
|
|
|
|
service = {
|
|
|
|
DISABLE_REGISTRATION = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
session = {
|
|
|
|
# only send cookies via HTTPS
|
|
|
|
COOKIE_SECURE = true;
|
|
|
|
};
|
2022-04-08 20:49:48 +02:00
|
|
|
};
|
2021-08-24 23:05:10 +02:00
|
|
|
};
|
2021-01-31 17:46:46 +01:00
|
|
|
|
2021-02-03 12:09:54 +01:00
|
|
|
users.users.git = {
|
|
|
|
description = "Gitea Service";
|
|
|
|
home = config.services.gitea.stateDir;
|
|
|
|
useDefaultShell = true;
|
|
|
|
group = "git";
|
|
|
|
|
|
|
|
# The service for gitea seems to hardcode the group as
|
|
|
|
# gitea, so, uh, just in case?
|
|
|
|
extraGroups = [ "gitea" ];
|
|
|
|
|
|
|
|
isSystemUser = true;
|
2021-01-31 17:46:46 +01:00
|
|
|
};
|
2021-02-03 12:09:54 +01:00
|
|
|
users.groups.git = { };
|
2021-01-31 17:46:46 +01:00
|
|
|
|
|
|
|
# Proxy to Gitea
|
2021-08-24 23:05:10 +02:00
|
|
|
my.services.nginx.virtualHosts = [
|
|
|
|
{
|
|
|
|
subdomain = "gitea";
|
|
|
|
inherit (cfg) port;
|
|
|
|
}
|
|
|
|
];
|
2021-02-07 21:43:15 +01:00
|
|
|
|
|
|
|
my.services.backup = {
|
|
|
|
paths = [
|
|
|
|
config.services.gitea.lfs.contentDir
|
|
|
|
config.services.gitea.repositoryRoot
|
|
|
|
];
|
|
|
|
};
|
2021-01-31 17:46:46 +01:00
|
|
|
};
|
|
|
|
}
|