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-03-28 22:08:19 +02:00
|
|
|
cfg = config.my.services.lohr;
|
|
|
|
my = config.my;
|
2022-06-12 17:18:58 +02:00
|
|
|
|
2021-03-28 22:08:19 +02:00
|
|
|
domain = config.networking.domain;
|
2022-06-12 17:18:58 +02:00
|
|
|
hostname = config.networking.hostName;
|
|
|
|
fqdn = "${hostname}.${domain}";
|
|
|
|
|
2021-04-08 02:19:54 +02:00
|
|
|
secrets = config.my.secrets;
|
2022-04-10 11:54:58 +02:00
|
|
|
lohrPkg = let
|
|
|
|
flake = builtins.getFlake "github:alarsyo/lohr?rev=58503cc8b95c8b627f6ae7e56740609e91f323cd";
|
|
|
|
in
|
2021-04-08 02:19:54 +02:00
|
|
|
flake.defaultPackage."x86_64-linux"; # FIXME: use correct system
|
2022-04-10 11:54:58 +02:00
|
|
|
in {
|
|
|
|
options.my.services.lohr = let
|
|
|
|
inherit (lib) types;
|
|
|
|
in {
|
2022-01-11 16:08:21 +01:00
|
|
|
enable = mkEnableOption "Lohr Mirroring Daemon";
|
2021-03-28 22:08:19 +02:00
|
|
|
|
|
|
|
home = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/lohr";
|
|
|
|
example = "/var/lib/lohr";
|
|
|
|
description = "Home for the lohr service, where data will be stored";
|
|
|
|
};
|
2021-04-08 02:19:54 +02:00
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8080;
|
|
|
|
example = 8080;
|
|
|
|
description = "Internal port for Lohr daemon";
|
|
|
|
};
|
2021-03-28 22:08:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-04-08 02:19:54 +02:00
|
|
|
systemd.services.lohr = {
|
2022-04-10 11:54:58 +02:00
|
|
|
wantedBy = ["multi-user.target"];
|
2021-04-08 02:19:54 +02:00
|
|
|
serviceConfig = {
|
|
|
|
Environment = [
|
|
|
|
"ROCKET_PORT=${toString cfg.port}"
|
|
|
|
"ROCKET_LOG_LEVEL=normal"
|
|
|
|
"LOHR_HOME=${cfg.home}"
|
|
|
|
];
|
2022-03-11 17:26:54 +01:00
|
|
|
EnvironmentFile = config.age.secrets."lohr/shared-secret".path;
|
2021-04-08 02:19:54 +02:00
|
|
|
ExecStart = "${lohrPkg}/bin/lohr";
|
|
|
|
StateDirectory = "lohr";
|
|
|
|
WorkingDirectory = "/var/lib/lohr";
|
|
|
|
User = "lohr";
|
|
|
|
Group = "lohr";
|
|
|
|
};
|
2022-05-02 13:26:00 +02:00
|
|
|
path = [
|
|
|
|
pkgs.git
|
|
|
|
pkgs.openssh
|
|
|
|
];
|
2021-04-08 02:19:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
users.users.lohr = {
|
|
|
|
isSystemUser = true;
|
|
|
|
home = cfg.home;
|
|
|
|
createHome = true;
|
|
|
|
group = "lohr";
|
|
|
|
};
|
2022-04-10 11:54:58 +02:00
|
|
|
users.groups.lohr = {};
|
2021-04-08 02:19:54 +02:00
|
|
|
|
2021-03-28 22:08:19 +02:00
|
|
|
services.nginx.virtualHosts = {
|
|
|
|
"lohr.${domain}" = {
|
|
|
|
forceSSL = true;
|
2022-06-12 17:18:58 +02:00
|
|
|
useACMEHost = fqdn;
|
2021-03-28 22:08:19 +02:00
|
|
|
|
|
|
|
locations."/" = {
|
2021-04-08 02:19:54 +02:00
|
|
|
proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
2021-03-28 22:08:19 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-06-12 17:18:58 +02:00
|
|
|
|
|
|
|
security.acme.certs.${fqdn}.extraDomainNames = ["lohr.${domain}"];
|
2021-03-28 22:08:19 +02:00
|
|
|
};
|
|
|
|
}
|