diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9d1ae31aa..91bc541cc 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -83,6 +83,9 @@ Makefile @thiagokokada /modules/programs/broot.nix @aheaume +/modules/programs/btop.nix @GaetanLepage +/tests/modules/programs/btop.nix @GaetanLepage + /modules/programs/dircolors.nix @JustinLovinger /modules/programs/direnv.nix @rycee diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index a5d999576..ab224efcf 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -153,6 +153,12 @@ githubId = 53856373; name = "Jens Krewald"; }; + GaetanLepage = { + email = "gaetan@glepage.com"; + github = "GaetanLepage"; + githubId = 33058747; + name = "Gaetan Lepage"; + }; maximsmol = { email = "maximsmol@gmail.com"; github = "maximsmol"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index bfc736671..247d4bff6 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -661,6 +661,13 @@ in A new module is available: 'services.pueue'. ''; } + + { + time = "2022-09-05T12:33:11+00:00"; + message = '' + A new module is available: 'programs.btop'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 92433906b..de977b22e 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -59,6 +59,7 @@ let ./programs/bottom.nix ./programs/broot.nix ./programs/browserpass.nix + ./programs/btop.nix ./programs/chromium.nix ./programs/command-not-found/command-not-found.nix ./programs/dircolors.nix diff --git a/modules/programs/btop.nix b/modules/programs/btop.nix new file mode 100644 index 000000000..cdf011e79 --- /dev/null +++ b/modules/programs/btop.nix @@ -0,0 +1,64 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.btop; + + finalConfig = let + toKeyValue = generators.toKeyValue { + mkKeyValue = generators.mkKeyValueDefault { + mkValueString = v: + with builtins; + if isBool v then + (if v then "True" else "False") + else if isString v then + ''"${v}"'' + else + toString v; + } " = "; + }; + in '' + ${toKeyValue cfg.settings} + ${optionalString (cfg.extraConfig != "") cfg.extraConfig} + ''; + +in { + meta.maintainers = [ hm.maintainers.GaetanLepage ]; + + options.programs.btop = { + enable = mkEnableOption "btop"; + + package = mkPackageOption pkgs "btop" { }; + + settings = mkOption { + type = with types; attrsOf (oneOf [ bool float int str ]); + default = { }; + example = { + color_theme = "Default"; + theme_background = false; + }; + description = '' + Options to add to btop.conf file. + See + for options. + ''; + }; + + extraConfig = mkOption { + type = types.lines; + default = ""; + description = '' + Extra lines added to the btop.conf file. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."btop/btop.conf" = + mkIf (cfg.settings != { }) { text = finalConfig; }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 18ec9ab12..4db813b38 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -64,6 +64,7 @@ import nmt { ./modules/programs/bottom ./modules/programs/broot ./modules/programs/browserpass + ./modules/programs/btop ./modules/programs/dircolors ./modules/programs/direnv ./modules/programs/emacs diff --git a/tests/modules/programs/btop/default.nix b/tests/modules/programs/btop/default.nix new file mode 100644 index 000000000..1b6f74d6b --- /dev/null +++ b/tests/modules/programs/btop/default.nix @@ -0,0 +1,4 @@ +{ + btop-example-settings = ./example-settings.nix; + btop-empty-settings = ./empty-settings.nix; +} diff --git a/tests/modules/programs/btop/empty-settings.nix b/tests/modules/programs/btop/empty-settings.nix new file mode 100644 index 000000000..21aad857d --- /dev/null +++ b/tests/modules/programs/btop/empty-settings.nix @@ -0,0 +1,11 @@ +{ ... }: + +{ + programs.btop.enable = true; + + test.stubs.btop = { }; + + nmt.script = '' + assertPathNotExists home-files/.config/btop + ''; +} diff --git a/tests/modules/programs/btop/example-settings-expected.conf b/tests/modules/programs/btop/example-settings-expected.conf new file mode 100644 index 000000000..05a2bae3b --- /dev/null +++ b/tests/modules/programs/btop/example-settings-expected.conf @@ -0,0 +1,9 @@ +disks_filter = "exclude=/foo/bar" +io_graph_combined = True +io_graph_speeds = "" +log_level = "DEBUG" +show_io_stat = False +update_ms = 1000 + +clock_format = "%H:%M" + diff --git a/tests/modules/programs/btop/example-settings.nix b/tests/modules/programs/btop/example-settings.nix new file mode 100644 index 000000000..bbd3649c5 --- /dev/null +++ b/tests/modules/programs/btop/example-settings.nix @@ -0,0 +1,34 @@ +{ config, ... }: + +{ + programs.btop = { + enable = true; + package = config.lib.test.mkStubPackage { }; + + settings = { + # Integer + update_ms = 1000; + + # Boolean + show_io_stat = false; + io_graph_combined = true; + + # String + disks_filter = "exclude=/foo/bar"; + log_level = "DEBUG"; + + # Empty string + io_graph_speeds = ""; + }; + + extraConfig = '' + clock_format = "%H:%M" + ''; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/btop/btop.conf \ + ${./example-settings-expected.conf} + ''; +}