From 7523252f97bff5d39de47fb2b112f2039d1218a3 Mon Sep 17 00:00:00 2001 From: Bart Bakker Date: Mon, 1 Nov 2021 19:27:29 +0000 Subject: [PATCH] htop: fix order or header_columns setting (#2435) When `header_columns` is in settings it must appear before any of the `column_meters_*` options. Fixes 2426. --- modules/programs/htop.nix | 13 ++++++- tests/modules/programs/htop/default.nix | 3 +- tests/modules/programs/htop/header_layout.nix | 37 +++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tests/modules/programs/htop/header_layout.nix diff --git a/modules/programs/htop.nix b/modules/programs/htop.nix index 0b0524e9..1506aab5 100644 --- a/modules/programs/htop.nix +++ b/modules/programs/htop.nix @@ -170,9 +170,18 @@ in { ]; }; + before = optionalAttrs (cfg.settings ? header_layout) { + inherit (cfg.settings) header_layout; + }; + + settings = defaults // (removeAttrs cfg.settings (attrNames before)); + + formatOptions = mapAttrsToList formatOption; + in mkIf (cfg.settings != { }) { - text = concatStringsSep "\n" - (mapAttrsToList formatOption (defaults // cfg.settings)) + "\n"; + text = + concatStringsSep "\n" (formatOptions before ++ formatOptions settings) + + "\n"; }; }; } diff --git a/tests/modules/programs/htop/default.nix b/tests/modules/programs/htop/default.nix index ebb3cefc..e63d74fd 100644 --- a/tests/modules/programs/htop/default.nix +++ b/tests/modules/programs/htop/default.nix @@ -1,5 +1,6 @@ { htop-empty-settings = ./empty-settings.nix; htop-example-settings = ./example-settings.nix; - settings-without-fields = ./settings-without-fields.nix; + htop-header_layout = ./header_layout.nix; + htop-settings-without-fields = ./settings-without-fields.nix; } diff --git a/tests/modules/programs/htop/header_layout.nix b/tests/modules/programs/htop/header_layout.nix new file mode 100644 index 00000000..2cf34998 --- /dev/null +++ b/tests/modules/programs/htop/header_layout.nix @@ -0,0 +1,37 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = with config.lib.htop; { + programs.htop.enable = true; + programs.htop.settings = { + header_layout = "two_50_50"; + column_meters_0 = [ "AllCPUs2" "Memory" "Swap" "Zram" ]; + column_meters_modes_0 = [ modes.Bar modes.Bar modes.Bar modes.Text ]; + column_meters_1 = [ "Tasks" "LoadAverage" "Uptime" "Systemd" ]; + column_meters_modes_1 = [ modes.Text modes.Text modes.Text modes.Text ]; + }; + + test.stubs.htop = { }; + + # Test that the 'fields' key is written in addition to the customized + # settings or htop won't read the options. + nmt.script = '' + htoprc=home-files/.config/htop/htoprc + assertFileExists $htoprc + assertFileContent $htoprc \ + ${ + builtins.toFile "htoprc-expected" '' + header_layout=two_50_50 + column_meters_0=AllCPUs2 Memory Swap Zram + column_meters_1=Tasks LoadAverage Uptime Systemd + column_meters_modes_0=1 1 1 2 + column_meters_modes_1=2 2 2 2 + fields=0 48 17 18 38 39 40 2 46 47 49 1 + '' + } + ''; + }; + +}