forked from hacc/haccfiles
65 lines
1.4 KiB
Nix
65 lines
1.4 KiB
Nix
|
{pkgs, lib, config, ...}:
|
||
|
|
||
|
with lib;
|
||
|
let format = pkgs.formats.toml {};
|
||
|
in
|
||
|
{
|
||
|
options.services.keytracker = {
|
||
|
enable = mkOption {
|
||
|
default = false;
|
||
|
type = types.bool;
|
||
|
};
|
||
|
domain = mkOption {
|
||
|
default = "example.org";
|
||
|
type = types.str;
|
||
|
};
|
||
|
frontendPackage = mkOption {
|
||
|
default = pkgs.keytracker-frontend;
|
||
|
type = types.package;
|
||
|
};
|
||
|
serverPackage = mkOption {
|
||
|
default = pkgs.keytracker-server;
|
||
|
type = types.package;
|
||
|
};
|
||
|
stateDir = mkOption {
|
||
|
default = "/var/lib/keytracker";
|
||
|
type = types.str;
|
||
|
};
|
||
|
config = mkOption {
|
||
|
default = {};
|
||
|
type = format.type;
|
||
|
};
|
||
|
nginx = mkOption {
|
||
|
default = {};
|
||
|
type = types.attrs;
|
||
|
};
|
||
|
};
|
||
|
|
||
|
config =
|
||
|
let cfg = config.services.keytracker;
|
||
|
configfile = format.generate "config" cfg.config;
|
||
|
in {
|
||
|
services.nginx = mkIf cfg.enable {
|
||
|
enable = true;
|
||
|
virtualHosts.${cfg.domain} = {
|
||
|
root = cfg.frontendPackage.outPath;
|
||
|
} // cfg.nginx;
|
||
|
};
|
||
|
|
||
|
systemd.services = mkIf cfg.enable {
|
||
|
"keytracker" = {
|
||
|
enable = true;
|
||
|
description = "Keytracker backend server";
|
||
|
wantedBy = [ "multi-user.target" ];
|
||
|
serviceConfig.Type = "simple";
|
||
|
script = ''
|
||
|
mkdir -p ${cfg.stateDir}
|
||
|
cd ${cfg.stateDir}
|
||
|
ln -sf ${configfile} config
|
||
|
${cfg.serverPackage}/wrapped
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
}
|