2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.pykms;
|
|
|
|
libDir = "/var/lib/pykms";
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
in
|
|
|
|
{
|
2020-04-24 23:36:52 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ peterhoeg ];
|
|
|
|
|
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "pykms" "verbose" ] "Use services.pykms.logLevel instead")
|
|
|
|
];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.pykms = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to enable the PyKMS service.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The IP address on which to listen.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2022-11-21 17:40:18 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 1688;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The port on which to listen.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
openFirewallPort = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether the listening port should be opened automatically.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
memoryLimit = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "64M";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "How much memory to use at most.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
2021-02-05 17:12:51 +00:00
|
|
|
type = types.enum [ "CRITICAL" "ERROR" "WARNING" "INFO" "DEBUG" "MININFO" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "INFO";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "How much to log";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2021-02-05 17:12:51 +00:00
|
|
|
default = [ ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Additional arguments";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewallPort [ cfg.port ];
|
|
|
|
|
|
|
|
systemd.services.pykms = {
|
|
|
|
description = "Python KMS";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
# python programs with DynamicUser = true require HOME to be set
|
|
|
|
environment.HOME = libDir;
|
|
|
|
serviceConfig = with pkgs; {
|
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = baseNameOf libDir;
|
|
|
|
ExecStartPre = "${getBin pykms}/libexec/create_pykms_db.sh ${libDir}/clients.db";
|
|
|
|
ExecStart = lib.concatStringsSep " " ([
|
|
|
|
"${getBin pykms}/bin/server"
|
2021-02-05 17:12:51 +00:00
|
|
|
"--logfile=STDOUT"
|
|
|
|
"--loglevel=${cfg.logLevel}"
|
|
|
|
"--sqlite=${libDir}/clients.db"
|
2020-04-24 23:36:52 +00:00
|
|
|
] ++ cfg.extraArgs ++ [
|
|
|
|
cfg.listenAddress
|
|
|
|
(toString cfg.port)
|
|
|
|
]);
|
|
|
|
ProtectHome = "tmpfs";
|
|
|
|
WorkingDirectory = libDir;
|
2020-05-03 17:38:23 +00:00
|
|
|
SyslogIdentifier = "pykms";
|
2020-04-24 23:36:52 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
MemoryLimit = cfg.memoryLimit;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|