nixos/atop: Add configuration for atop services, allow to enable netatop, gpuatop, allow setuid wrapper
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Global configuration for atop.
|
||||
|
||||
{ config, lib, ... }:
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
@@ -12,11 +12,82 @@ in
|
||||
|
||||
options = {
|
||||
|
||||
programs.atop = {
|
||||
programs.atop = rec {
|
||||
|
||||
enable = mkEnableOption "Atop";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.atop;
|
||||
description = ''
|
||||
Which package to use for Atop.
|
||||
'';
|
||||
};
|
||||
|
||||
netatop = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to install and enable the netatop kernel module.
|
||||
'';
|
||||
};
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = config.boot.kernelPackages.netatop;
|
||||
description = ''
|
||||
Which package to use for netatop.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
atopgpu.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to install and enable the atopgpud daemon to get information about
|
||||
NVIDIA gpus.
|
||||
'';
|
||||
};
|
||||
|
||||
setuidWrapper.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = cfg.netatop.enable || cfg.atopgpu.enable;
|
||||
description = ''
|
||||
Whether to install a setuid wrapper for Atop. This is required to use some of
|
||||
the features as non-root user (e.g.: ipc information, netatop, atopgpu).
|
||||
Atop tries to drop the root privileges shortly after starting.
|
||||
'';
|
||||
};
|
||||
|
||||
atopsvc.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to enable the atop service responsible for storing statistics for
|
||||
long-term analysis.
|
||||
'';
|
||||
};
|
||||
atopRotate.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to enable the atop-rotate timer, which restarts the atop service
|
||||
daily to make sure the data files are rotate.
|
||||
'';
|
||||
};
|
||||
atopacct.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to enable the atopacct service which manages process accounting.
|
||||
This allows Atop to gather data about processes that disappeared in between
|
||||
two refresh intervals.
|
||||
'';
|
||||
};
|
||||
settings = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
default = { };
|
||||
example = {
|
||||
flags = "a1f";
|
||||
interval = 5;
|
||||
@@ -25,12 +96,51 @@ in
|
||||
Parameters to be written to <filename>/etc/atoprc</filename>.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf (cfg.settings != {}) {
|
||||
environment.etc.atoprc.text =
|
||||
concatStrings (mapAttrsToList (n: v: "${n} ${toString v}\n") cfg.settings);
|
||||
};
|
||||
config = mkIf cfg.enable (
|
||||
let
|
||||
atop =
|
||||
if cfg.atopgpu.enable then
|
||||
(cfg.package.override { withAtopgpu = true; })
|
||||
else
|
||||
cfg.package;
|
||||
packages = [ atop (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
|
||||
in
|
||||
{
|
||||
environment.etc = mkIf (cfg.settings != { }) {
|
||||
atoprc.text = concatStrings
|
||||
(mapAttrsToList
|
||||
(n: v: ''
|
||||
${n} ${toString v}
|
||||
'')
|
||||
cfg.settings);
|
||||
};
|
||||
environment.systemPackages = packages;
|
||||
boot.extraModulePackages = [ (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
|
||||
systemd =
|
||||
let
|
||||
mkSystemd = type: cond: name: {
|
||||
${name} = lib.mkIf cond {
|
||||
restartTriggers = packages;
|
||||
wantedBy = [ (if type == "services" then "multi-user.target" else if type == "timers" then "timers.target" else null) ];
|
||||
};
|
||||
};
|
||||
mkService = mkSystemd "services";
|
||||
mkTimer = mkSystemd "timers";
|
||||
in
|
||||
{
|
||||
inherit packages;
|
||||
services =
|
||||
mkService cfg.atopsvc.enable "atop"
|
||||
// mkService cfg.atopacct.enable "atopacct"
|
||||
// mkService cfg.netatop.enable "netatop"
|
||||
// mkService cfg.atopgpu.enable "atopgpu";
|
||||
timers = mkTimer cfg.atopRotate.enable "atop-rotate";
|
||||
};
|
||||
security.wrappers =
|
||||
lib.mkIf cfg.setuidWrapper.enable { atop = { source = "${atop}/bin/atop"; }; };
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user