the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
93 lines
2.5 KiB
Nix
93 lines
2.5 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
let
|
|
cfg = config.services.pykms;
|
|
libDir = "/var/lib/pykms";
|
|
|
|
in
|
|
{
|
|
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;
|
|
description = lib.mdDoc "Whether to enable the PyKMS service.";
|
|
};
|
|
|
|
listenAddress = mkOption {
|
|
type = types.str;
|
|
default = "0.0.0.0";
|
|
description = lib.mdDoc "The IP address on which to listen.";
|
|
};
|
|
|
|
port = mkOption {
|
|
type = types.int;
|
|
default = 1688;
|
|
description = lib.mdDoc "The port on which to listen.";
|
|
};
|
|
|
|
openFirewallPort = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = lib.mdDoc "Whether the listening port should be opened automatically.";
|
|
};
|
|
|
|
memoryLimit = mkOption {
|
|
type = types.str;
|
|
default = "64M";
|
|
description = lib.mdDoc "How much memory to use at most.";
|
|
};
|
|
|
|
logLevel = mkOption {
|
|
type = types.enum [ "CRITICAL" "ERROR" "WARNING" "INFO" "DEBUG" "MININFO" ];
|
|
default = "INFO";
|
|
description = lib.mdDoc "How much to log";
|
|
};
|
|
|
|
extraArgs = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [ ];
|
|
description = lib.mdDoc "Additional arguments";
|
|
};
|
|
};
|
|
};
|
|
|
|
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"
|
|
"--logfile=STDOUT"
|
|
"--loglevel=${cfg.logLevel}"
|
|
"--sqlite=${libDir}/clients.db"
|
|
] ++ cfg.extraArgs ++ [
|
|
cfg.listenAddress
|
|
(toString cfg.port)
|
|
]);
|
|
ProtectHome = "tmpfs";
|
|
WorkingDirectory = libDir;
|
|
SyslogIdentifier = "pykms";
|
|
Restart = "on-failure";
|
|
MemoryLimit = cfg.memoryLimit;
|
|
};
|
|
};
|
|
};
|
|
}
|