2e751c0772
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.
110 lines
3.4 KiB
Nix
110 lines
3.4 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.services.mackerel-agent;
|
|
settingsFmt = pkgs.formats.toml {};
|
|
in {
|
|
options.services.mackerel-agent = {
|
|
enable = mkEnableOption "mackerel.io agent";
|
|
|
|
# the upstream package runs as root, but doesn't seem to be strictly
|
|
# necessary for basic functionality
|
|
runAsRoot = mkEnableOption "Whether to run as root.";
|
|
|
|
autoRetirement = mkEnableOption ''
|
|
Whether to automatically retire the host upon OS shutdown.
|
|
'';
|
|
|
|
apiKeyFile = mkOption {
|
|
type = types.path;
|
|
example = "/run/keys/mackerel-api-key";
|
|
description = ''
|
|
Path to file containing the Mackerel API key. The file should contain a
|
|
single line of the following form:
|
|
|
|
<literallayout>apikey = "EXAMPLE_API_KEY"</literallayout>
|
|
'';
|
|
};
|
|
|
|
settings = mkOption {
|
|
description = lib.mdDoc ''
|
|
Options for mackerel-agent.conf.
|
|
|
|
Documentation:
|
|
<https://mackerel.io/docs/entry/spec/agent>
|
|
'';
|
|
|
|
default = {};
|
|
example = {
|
|
verbose = false;
|
|
silent = false;
|
|
};
|
|
|
|
type = types.submodule {
|
|
freeformType = settingsFmt.type;
|
|
|
|
options.host_status = {
|
|
on_start = mkOption {
|
|
type = types.enum [ "working" "standby" "maintenance" "poweroff" ];
|
|
description = lib.mdDoc "Host status after agent startup.";
|
|
default = "working";
|
|
};
|
|
on_stop = mkOption {
|
|
type = types.enum [ "working" "standby" "maintenance" "poweroff" ];
|
|
description = lib.mdDoc "Host status after agent shutdown.";
|
|
default = "poweroff";
|
|
};
|
|
};
|
|
|
|
options.diagnostic =
|
|
mkEnableOption "Collect memory usage for the agent itself";
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
environment.systemPackages = with pkgs; [ mackerel-agent ];
|
|
|
|
environment.etc = {
|
|
"mackerel-agent/mackerel-agent.conf".source =
|
|
settingsFmt.generate "mackerel-agent.conf" cfg.settings;
|
|
"mackerel-agent/conf.d/api-key.conf".source = cfg.apiKeyFile;
|
|
};
|
|
|
|
services.mackerel-agent.settings = {
|
|
root = mkDefault "/var/lib/mackerel-agent";
|
|
pidfile = mkDefault "/run/mackerel-agent/mackerel-agent.pid";
|
|
|
|
# conf.d stores the symlink to cfg.apiKeyFile
|
|
include = mkDefault "/etc/mackerel-agent/conf.d/*.conf";
|
|
};
|
|
|
|
# upstream service file in https://git.io/JUt4Q
|
|
systemd.services.mackerel-agent = {
|
|
description = "mackerel.io agent";
|
|
after = [ "network-online.target" "nss-lookup.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
environment = {
|
|
MACKEREL_PLUGIN_WORKDIR = mkDefault "%C/mackerel-agent";
|
|
};
|
|
serviceConfig = {
|
|
DynamicUser = !cfg.runAsRoot;
|
|
PrivateTmp = mkDefault true;
|
|
CacheDirectory = "mackerel-agent";
|
|
ConfigurationDirectory = "mackerel-agent";
|
|
RuntimeDirectory = "mackerel-agent";
|
|
StateDirectory = "mackerel-agent";
|
|
ExecStart = "${pkgs.mackerel-agent}/bin/mackerel-agent supervise";
|
|
ExecStopPost = mkIf cfg.autoRetirement "${pkg.mackerel-agent}/bin/mackerel-agent retire -force";
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
LimitNOFILE = mkDefault 65536;
|
|
LimitNPROC = mkDefault 65536;
|
|
};
|
|
restartTriggers = [
|
|
config.environment.etc."mackerel-agent/mackerel-agent.conf".source
|
|
];
|
|
};
|
|
};
|
|
}
|