nixos/services.collectd: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-30 00:46:55 +02:00
parent 5ced735a89
commit c39797b55e

View File

@ -1,7 +1,4 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.collectd;
@ -28,10 +25,10 @@ let
};
in {
options.services.collectd = with types; {
enable = mkEnableOption "collectd agent";
options.services.collectd = with lib.types; {
enable = lib.mkEnableOption "collectd agent";
validateConfig = mkOption {
validateConfig = lib.mkOption {
default = true;
description = ''
Validate the syntax of collectd configuration file at build time.
@ -41,9 +38,9 @@ in {
type = types.bool;
};
package = mkPackageOption pkgs "collectd" { };
package = lib.mkPackageOption pkgs "collectd" { };
buildMinimalPackage = mkOption {
buildMinimalPackage = lib.mkOption {
default = false;
description = ''
Build a minimal collectd package with only the configured `services.collectd.plugins`
@ -51,7 +48,7 @@ in {
type = bool;
};
user = mkOption {
user = lib.mkOption {
default = "collectd";
description = ''
User under which to run collectd.
@ -59,7 +56,7 @@ in {
type = nullOr str;
};
dataDir = mkOption {
dataDir = lib.mkOption {
default = "/var/lib/collectd";
description = ''
Data directory for collectd agent.
@ -67,7 +64,7 @@ in {
type = path;
};
autoLoadPlugin = mkOption {
autoLoadPlugin = lib.mkOption {
default = false;
description = ''
Enable plugin autoloading.
@ -75,7 +72,7 @@ in {
type = bool;
};
include = mkOption {
include = lib.mkOption {
default = [];
description = ''
Additional paths to load config from.
@ -83,7 +80,7 @@ in {
type = listOf str;
};
plugins = mkOption {
plugins = lib.mkOption {
default = {};
example = { cpu = ""; memory = ""; network = "Server 192.168.1.1 25826"; };
description = ''
@ -92,7 +89,7 @@ in {
type = attrsOf lines;
};
extraConfig = mkOption {
extraConfig = lib.mkOption {
default = "";
description = ''
Extra configuration for collectd. Use mkBefore to add lines before the
@ -103,11 +100,11 @@ in {
};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
# 1200 is after the default (1000) but before mkAfter (1500).
services.collectd.extraConfig = lib.mkOrder 1200 ''
${baseDirLine}
AutoLoadPlugin ${boolToString cfg.autoLoadPlugin}
AutoLoadPlugin ${lib.boolToString cfg.autoLoadPlugin}
Hostname "${config.networking.hostName}"
LoadPlugin syslog
@ -116,14 +113,14 @@ in {
NotifyLevel "OKAY"
</Plugin>
${concatStrings (mapAttrsToList (plugin: pluginConfig: ''
${lib.concatStrings (lib.mapAttrsToList (plugin: pluginConfig: ''
LoadPlugin ${plugin}
<Plugin "${plugin}">
${pluginConfig}
</Plugin>
'') cfg.plugins)}
${concatMapStrings (f: ''
${lib.concatMapStrings (f: ''
Include "${f}"
'') cfg.include}
'';
@ -145,14 +142,14 @@ in {
};
};
users.users = optionalAttrs (cfg.user == "collectd") {
users.users = lib.optionalAttrs (cfg.user == "collectd") {
collectd = {
isSystemUser = true;
group = "collectd";
};
};
users.groups = optionalAttrs (cfg.user == "collectd") {
users.groups = lib.optionalAttrs (cfg.user == "collectd") {
collectd = {};
};
};