stuebinm
35e2e6529d
Apparently, keytracker expects a toml file as config that may or may not be an instance of an entirely different specification of the spec than the one python understands.
64 lines
1.4 KiB
Nix
64 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 = types.str;
|
|
};
|
|
nginx = mkOption {
|
|
default = {};
|
|
type = types.attrs;
|
|
};
|
|
};
|
|
|
|
config =
|
|
let cfg = config.services.keytracker;
|
|
configfile = pkgs.writeText "keytracker-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
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
}
|