diff --git a/nixos/modules/services/monitoring/mackerel-agent.nix b/nixos/modules/services/monitoring/mackerel-agent.nix index 0908ea9ca68e..4d2d2e6c5972 100644 --- a/nixos/modules/services/monitoring/mackerel-agent.nix +++ b/nixos/modules/services/monitoring/mackerel-agent.nix @@ -1,24 +1,21 @@ { 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"; + enable = lib.mkEnableOption "mackerel.io agent"; # the upstream package runs as root, but doesn't seem to be strictly # necessary for basic functionality - runAsRoot = mkEnableOption "running as root"; + runAsRoot = lib.mkEnableOption "running as root"; - autoRetirement = mkEnableOption '' + autoRetirement = lib.mkEnableOption '' retiring the host upon OS shutdown ''; - apiKeyFile = mkOption { - type = types.path; + apiKeyFile = lib.mkOption { + type = lib.types.path; example = "/run/keys/mackerel-api-key"; description = '' Path to file containing the Mackerel API key. The file should contain a @@ -28,7 +25,7 @@ in { ''; }; - settings = mkOption { + settings = lib.mkOption { description = '' Options for mackerel-agent.conf. @@ -42,29 +39,29 @@ in { silent = false; }; - type = types.submodule { + type = lib.types.submodule { freeformType = settingsFmt.type; options.host_status = { - on_start = mkOption { - type = types.enum [ "working" "standby" "maintenance" "poweroff" ]; + on_start = lib.mkOption { + type = lib.types.enum [ "working" "standby" "maintenance" "poweroff" ]; description = "Host status after agent startup."; default = "working"; }; - on_stop = mkOption { - type = types.enum [ "working" "standby" "maintenance" "poweroff" ]; + on_stop = lib.mkOption { + type = lib.types.enum [ "working" "standby" "maintenance" "poweroff" ]; description = "Host status after agent shutdown."; default = "poweroff"; }; }; options.diagnostic = - mkEnableOption "collecting memory usage for the agent itself"; + lib.mkEnableOption "collecting memory usage for the agent itself"; }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { environment.systemPackages = with pkgs; [ mackerel-agent ]; environment.etc = { @@ -74,11 +71,11 @@ in { }; services.mackerel-agent.settings = { - root = mkDefault "/var/lib/mackerel-agent"; - pidfile = mkDefault "/run/mackerel-agent/mackerel-agent.pid"; + root = lib.mkDefault "/var/lib/mackerel-agent"; + pidfile = lib.mkDefault "/run/mackerel-agent/mackerel-agent.pid"; # conf.d stores the symlink to cfg.apiKeyFile - include = mkDefault "/etc/mackerel-agent/conf.d/*.conf"; + include = lib.mkDefault "/etc/mackerel-agent/conf.d/*.conf"; }; # upstream service file in https://github.com/mackerelio/mackerel-agent/blob/master/packaging/rpm/src/mackerel-agent.service @@ -88,20 +85,20 @@ in { after = [ "network-online.target" "nss-lookup.target" ]; wantedBy = [ "multi-user.target" ]; environment = { - MACKEREL_PLUGIN_WORKDIR = mkDefault "%C/mackerel-agent"; + MACKEREL_PLUGIN_WORKDIR = lib.mkDefault "%C/mackerel-agent"; }; serviceConfig = { DynamicUser = !cfg.runAsRoot; - PrivateTmp = mkDefault true; + PrivateTmp = lib.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 "${pkgs.mackerel-agent}/bin/mackerel-agent retire -force"; + ExecStopPost = lib.mkIf cfg.autoRetirement "${pkgs.mackerel-agent}/bin/mackerel-agent retire -force"; ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; - LimitNOFILE = mkDefault 65536; - LimitNPROC = mkDefault 65536; + LimitNOFILE = lib.mkDefault 65536; + LimitNPROC = lib.mkDefault 65536; }; restartTriggers = [ config.environment.etc."mackerel-agent/mackerel-agent.conf".source