2017-07-24 07:47:59 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2022-05-13 22:53:16 +02:00
|
|
|
inherit (pkgs.stdenv.hostPlatform) isDarwin;
|
2020-02-02 00:39:17 +01:00
|
|
|
|
2017-07-24 07:47:59 +02:00
|
|
|
cfg = config.programs.htop;
|
|
|
|
|
2021-05-19 01:36:08 +02:00
|
|
|
formatOption = n: v:
|
|
|
|
let v' = if isBool v then (if v then "1" else "0") else toString v;
|
|
|
|
in "${n}=${v'}";
|
2017-07-24 07:47:59 +02:00
|
|
|
|
2021-07-29 13:53:42 +02:00
|
|
|
formatMeters = side: meters: {
|
|
|
|
"${side}_meters" = concatMap (mapAttrsToList (x: _: x)) meters;
|
|
|
|
"${side}_meter_modes" = concatMap (mapAttrsToList (_: y: y)) meters;
|
|
|
|
};
|
2021-05-19 01:36:08 +02:00
|
|
|
leftMeters = formatMeters "left";
|
|
|
|
rightMeters = formatMeters "right";
|
2017-07-24 07:47:59 +02:00
|
|
|
|
|
|
|
fields = {
|
|
|
|
PID = 0;
|
|
|
|
COMM = 1;
|
|
|
|
STATE = 2;
|
|
|
|
PPID = 3;
|
|
|
|
PGRP = 4;
|
|
|
|
SESSION = 5;
|
|
|
|
TTY_NR = 6;
|
|
|
|
TPGID = 7;
|
|
|
|
MINFLT = 9;
|
|
|
|
MAJFLT = 11;
|
|
|
|
PRIORITY = 17;
|
|
|
|
NICE = 18;
|
|
|
|
STARTTIME = 20;
|
|
|
|
PROCESSOR = 37;
|
|
|
|
M_SIZE = 38;
|
|
|
|
M_RESIDENT = 39;
|
|
|
|
ST_UID = 45;
|
|
|
|
PERCENT_CPU = 46;
|
|
|
|
PERCENT_MEM = 47;
|
|
|
|
USER = 48;
|
|
|
|
TIME = 49;
|
|
|
|
NLWP = 50;
|
|
|
|
TGID = 51;
|
2022-06-05 11:50:13 +02:00
|
|
|
PERCENT_NORM_CPU = 52;
|
|
|
|
ELAPSED = 53;
|
2017-07-24 07:47:59 +02:00
|
|
|
CMINFLT = 10;
|
|
|
|
CMAJFLT = 12;
|
|
|
|
UTIME = 13;
|
|
|
|
STIME = 14;
|
|
|
|
CUTIME = 15;
|
|
|
|
CSTIME = 16;
|
|
|
|
M_SHARE = 40;
|
|
|
|
M_TRS = 41;
|
|
|
|
M_DRS = 42;
|
|
|
|
M_LRS = 43;
|
|
|
|
M_DT = 44;
|
|
|
|
CTID = 99;
|
|
|
|
VPID = 100;
|
|
|
|
VXID = 102;
|
|
|
|
RCHAR = 102;
|
|
|
|
WCHAR = 103;
|
|
|
|
SYSCR = 104;
|
|
|
|
SYSCW = 105;
|
|
|
|
RBYTES = 106;
|
|
|
|
WBYTES = 107;
|
|
|
|
CNCLWB = 108;
|
|
|
|
IO_READ_RATE = 109;
|
|
|
|
IO_WRITE_RATE = 110;
|
|
|
|
IO_RATE = 111;
|
|
|
|
CGROUP = 112;
|
|
|
|
OOM = 113;
|
|
|
|
IO_PRIORITY = 114;
|
2020-09-06 10:58:37 +02:00
|
|
|
M_PSS = 118;
|
|
|
|
M_SWAP = 119;
|
|
|
|
M_PSSWP = 120;
|
2017-07-24 07:47:59 +02:00
|
|
|
};
|
|
|
|
|
2022-05-13 22:53:16 +02:00
|
|
|
defaultFields = with fields; [
|
|
|
|
PID
|
|
|
|
USER
|
|
|
|
PRIORITY
|
|
|
|
NICE
|
|
|
|
M_SIZE
|
|
|
|
M_RESIDENT
|
|
|
|
M_SHARE
|
|
|
|
STATE
|
|
|
|
PERCENT_CPU
|
|
|
|
PERCENT_MEM
|
|
|
|
TIME
|
|
|
|
COMM
|
|
|
|
];
|
|
|
|
|
2021-05-19 01:36:08 +02:00
|
|
|
modes = {
|
|
|
|
Bar = 1;
|
|
|
|
Text = 2;
|
|
|
|
Graph = 3;
|
|
|
|
LED = 4;
|
|
|
|
};
|
|
|
|
|
2021-06-03 01:27:17 +02:00
|
|
|
# Utilities for constructing meters
|
|
|
|
meter = mode: name: { ${name} = mode; };
|
|
|
|
bar = meter modes.Bar;
|
|
|
|
text = meter modes.Text;
|
|
|
|
graph = meter modes.Graph;
|
|
|
|
led = meter modes.LED;
|
|
|
|
blank = text "Blank";
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2021-12-25 19:32:05 +01:00
|
|
|
meta.maintainers = [ hm.maintainers.bjpbakker ];
|
2021-07-29 14:16:43 +02:00
|
|
|
|
2017-07-24 07:47:59 +02:00
|
|
|
options.programs.htop = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "htop";
|
2017-07-24 07:47:59 +02:00
|
|
|
|
2021-05-19 01:36:08 +02:00
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrs;
|
2021-07-29 14:34:08 +02:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-05-19 01:36:08 +02:00
|
|
|
{
|
|
|
|
color_scheme = 6;
|
|
|
|
cpu_count_from_one = 0;
|
|
|
|
delay = 15;
|
|
|
|
fields = with config.lib.htop.fields; [
|
|
|
|
PID
|
|
|
|
USER
|
|
|
|
PRIORITY
|
|
|
|
NICE
|
|
|
|
M_SIZE
|
|
|
|
M_RESIDENT
|
|
|
|
M_SHARE
|
|
|
|
STATE
|
|
|
|
PERCENT_CPU
|
|
|
|
PERCENT_MEM
|
|
|
|
TIME
|
|
|
|
COMM
|
|
|
|
];
|
|
|
|
highlight_base_name = 1;
|
|
|
|
highlight_megabytes = 1;
|
|
|
|
highlight_threads = 1;
|
2021-06-03 01:27:17 +02:00
|
|
|
} // (with config.lib.htop; leftMeters [
|
|
|
|
(bar "AllCPUs2")
|
|
|
|
(bar "Memory")
|
|
|
|
(bar "Swap")
|
|
|
|
(text "Zram")
|
|
|
|
]) // (with config.lib.htop; rightMeters [
|
|
|
|
(text "Tasks")
|
|
|
|
(text "LoadAverage")
|
|
|
|
(text "Uptime")
|
|
|
|
(text "Systemd")
|
|
|
|
]);
|
2021-05-19 01:36:08 +02:00
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-05-19 01:36:08 +02:00
|
|
|
Configuration options to add to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/htop/htoprc`.
|
2021-05-19 01:36:08 +02:00
|
|
|
'';
|
2020-09-06 10:58:37 +02:00
|
|
|
};
|
2021-10-20 17:22:17 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.htop;
|
|
|
|
defaultText = literalExpression "pkgs.htop";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Package containing the {command}`htop` program.";
|
2021-10-20 17:22:17 +02:00
|
|
|
};
|
2017-07-24 07:47:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-06-03 01:27:17 +02:00
|
|
|
lib.htop = {
|
|
|
|
inherit fields modes leftMeters rightMeters bar text graph led blank;
|
|
|
|
};
|
2021-05-19 01:36:08 +02:00
|
|
|
|
2021-10-20 17:22:17 +02:00
|
|
|
home.packages = [ cfg.package ];
|
2017-07-24 07:47:59 +02:00
|
|
|
|
2021-07-29 14:54:28 +02:00
|
|
|
xdg.configFile."htop/htoprc" = let
|
|
|
|
defaults = {
|
2022-05-13 22:53:16 +02:00
|
|
|
fields = if isDarwin then
|
|
|
|
remove fields.M_SHARE defaultFields
|
|
|
|
else
|
|
|
|
defaultFields;
|
2021-07-29 14:54:28 +02:00
|
|
|
};
|
|
|
|
|
2021-11-01 20:27:29 +01:00
|
|
|
before = optionalAttrs (cfg.settings ? header_layout) {
|
|
|
|
inherit (cfg.settings) header_layout;
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = defaults // (removeAttrs cfg.settings (attrNames before));
|
|
|
|
|
|
|
|
formatOptions = mapAttrsToList formatOption;
|
|
|
|
|
2021-07-29 14:54:28 +02:00
|
|
|
in mkIf (cfg.settings != { }) {
|
2021-11-01 20:27:29 +01:00
|
|
|
text =
|
|
|
|
concatStringsSep "\n" (formatOptions before ++ formatOptions settings)
|
|
|
|
+ "\n";
|
2021-07-29 14:34:08 +02:00
|
|
|
};
|
2017-07-24 07:47:59 +02:00
|
|
|
};
|
|
|
|
}
|