3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/modules/services/misc/pykms.nix

91 lines
2.4 KiB
Nix
Raw Normal View History

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