nixpkgs/nixos/modules/services/misc/pykms.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.5 KiB
Nix
Raw Normal View History

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