2024-12-10 20:26:33 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2017-07-25 15:20:24 +08:00
|
|
|
let
|
|
|
|
cfg = config.services.pykms;
|
2019-07-05 09:46:03 +08:00
|
|
|
libDir = "/var/lib/pykms";
|
2017-07-25 15:20:24 +08:00
|
|
|
|
2021-01-31 20:40:45 +08:00
|
|
|
in
|
|
|
|
{
|
2018-03-26 15:16:22 +08:00
|
|
|
meta.maintainers = with lib.maintainers; [ peterhoeg ];
|
2017-07-25 15:20:24 +08:00
|
|
|
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
2024-08-30 00:46:43 +02:00
|
|
|
(lib.mkRemovedOptionModule [ "services" "pykms" "verbose" ] "Use services.pykms.logLevel instead")
|
2019-12-10 02:51:19 +01:00
|
|
|
];
|
|
|
|
|
2017-07-25 15:20:24 +08:00
|
|
|
options = {
|
2019-08-13 21:52:01 +00:00
|
|
|
services.pykms = {
|
2024-08-30 00:46:43 +02:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2017-07-25 15:20:24 +08:00
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "Whether to enable the PyKMS service.";
|
2017-07-25 15:20:24 +08:00
|
|
|
};
|
|
|
|
|
2025-01-01 00:35:10 +08:00
|
|
|
package = lib.mkPackageOption pkgs "pykms" { };
|
|
|
|
|
2024-08-30 00:46:43 +02:00
|
|
|
listenAddress = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2017-07-25 15:20:24 +08:00
|
|
|
default = "0.0.0.0";
|
2025-01-01 00:59:56 +08:00
|
|
|
example = "::";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "The IP address on which to listen.";
|
2017-07-25 15:20:24 +08:00
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:43 +02:00
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2017-07-25 15:20:24 +08:00
|
|
|
default = 1688;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "The port on which to listen.";
|
2017-07-25 15:20:24 +08:00
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:43 +02:00
|
|
|
openFirewallPort = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2017-07-25 15:20:24 +08:00
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "Whether the listening port should be opened automatically.";
|
2017-07-25 15:20:24 +08:00
|
|
|
};
|
2018-03-26 15:16:22 +08:00
|
|
|
|
2024-08-30 00:46:43 +02:00
|
|
|
memoryLimit = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2018-03-26 15:16:22 +08:00
|
|
|
default = "64M";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "How much memory to use at most.";
|
2018-03-26 15:16:22 +08:00
|
|
|
};
|
2019-07-05 09:46:03 +08:00
|
|
|
|
2024-08-30 00:46:43 +02:00
|
|
|
logLevel = lib.mkOption {
|
2024-12-10 20:26:33 +01:00
|
|
|
type = lib.types.enum [
|
|
|
|
"CRITICAL"
|
|
|
|
"ERROR"
|
|
|
|
"WARNING"
|
|
|
|
"INFO"
|
|
|
|
"DEBUG"
|
|
|
|
"MININFO"
|
|
|
|
];
|
2019-07-05 09:46:03 +08:00
|
|
|
default = "INFO";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "How much to log";
|
2019-07-05 09:46:03 +08:00
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:43 +02:00
|
|
|
extraArgs = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2021-01-31 20:40:45 +08:00
|
|
|
default = [ ];
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "Additional arguments";
|
2019-07-05 09:46:03 +08:00
|
|
|
};
|
2017-07-25 15:20:24 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:43 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2017-07-25 15:20:24 +08:00
|
|
|
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewallPort [ cfg.port ];
|
|
|
|
|
2019-07-05 09:46:03 +08:00
|
|
|
systemd.services.pykms = {
|
2018-03-26 15:16:22 +08:00
|
|
|
description = "Python KMS";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
# python programs with DynamicUser = true require HOME to be set
|
2019-07-05 09:46:03 +08:00
|
|
|
environment.HOME = libDir;
|
2025-01-01 00:35:10 +08:00
|
|
|
serviceConfig = {
|
2018-03-26 15:16:22 +08:00
|
|
|
DynamicUser = true;
|
2019-07-05 09:46:03 +08:00
|
|
|
StateDirectory = baseNameOf libDir;
|
2025-01-01 00:35:10 +08:00
|
|
|
ExecStartPre = "${lib.getBin cfg.package}/libexec/create_pykms_db.sh ${libDir}/clients.db";
|
2024-12-10 20:26:33 +01:00
|
|
|
ExecStart = lib.concatStringsSep " " (
|
|
|
|
[
|
2025-01-01 00:35:10 +08:00
|
|
|
"${lib.getBin cfg.package}/bin/server"
|
2024-12-10 20:26:33 +01:00
|
|
|
"--logfile=STDOUT"
|
|
|
|
"--loglevel=${cfg.logLevel}"
|
|
|
|
"--sqlite=${libDir}/clients.db"
|
|
|
|
]
|
|
|
|
++ cfg.extraArgs
|
|
|
|
++ [
|
|
|
|
cfg.listenAddress
|
|
|
|
(toString cfg.port)
|
|
|
|
]
|
|
|
|
);
|
2019-07-05 09:46:03 +08:00
|
|
|
ProtectHome = "tmpfs";
|
|
|
|
WorkingDirectory = libDir;
|
2020-02-29 11:14:17 +00:00
|
|
|
SyslogIdentifier = "pykms";
|
2018-03-26 15:16:22 +08:00
|
|
|
Restart = "on-failure";
|
2023-02-06 11:25:48 +08:00
|
|
|
MemoryMax = cfg.memoryLimit;
|
2017-07-25 15:20:24 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|