1 # Global configuration for atop.
3 { config, lib, pkgs, ... }:
5 let cfg = config.programs.atop;
15 enable = lib.mkEnableOption "Atop, a tool for monitoring system resources";
17 package = lib.mkPackageOption pkgs "atop" { };
20 enable = lib.mkOption {
21 type = lib.types.bool;
24 Whether to install and enable the netatop kernel module.
25 Note: this sets the kernel taint flag "O" for loading out-of-tree modules.
28 package = lib.mkOption {
29 type = lib.types.package;
30 default = config.boot.kernelPackages.netatop;
31 defaultText = lib.literalExpression "config.boot.kernelPackages.netatop";
33 Which package to use for netatop.
38 atopgpu.enable = lib.mkOption {
39 type = lib.types.bool;
42 Whether to install and enable the atopgpud daemon to get information about
47 setuidWrapper.enable = lib.mkOption {
48 type = lib.types.bool;
51 Whether to install a setuid wrapper for Atop. This is required to use some of
52 the features as non-root user (e.g.: ipc information, netatop, atopgpu).
53 Atop tries to drop the root privileges shortly after starting.
57 atopService.enable = lib.mkOption {
58 type = lib.types.bool;
61 Whether to enable the atop service responsible for storing statistics for
65 atopRotateTimer.enable = lib.mkOption {
66 type = lib.types.bool;
69 Whether to enable the atop-rotate timer, which restarts the atop service
70 daily to make sure the data files are rotate.
73 atopacctService.enable = lib.mkOption {
74 type = lib.types.bool;
77 Whether to enable the atopacct service which manages process accounting.
78 This allows Atop to gather data about processes that disappeared in between
79 two refresh intervals.
82 settings = lib.mkOption {
83 type = lib.types.attrs;
90 Parameters to be written to {file}`/etc/atoprc`.
96 config = lib.mkIf cfg.enable (
99 if cfg.atopgpu.enable then
100 (cfg.package.override { withAtopgpu = true; })
105 environment.etc = lib.mkIf (cfg.settings != { }) {
106 atoprc.text = lib.concatStrings
109 ${n} ${builtins.toString v}
113 environment.systemPackages = [ atop (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
114 boot.extraModulePackages = [ (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
117 mkSystemd = type: name: restartTriggers: {
119 inherit restartTriggers;
120 wantedBy = [ (if type == "services" then "multi-user.target" else if type == "timers" then "timers.target" else null) ];
123 mkService = mkSystemd "services";
124 mkTimer = mkSystemd "timers";
127 packages = [ atop (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
128 services = lib.mkMerge [
129 (lib.mkIf cfg.atopService.enable (lib.recursiveUpdate
130 (mkService "atop" [ atop ])
132 # always convert logs to newer version first
133 # XXX might trigger TimeoutStart but restarting atop.service will
134 # convert remainings logs and start eventually
138 rm -f "$LOGPATH"/atop_*.new
139 for logfile in "$LOGPATH"/atop_*
141 ${atop}/bin/atopconvert "$logfile" "$logfile".new
142 # only replace old file if version was upgraded to avoid
143 # false positives for atop-rotate.service
144 if ! ${pkgs.diffutils}/bin/cmp -s "$logfile" "$logfile".new
146 mv -v -f "$logfile".new "$logfile"
153 (lib.mkIf cfg.atopacctService.enable (mkService "atopacct" [ atop ]))
154 (lib.mkIf cfg.netatop.enable (mkService "netatop" [ cfg.netatop.package ]))
155 (lib.mkIf cfg.atopgpu.enable (mkService "atopgpu" [ atop ]))
157 timers = lib.mkIf cfg.atopRotateTimer.enable (mkTimer "atop-rotate" [ atop ]);
160 security.wrappers = lib.mkIf cfg.setuidWrapper.enable {
165 source = "${atop}/bin/atop";