2013-05-23 13:04:07 +02:00
|
|
|
# Global configuration for atop.
|
|
|
|
|
2021-05-14 02:11:05 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-05-23 13:04:07 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2013-05-23 13:04:07 +02:00
|
|
|
|
|
|
|
let cfg = config.programs.atop;
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2021-05-14 02:11:05 +02:00
|
|
|
programs.atop = rec {
|
2013-05-23 13:04:07 +02:00
|
|
|
|
2021-05-14 02:11:05 +02:00
|
|
|
enable = mkEnableOption "Atop";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.atop;
|
2021-05-21 23:12:27 +02:00
|
|
|
defaultText = "pkgs.atop";
|
2021-05-14 02:11:05 +02:00
|
|
|
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.
|
2021-05-16 21:43:20 +02:00
|
|
|
Note: this sets the kernel taint flag "O" for loading out-of-tree modules.
|
2021-05-14 02:11:05 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = config.boot.kernelPackages.netatop;
|
2021-05-21 23:12:27 +02:00
|
|
|
defaultText = "config.boot.kernelPackages.netatop";
|
2021-05-14 02:11:05 +02:00
|
|
|
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;
|
2021-05-16 18:19:27 +02:00
|
|
|
default = false;
|
2021-05-14 02:11:05 +02:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-05-16 18:19:27 +02:00
|
|
|
atopService.enable = mkOption {
|
2021-05-14 02:11:05 +02:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the atop service responsible for storing statistics for
|
|
|
|
long-term analysis.
|
|
|
|
'';
|
|
|
|
};
|
2021-05-16 18:19:27 +02:00
|
|
|
atopRotateTimer.enable = mkOption {
|
2021-05-14 02:11:05 +02:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2021-05-16 18:19:27 +02:00
|
|
|
atopacctService.enable = mkOption {
|
2021-05-14 02:11:05 +02:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2013-05-23 13:04:07 +02:00
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrs;
|
2021-05-14 02:11:05 +02:00
|
|
|
default = { };
|
2013-05-23 13:04:07 +02:00
|
|
|
example = {
|
|
|
|
flags = "a1f";
|
|
|
|
interval = 5;
|
|
|
|
};
|
|
|
|
description = ''
|
2014-06-24 21:23:14 +02:00
|
|
|
Parameters to be written to <filename>/etc/atoprc</filename>.
|
2013-05-23 13:04:07 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-05-14 02:11:05 +02:00
|
|
|
config = mkIf cfg.enable (
|
|
|
|
let
|
|
|
|
atop =
|
|
|
|
if cfg.atopgpu.enable then
|
|
|
|
(cfg.package.override { withAtopgpu = true; })
|
|
|
|
else
|
|
|
|
cfg.package;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
environment.etc = mkIf (cfg.settings != { }) {
|
|
|
|
atoprc.text = concatStrings
|
|
|
|
(mapAttrsToList
|
|
|
|
(n: v: ''
|
|
|
|
${n} ${toString v}
|
|
|
|
'')
|
|
|
|
cfg.settings);
|
|
|
|
};
|
2021-05-16 22:00:24 +02:00
|
|
|
environment.systemPackages = [ atop (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
|
2021-05-14 02:11:05 +02:00
|
|
|
boot.extraModulePackages = [ (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
|
|
|
|
systemd =
|
|
|
|
let
|
2021-05-16 22:00:24 +02:00
|
|
|
mkSystemd = type: cond: name: restartTriggers: {
|
2021-05-14 02:11:05 +02:00
|
|
|
${name} = lib.mkIf cond {
|
2021-05-16 22:00:24 +02:00
|
|
|
inherit restartTriggers;
|
2021-05-14 02:11:05 +02:00
|
|
|
wantedBy = [ (if type == "services" then "multi-user.target" else if type == "timers" then "timers.target" else null) ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
mkService = mkSystemd "services";
|
|
|
|
mkTimer = mkSystemd "timers";
|
|
|
|
in
|
|
|
|
{
|
2021-05-16 22:00:24 +02:00
|
|
|
packages = [ atop (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
|
2021-05-14 02:11:05 +02:00
|
|
|
services =
|
2021-05-16 22:00:24 +02:00
|
|
|
mkService cfg.atopService.enable "atop" [ atop ]
|
|
|
|
// mkService cfg.atopacctService.enable "atopacct" [ atop ]
|
|
|
|
// mkService cfg.netatop.enable "netatop" [ cfg.netatop.package ]
|
|
|
|
// mkService cfg.atopgpu.enable "atopgpu" [ atop ];
|
|
|
|
timers = mkTimer cfg.atopRotateTimer.enable "atop-rotate" [ atop ];
|
2021-05-14 02:11:05 +02:00
|
|
|
};
|
|
|
|
security.wrappers =
|
|
|
|
lib.mkIf cfg.setuidWrapper.enable { atop = { source = "${atop}/bin/atop"; }; };
|
|
|
|
}
|
|
|
|
);
|
2013-05-23 13:04:07 +02:00
|
|
|
}
|