Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

htop: fix preserving the order of meters (backport to 21.05) #2068

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 41 additions & 25 deletions modules/programs/htop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ let
let v' = if isBool v then (if v then "1" else "0") else toString v;
in "${n}=${v'}";

formatMeters = side: meters: {
"${side}_meters" = mapAttrsToList (x: _: x) meters;
"${side}_meter_modes" = mapAttrsToList (_: y: y) meters;
};
formatMeters = side: meters:
let
warn' = warn "htop: meters should be passed as a list";
meters' = if isList meters then meters else warn' [ meters ];
in {
"${side}_meters" = concatMap (mapAttrsToList (x: _: x)) meters';
"${side}_meter_modes" = concatMap (mapAttrsToList (_: y: y)) meters';
};
leftMeters = formatMeters "left";
rightMeters = formatMeters "right";

Expand Down Expand Up @@ -80,6 +84,14 @@ let
LED = 4;
};

# 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";

# Mapping from names to defaults
meters = {
Clock = 2;
Expand Down Expand Up @@ -231,15 +243,17 @@ in {
tree_view = false;
update_process_names = false;
vim_mode = false;
} // (leftMeters {
AllCPUs = modes.Bar;
Memory = modes.Bar;
Swap = modes.Bar;
}) // (rightMeters {
Tasks = modes.Text;
LoadAverage = modes.Text;
Uptime = modes.Text;
});
} // (leftMeters [
(bar "AllCPUs2")
(bar "Memory")
(bar "Swap")
(text "Zram")
]) // (rightMeters [
(text "Tasks")
(text "LoadAverage")
(text "Uptime")
(text "Systemd")
]);
example = literalExample ''
{
color_scheme = 6;
Expand All @@ -262,17 +276,17 @@ in {
highlight_base_name = 1;
highlight_megabytes = 1;
highlight_threads = 1;
} // (with config.lib.htop; leftMeters {
AllCPUs2 = modes.Bar;
Memory = modes.Bar;
Swap = modes.Bar;
Zram = modes.Text;
}) // (with config.lib.htop; rightMeters {
Tasks = modes.Text;
LoadAverage = modes.Text;
Uptime = modes.Text;
Systemd = modes.Text;
})
} // (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")
]);
'';
description = ''
Configuration options to add to
Expand Down Expand Up @@ -576,7 +590,9 @@ in {
};

config = mkIf cfg.enable {
lib.htop = { inherit fields modes leftMeters rightMeters; };
lib.htop = {
inherit fields modes leftMeters rightMeters bar text graph led blank;
};

home.packages = [ pkgs.htop ];

Expand Down
20 changes: 8 additions & 12 deletions tests/modules/programs/htop/example-settings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ with lib;
highlight_megabytes = 1;
highlight_threads = 1;
} // (with config.lib.htop;
leftMeters {
AllCPUs2 = modes.Bar;
Memory = modes.Bar;
Swap = modes.Bar;
Zram = modes.Text;
}) // (with config.lib.htop;
rightMeters {
Tasks = modes.Text;
LoadAverage = modes.Text;
Uptime = modes.Text;
Systemd = modes.Text;
});
leftMeters [ (bar "AllCPUs2") (bar "Memory") (bar "Swap") (text "Zram") ])
// (with config.lib.htop;
rightMeters [
(text "Tasks")
(text "LoadAverage")
(text "Uptime")
(text "Systemd")
]);

nmt.script = ''
assertFileExists home-files/.config/htop/htoprc
Expand Down