From e60dca7bb3e34817f237f9f97124e64a2afa0455 Mon Sep 17 00:00:00 2001 From: Bart Bakker Date: Thu, 29 Jul 2021 14:54:28 +0200 Subject: [PATCH] htop: fix htoprc when fields is not explicitly set When the 'fields' setting is not set in htoprc, the htop program won't read any of the settings. Provide a default value for fields in case it's not explicitly set by the user. --- modules/programs/htop.nix | 24 +++++++++++++++--- tests/modules/programs/htop/default.nix | 1 + .../programs/htop/settings-without-fields.nix | 25 +++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 tests/modules/programs/htop/settings-without-fields.nix diff --git a/modules/programs/htop.nix b/modules/programs/htop.nix index e6177e228..81abc8c63 100644 --- a/modules/programs/htop.nix +++ b/modules/programs/htop.nix @@ -145,9 +145,27 @@ in { home.packages = [ pkgs.htop ]; - xdg.configFile."htop/htoprc" = mkIf (cfg.settings != { }) { - text = concatStringsSep "\n" (mapAttrsToList formatOption cfg.settings) - + "\n"; + xdg.configFile."htop/htoprc" = let + defaults = { + fields = with fields; [ + PID + USER + PRIORITY + NICE + M_SIZE + M_RESIDENT + M_SHARE + STATE + PERCENT_CPU + PERCENT_MEM + TIME + COMM + ]; + }; + + in mkIf (cfg.settings != { }) { + text = concatStringsSep "\n" + (mapAttrsToList formatOption (defaults // cfg.settings)) + "\n"; }; }; } diff --git a/tests/modules/programs/htop/default.nix b/tests/modules/programs/htop/default.nix index dbe4641f6..ebb3cefcf 100644 --- a/tests/modules/programs/htop/default.nix +++ b/tests/modules/programs/htop/default.nix @@ -1,4 +1,5 @@ { htop-empty-settings = ./empty-settings.nix; htop-example-settings = ./example-settings.nix; + settings-without-fields = ./settings-without-fields.nix; } diff --git a/tests/modules/programs/htop/settings-without-fields.nix b/tests/modules/programs/htop/settings-without-fields.nix new file mode 100644 index 000000000..19d3e81f1 --- /dev/null +++ b/tests/modules/programs/htop/settings-without-fields.nix @@ -0,0 +1,25 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.htop.enable = true; + programs.htop.settings = { color_scheme = 6; }; + + # 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" '' + color_scheme=6 + fields=0 48 17 18 38 39 40 2 46 47 49 1 + '' + } + ''; + }; + +}