nixos/services.below: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-30 00:46:55 +02:00
parent 7123ef8458
commit 66ea353e1c

View File

@ -1,32 +1,31 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.below;
cfgContents = concatStringsSep "\n" (
mapAttrsToList (n: v: ''${n} = "${v}"'') (filterAttrs (_k: v: v != null) {
cfgContents = lib.concatStringsSep "\n" (
lib.mapAttrsToList (n: v: ''${n} = "${v}"'') (lib.filterAttrs (_k: v: v != null) {
log_dir = cfg.dirs.log;
store_dir = cfg.dirs.store;
cgroup_filter_out = cfg.cgroupFilterOut;
})
);
mkDisableOption = n: mkOption {
type = types.bool;
mkDisableOption = n: lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to enable ${n}.";
};
optionalType = ty: x: mkOption (x // {
optionalType = ty: x: lib.mkOption (x // {
description = x.description;
type = (types.nullOr ty);
type = (lib.types.nullOr ty);
default = null;
});
optionalPath = optionalType types.path;
optionalStr = optionalType types.str;
optionalInt = optionalType types.int;
optionalPath = optionalType lib.types.path;
optionalStr = optionalType lib.types.str;
optionalInt = optionalType lib.types.int;
in {
options = {
services.below = {
enable = mkEnableOption "'below' resource monitor";
enable = lib.mkEnableOption "'below' resource monitor";
cgroupFilterOut = optionalStr {
description = "A regexp matching the full paths of cgroups whose data shouldn't be collected";
@ -34,10 +33,10 @@ in {
};
collect = {
diskStats = mkDisableOption "dist_stat collection";
ioStats = mkEnableOption "io.stat collection for cgroups";
ioStats = lib.mkEnableOption "io.stat collection for cgroups";
exitStats = mkDisableOption "eBPF-based exitstats";
};
compression.enable = mkEnableOption "data compression";
compression.enable = lib.mkEnableOption "data compression";
retention = {
size = optionalInt {
description = ''
@ -75,7 +74,7 @@ in {
};
};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
environment.systemPackages = [ pkgs.below ];
# /etc/below.conf is also refered to by the `below` CLI tool,
# so this can't be a store-only file whose path is passed to the service
@ -90,14 +89,14 @@ in {
serviceConfig.ExecStart = [
""
("${lib.getExe pkgs.below} record " + (concatStringsSep " " (
optional (!cfg.collect.diskStats) "--disable-disk-stat" ++
optional cfg.collect.ioStats "--collect-io-stat" ++
optional (!cfg.collect.exitStats) "--disable-exitstats" ++
optional cfg.compression.enable "--compress" ++
("${lib.getExe pkgs.below} record " + (lib.concatStringsSep " " (
lib.optional (!cfg.collect.diskStats) "--disable-disk-stat" ++
lib.optional cfg.collect.ioStats "--collect-io-stat" ++
lib.optional (!cfg.collect.exitStats) "--disable-exitstats" ++
lib.optional cfg.compression.enable "--compress" ++
optional (cfg.retention.size != null) "--store-size-limit ${toString cfg.retention.size}" ++
optional (cfg.retention.time != null) "--retain-for-s ${toString cfg.retention.time}"
lib.optional (cfg.retention.size != null) "--store-size-limit ${toString cfg.retention.size}" ++
lib.optional (cfg.retention.time != null) "--retain-for-s ${toString cfg.retention.time}"
)))
];
};