diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7326fb67..f5d35eff 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -58,6 +58,9 @@ /modules/programs/beets.nix @rycee +/modules/programs/bottom.nix @polykernel +/tests/modules/programs/bottom @polykernel + /modules/programs/broot.nix @aheaume /modules/programs/dircolors.nix @JustinLovinger diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 4807fcb7..a2aa80d7 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2196,6 +2196,13 @@ in A new module is available: 'services.betterlockscreen'. ''; } + + { + time = "2021-09-14T21:31:03+00:00"; + message = '' + A new module is available: 'programs.bottom'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 595a4b76..e87dc85d 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -50,6 +50,7 @@ let ./programs/bash.nix ./programs/bat.nix ./programs/beets.nix + ./programs/bottom.nix ./programs/broot.nix ./programs/browserpass.nix ./programs/chromium.nix diff --git a/modules/programs/bottom.nix b/modules/programs/bottom.nix new file mode 100644 index 00000000..8028e6d0 --- /dev/null +++ b/modules/programs/bottom.nix @@ -0,0 +1,66 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.bottom; + + tomlFormat = pkgs.formats.toml { }; + + configDir = if pkgs.stdenv.isDarwin then + "Library/Application Support" + else + config.xdg.configHome; + +in { + options = { + programs.bottom = { + enable = mkEnableOption '' + bottom, a cross-platform graphical process/system monitor with a + customizable interface''; + + package = mkOption { + type = types.package; + default = pkgs.bottom; + defaultText = literalExample "pkgs.bottom"; + description = "Package providing bottom."; + }; + + settings = mkOption { + type = tomlFormat.type; + default = { }; + description = '' + Configuration written to + $XDG_CONFIG_HOME/bottom/bottom.toml on Linux or + $HOME/Library/Application Support/bottom/bottom.toml on Darwin. + + See + for the default configuration. + ''; + example = literalExample '' + { + flags = { + avg_cpu = true; + temperature_type = "c"; + }; + + colors = { + low_battery_color = "red"; + }; + } + ''; + }; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + home.file."${configDir}/bottom/bottom.toml" = mkIf (cfg.settings != { }) { + source = tomlFormat.generate "bottom.toml" cfg.settings; + }; + }; + + meta.maintainers = [ maintainers.polykernel ]; +} diff --git a/tests/default.nix b/tests/default.nix index 43f3b9f4..a773fd50 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -46,6 +46,7 @@ import nmt { ./modules/programs/autojump ./modules/programs/bash ./modules/programs/bat + ./modules/programs/bottom ./modules/programs/broot ./modules/programs/browserpass ./modules/programs/dircolors diff --git a/tests/modules/programs/bottom/default.nix b/tests/modules/programs/bottom/default.nix new file mode 100644 index 00000000..ed6e241f --- /dev/null +++ b/tests/modules/programs/bottom/default.nix @@ -0,0 +1,4 @@ +{ + bottom-empty-settings = ./empty-settings.nix; + bottom-example-settings = ./example-settings.nix; +} diff --git a/tests/modules/programs/bottom/empty-settings.nix b/tests/modules/programs/bottom/empty-settings.nix new file mode 100644 index 00000000..bedcf212 --- /dev/null +++ b/tests/modules/programs/bottom/empty-settings.nix @@ -0,0 +1,16 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.bottom = { + enable = true; + package = pkgs.writeScriptBin "dummy" ""; + }; + + nmt.script = '' + assertPathNotExists home-files/.config/bottom + ''; + }; +} diff --git a/tests/modules/programs/bottom/example-settings.nix b/tests/modules/programs/bottom/example-settings.nix new file mode 100644 index 00000000..3635bd19 --- /dev/null +++ b/tests/modules/programs/bottom/example-settings.nix @@ -0,0 +1,41 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.bottom = { + enable = true; + package = pkgs.writeShellScriptBin "dummy" ""; + + settings = { + flags = { + avg_cpu = true; + temperature_type = "c"; + }; + + colors = { low_battery_color = "red"; }; + }; + }; + + nmt.script = let + configDir = if pkgs.stdenv.isDarwin then + "home-files/Library/Application Support" + else + "home-files/.config"; + in '' + assertFileContent \ + "${configDir}/bottom/bottom.toml" \ + ${ + builtins.toFile "example-settings-expected.toml" '' + [colors] + low_battery_color = "red" + + [flags] + avg_cpu = true + temperature_type = "c" + '' + } + ''; + }; +}