1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-28 00:22:13 +00:00
nixpkgs/nixos/modules/services/misc/pykms.nix

78 lines
2 KiB
Nix
Raw Normal View History

2017-07-25 08:20:24 +01:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.pykms;
in {
2018-03-26 08:16:22 +01:00
meta.maintainers = with lib.maintainers; [ peterhoeg ];
2017-07-25 08:20:24 +01:00
options = {
services.pykms = rec {
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.";
};
verbose = mkOption {
type = types.bool;
default = false;
description = "Show verbose output.";
};
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.";
};
2017-07-25 08:20:24 +01:00
};
};
config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewallPort [ cfg.port ];
2018-03-26 08:16:22 +01:00
systemd.services.pykms = let
home = "/var/lib/pykms";
in {
description = "Python KMS";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
# python programs with DynamicUser = true require HOME to be set
environment.HOME = home;
serviceConfig = with pkgs; {
DynamicUser = true;
StateDirectory = baseNameOf home;
ExecStartPre = "${getBin pykms}/bin/create_pykms_db.sh ${home}/clients.db";
ExecStart = lib.concatStringsSep " " ([
"${getBin pykms}/bin/server.py"
cfg.listenAddress
(toString cfg.port)
] ++ lib.optional cfg.verbose "--verbose");
WorkingDirectory = home;
Restart = "on-failure";
MemoryLimit = cfg.memoryLimit;
2017-07-25 08:20:24 +01:00
};
};
};
}