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: name: restartTriggers: {
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) ];
137 services = lib.mkMerge [
138 (lib.mkIf cfg.atopService.enable (lib.recursiveUpdate
139 (mkService "atop" [ atop ])
141 # always convert logs to newer version first
142 # XXX might trigger TimeoutStart but restarting atop.service will
143 # convert remainings logs and start eventually
147 for logfile in "$LOGPATH"/atop_*
149 ${atop}/bin/atopconvert "$logfile" "$logfile".new
150 # only replace old file if version was upgraded to avoid
151 # false positives for atop-rotate.service
152 if ! ${pkgs.diffutils}/bin/cmp -s "$logfile" "$logfile".new
154 ${pkgs.coreutils}/bin/mv -v -f "$logfile".new "$logfile"
156 ${pkgs.coreutils}/bin/rm -f "$logfile".new
161 (lib.mkIf cfg.atopacctService.enable (mkService "atopacct" [ atop ]))
162 (lib.mkIf cfg.netatop.enable (mkService "netatop" [ cfg.netatop.package ]))
163 (lib.mkIf cfg.atopgpu.enable (mkService "atopgpu" [ atop ]))
165 timers = lib.mkIf cfg.atopRotateTimer.enable (mkTimer "atop-rotate" [ atop ]);
168 security.wrappers = lib.mkIf cfg.setuidWrapper.enable {
173 source = "${atop}/bin/atop";