2022-04-10 11:54:58 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit
|
|
|
|
(lib)
|
2022-01-11 16:08:21 +01:00
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
2022-04-10 11:54:58 +02:00
|
|
|
;
|
2022-01-11 16:08:21 +01:00
|
|
|
|
2021-02-02 16:55:19 +01:00
|
|
|
cfg = config.my.services.gitea;
|
|
|
|
my = config.my;
|
|
|
|
|
|
|
|
domain = config.networking.domain;
|
2022-06-12 17:18:58 +02:00
|
|
|
hostname = config.networking.hostName;
|
|
|
|
fqdn = "${hostname}.${domain}";
|
2022-06-14 19:28:06 +02:00
|
|
|
|
|
|
|
giteaUser = "git";
|
2021-02-02 16:55:19 +01:00
|
|
|
in {
|
2022-04-10 11:54:58 +02:00
|
|
|
options.my.services.gitea = let
|
|
|
|
inherit (lib) types;
|
|
|
|
in {
|
2021-02-02 16:55:19 +01:00
|
|
|
enable = mkEnableOption "Personal Git hosting with Gitea";
|
|
|
|
|
|
|
|
privatePort = mkOption {
|
2021-02-02 18:24:28 +01:00
|
|
|
type = types.port;
|
2021-02-02 16:55:19 +01:00
|
|
|
default = 8082;
|
|
|
|
example = 8082;
|
|
|
|
description = "Port to serve the app";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
# use git as user to have `git clone git@git.domain`
|
2022-06-14 19:28:06 +02:00
|
|
|
users.users.${giteaUser} = {
|
2021-02-02 16:55:19 +01:00
|
|
|
description = "Gitea Service";
|
|
|
|
home = config.services.gitea.stateDir;
|
|
|
|
useDefaultShell = true;
|
2022-06-14 19:28:06 +02:00
|
|
|
group = giteaUser;
|
2021-02-02 16:55:19 +01:00
|
|
|
|
|
|
|
# the systemd service for the gitea module seems to hardcode the group as
|
|
|
|
# gitea, so, uh, just in case?
|
2022-04-10 11:54:58 +02:00
|
|
|
extraGroups = ["gitea"];
|
2021-02-02 16:55:19 +01:00
|
|
|
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
2022-06-14 19:28:06 +02:00
|
|
|
users.groups.${giteaUser} = {};
|
2021-02-02 16:55:19 +01:00
|
|
|
|
|
|
|
services.gitea = {
|
|
|
|
enable = true;
|
2022-06-14 19:28:06 +02:00
|
|
|
user = giteaUser;
|
2021-02-02 16:55:19 +01:00
|
|
|
domain = "git.${domain}";
|
|
|
|
appName = "Personal Forge";
|
|
|
|
rootUrl = "https://git.${domain}/";
|
|
|
|
httpAddress = "127.0.0.1";
|
|
|
|
httpPort = cfg.privatePort;
|
|
|
|
lfs.enable = true;
|
|
|
|
|
|
|
|
|
|
|
|
settings = {
|
2022-08-29 13:28:59 +02:00
|
|
|
log.LEVEL = "Warn"; # [ "Trace" "Debug" "Info" "Warn" "Error" "Critical" ]
|
2021-02-02 16:55:19 +01:00
|
|
|
other.SHOW_FOOTER_VERSION = false;
|
2021-04-09 19:43:51 +02:00
|
|
|
repository = {
|
|
|
|
ENABLE_PUSH_CREATE_USER = true;
|
2021-04-09 20:31:58 +02:00
|
|
|
DEFAULT_BRANCH = "main";
|
2021-04-09 19:43:51 +02:00
|
|
|
};
|
2022-08-29 13:28:59 +02:00
|
|
|
|
|
|
|
# NOTE: temporarily remove this for initial setup
|
|
|
|
service.DISABLE_REGISTRATION = true;
|
|
|
|
|
|
|
|
# only send cookies via HTTPS
|
|
|
|
session.COOKIE_SECURE = true;
|
2021-02-02 16:55:19 +01:00
|
|
|
};
|
|
|
|
|
2021-02-02 18:09:10 +01:00
|
|
|
# NixOS module uses `gitea dump` to backup repositories and the database,
|
2021-08-09 20:19:27 +02:00
|
|
|
# but it produces a single .zip file that's not very restic friendly.
|
2021-02-02 18:09:10 +01:00
|
|
|
# I configure my backup system manually below.
|
|
|
|
dump.enable = false;
|
2021-02-02 16:55:19 +01:00
|
|
|
|
|
|
|
database = {
|
|
|
|
type = "postgres";
|
|
|
|
# user needs to be the same as gitea user
|
2022-06-14 19:28:06 +02:00
|
|
|
user = giteaUser;
|
2021-02-02 16:55:19 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-02-02 18:09:10 +01:00
|
|
|
# FIXME: Borg *could* be backing up files while they're being edited by
|
|
|
|
# gitea, so it may produce corrupt files in the snapshot if I push stuff
|
|
|
|
# around midnight. I'm not sure how `gitea dump` handles this either,
|
|
|
|
# though.
|
2021-08-09 20:19:27 +02:00
|
|
|
my.services.restic-backup = {
|
2021-02-02 18:09:10 +01:00
|
|
|
paths = [
|
|
|
|
config.services.gitea.lfs.contentDir
|
|
|
|
config.services.gitea.repositoryRoot
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2022-06-14 17:58:05 +02:00
|
|
|
# NOTE: no need to use postgresql.ensureDatabases because the gitea module
|
|
|
|
# takes care of this automatically
|
2021-03-23 22:24:12 +01:00
|
|
|
services.postgresqlBackup = {
|
2022-04-10 11:54:58 +02:00
|
|
|
databases = ["gitea"];
|
2021-02-02 16:55:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
virtualHosts = {
|
|
|
|
"git.${domain}" = {
|
|
|
|
forceSSL = true;
|
2022-06-12 17:18:58 +02:00
|
|
|
useACMEHost = fqdn;
|
2021-02-02 16:55:19 +01:00
|
|
|
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${toString cfg.privatePort}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-04-09 16:53:05 +02:00
|
|
|
|
2022-06-12 17:18:58 +02:00
|
|
|
security.acme.certs.${fqdn}.extraDomainNames = ["git.${domain}"];
|
|
|
|
|
2021-04-09 16:53:05 +02:00
|
|
|
systemd.services.gitea.preStart = "${pkgs.coreutils}/bin/ln -sfT ${./templates} ${config.services.gitea.stateDir}/custom/templates";
|
2021-02-02 16:55:19 +01:00
|
|
|
};
|
|
|
|
}
|