2021-03-30 21:09:09 +02:00
|
|
|
# A simple Gitea webhook to mirror all my repositories
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.my.services.lohr;
|
|
|
|
settingsFormat = pkgs.formats.yaml { };
|
|
|
|
|
2021-11-05 16:31:22 +01:00
|
|
|
lohrStateDirectory = "lohr";
|
|
|
|
lohrHome = "/var/lib/lohr/";
|
2021-03-30 21:09:09 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.services.lohr = with lib; {
|
|
|
|
enable = mkEnableOption "Automatic gitea repositories mirroring";
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 9192;
|
|
|
|
example = 8080;
|
|
|
|
description = "Internal port of the Lohr service";
|
|
|
|
};
|
|
|
|
|
|
|
|
setting = mkOption rec {
|
|
|
|
type = settingsFormat.type;
|
|
|
|
apply = recursiveUpdate default;
|
|
|
|
default = {
|
|
|
|
default_remotes = [
|
|
|
|
"git@github.com:ambroisie"
|
|
|
|
"git@git.sr.ht:~ambroisie"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
description = "Global settings configuration file";
|
|
|
|
};
|
|
|
|
|
|
|
|
sharedSecretFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "/run/secrets/lohr.env";
|
|
|
|
description = "Shared secret between lohr and Gitea hook";
|
|
|
|
};
|
2021-11-05 16:31:22 +01:00
|
|
|
|
|
|
|
sshKeyFile = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = "/run/secrets/lohr/ssh-key";
|
|
|
|
description = ''
|
|
|
|
The ssh key that should be used by lohr to mirror repositories
|
|
|
|
'';
|
|
|
|
};
|
2021-03-30 21:09:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.services.lohr = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
EnvironmentFile = [
|
|
|
|
cfg.sharedSecretFile
|
|
|
|
];
|
|
|
|
Environment = [
|
|
|
|
"ROCKET_PORT=${toString cfg.port}"
|
2021-04-19 21:59:11 +02:00
|
|
|
"ROCKET_LOG_LEVEL=normal"
|
2021-11-05 16:31:22 +01:00
|
|
|
"LOHR_HOME=${lohrHome}"
|
2021-03-30 21:09:09 +02:00
|
|
|
"LOHR_CONFIG="
|
|
|
|
];
|
|
|
|
ExecStart =
|
|
|
|
let
|
|
|
|
configFile = settingsFormat.generate "lohr-config.yaml" cfg.setting;
|
|
|
|
in
|
2023-07-23 19:58:40 +02:00
|
|
|
"${lib.getExe pkgs.ambroisie.lohr} --config ${configFile}";
|
2021-11-05 16:31:22 +01:00
|
|
|
StateDirectory = lohrStateDirectory;
|
|
|
|
WorkingDirectory = lohrHome;
|
2021-03-30 21:09:09 +02:00
|
|
|
User = "lohr";
|
|
|
|
Group = "lohr";
|
|
|
|
};
|
|
|
|
path = with pkgs; [
|
|
|
|
git
|
2022-05-31 13:54:34 +02:00
|
|
|
openssh
|
2021-03-30 21:09:09 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.lohr = {
|
|
|
|
isSystemUser = true;
|
2021-11-05 16:31:22 +01:00
|
|
|
home = lohrHome;
|
2021-03-30 21:09:09 +02:00
|
|
|
createHome = true;
|
|
|
|
group = "lohr";
|
|
|
|
};
|
|
|
|
users.groups.lohr = { };
|
|
|
|
|
2023-12-25 19:25:08 +01:00
|
|
|
my.services.nginx.virtualHosts = {
|
|
|
|
lohr = {
|
2021-08-24 23:05:10 +02:00
|
|
|
inherit (cfg) port;
|
2023-12-25 19:25:08 +01:00
|
|
|
};
|
|
|
|
};
|
2024-03-09 22:00:17 +01:00
|
|
|
|
|
|
|
# SSH key provisioning
|
|
|
|
systemd.tmpfiles.settings."10-lohr" = lib.mkIf (cfg.sshKeyFile != null) {
|
|
|
|
"${lohrHome}/.ssh" = {
|
|
|
|
d = {
|
|
|
|
user = "lohr";
|
|
|
|
group = "lohr";
|
|
|
|
mode = "0700";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
"${lohrHome}/.ssh/id_ed25519" = {
|
2024-04-02 12:25:34 +02:00
|
|
|
"L+" = {
|
2024-03-09 22:00:17 +01:00
|
|
|
user = "lohr";
|
|
|
|
group = "lohr";
|
|
|
|
mode = "0700";
|
|
|
|
argument = cfg.sshKeyFile;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-03-30 21:09:09 +02:00
|
|
|
};
|
|
|
|
}
|