1 # Global configuration for atop.
3 { config, lib, pkgs, ... }:
7 let cfg = config.programs.atop;
17 enable = mkEnableOption (lib.mdDoc "Atop");
22 defaultText = literalExpression "pkgs.atop";
23 description = lib.mdDoc ''
24 Which package to use for Atop.
32 description = lib.mdDoc ''
33 Whether to install and enable the netatop kernel module.
34 Note: this sets the kernel taint flag "O" for loading out-of-tree modules.
39 default = config.boot.kernelPackages.netatop;
40 defaultText = literalExpression "config.boot.kernelPackages.netatop";
41 description = lib.mdDoc ''
42 Which package to use for netatop.
47 atopgpu.enable = mkOption {
50 description = lib.mdDoc ''
51 Whether to install and enable the atopgpud daemon to get information about
56 setuidWrapper.enable = mkOption {
59 description = lib.mdDoc ''
60 Whether to install a setuid wrapper for Atop. This is required to use some of
61 the features as non-root user (e.g.: ipc information, netatop, atopgpu).
62 Atop tries to drop the root privileges shortly after starting.
66 atopService.enable = mkOption {
69 description = lib.mdDoc ''
70 Whether to enable the atop service responsible for storing statistics for
74 atopRotateTimer.enable = mkOption {
77 description = lib.mdDoc ''
78 Whether to enable the atop-rotate timer, which restarts the atop service
79 daily to make sure the data files are rotate.
82 atopacctService.enable = mkOption {
85 description = lib.mdDoc ''
86 Whether to enable the atopacct service which manages process accounting.
87 This allows Atop to gather data about processes that disappeared in between
88 two refresh intervals.
98 description = lib.mdDoc ''
99 Parameters to be written to {file}`/etc/atoprc`.
105 config = mkIf cfg.enable (
108 if cfg.atopgpu.enable then
109 (cfg.package.override { withAtopgpu = true; })
114 environment.etc = mkIf (cfg.settings != { }) {
115 atoprc.text = concatStrings
122 environment.systemPackages = [ atop (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
123 boot.extraModulePackages = [ (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
126 mkSystemd = type: cond: name: restartTriggers: {
127 ${name} = lib.mkIf cond {
128 inherit restartTriggers;
129 wantedBy = [ (if type == "services" then "multi-user.target" else if type == "timers" then "timers.target" else null) ];
132 mkService = mkSystemd "services";
133 mkTimer = mkSystemd "timers";
136 packages = [ atop (lib.mkIf cfg.netatop.enable cfg.netatop.package) ];
138 mkService cfg.atopService.enable "atop" [ atop ]
139 // lib.mkIf cfg.atopService.enable {
140 # always convert logs to newer version first
141 # XXX might trigger TimeoutStart but restarting atop.service will
142 # convert remainings logs and start eventually
143 atop.serviceConfig.ExecStartPre = pkgs.writeShellScript "atop-update-log-format" ''
145 for logfile in "$LOGPATH"/atop_*
147 ${atop}/bin/atopconvert "$logfile" "$logfile".new
148 # only replace old file if version was upgraded to avoid
149 # false positives for atop-rotate.service
150 if ! ${pkgs.diffutils}/bin/cmp -s "$logfile" "$logfile".new
152 ${pkgs.coreutils}/bin/mv -v -f "$logfile".new "$logfile"
157 // mkService cfg.atopacctService.enable "atopacct" [ atop ]
158 // mkService cfg.netatop.enable "netatop" [ cfg.netatop.package ]
159 // mkService cfg.atopgpu.enable "atopgpu" [ atop ];
160 timers = mkTimer cfg.atopRotateTimer.enable "atop-rotate" [ atop ];
163 security.wrappers = lib.mkIf cfg.setuidWrapper.enable {
168 source = "${atop}/bin/atop";