nixos-config/services/lohr.nix

78 lines
1.8 KiB
Nix
Raw Normal View History

2021-04-08 02:19:54 +02:00
{ config, lib, pkgs, ... }:
2021-03-28 22:08:19 +02:00
let
2022-01-11 16:08:21 +01:00
inherit (lib)
mkEnableOption
mkIf
mkOption
;
2021-03-28 22:08:19 +02:00
cfg = config.my.services.lohr;
my = config.my;
domain = config.networking.domain;
2021-04-08 02:19:54 +02:00
secrets = config.my.secrets;
lohrPkg =
let
flake = builtins.getFlake "github:alarsyo/lohr?rev=58503cc8b95c8b627f6ae7e56740609e91f323cd";
2021-04-08 02:19:54 +02:00
in
flake.defaultPackage."x86_64-linux"; # FIXME: use correct system
2021-03-28 22:08:19 +02:00
in
{
2022-01-11 16:08:21 +01:00
options.my.services.lohr = let inherit (lib) types; in {
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 = {
wantedBy = [ "multi-user.target" ];
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-01-11 16:08:21 +01:00
path = [ pkgs.git ];
2021-04-08 02:19:54 +02:00
};
users.users.lohr = {
isSystemUser = true;
home = cfg.home;
createHome = true;
group = "lohr";
};
users.groups.lohr = { };
2021-03-28 22:08:19 +02:00
services.nginx.virtualHosts = {
"lohr.${domain}" = {
forceSSL = true;
useACMEHost = domain;
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
};
};
};
};
}