diff --git a/modules/programs/htop.nix b/modules/programs/htop.nix index 0b0524e95..1506aab5b 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 ebb3cefcf..e63d74fd3 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 000000000..2cf34998d --- /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 + '' + } + ''; + }; + +}