btop: add module

This commit is contained in:
Gaetan Lepage 2022-08-17 18:16:01 +02:00 committed by Robert Helgesson
parent 960c009ce0
commit de079ec371
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
10 changed files with 140 additions and 0 deletions

3
.github/CODEOWNERS vendored
View file

@ -83,6 +83,9 @@ Makefile @thiagokokada
/modules/programs/broot.nix @aheaume /modules/programs/broot.nix @aheaume
/modules/programs/btop.nix @GaetanLepage
/tests/modules/programs/btop.nix @GaetanLepage
/modules/programs/dircolors.nix @JustinLovinger /modules/programs/dircolors.nix @JustinLovinger
/modules/programs/direnv.nix @rycee /modules/programs/direnv.nix @rycee

View file

@ -153,6 +153,12 @@
githubId = 53856373; githubId = 53856373;
name = "Jens Krewald"; name = "Jens Krewald";
}; };
GaetanLepage = {
email = "gaetan@glepage.com";
github = "GaetanLepage";
githubId = 33058747;
name = "Gaetan Lepage";
};
maximsmol = { maximsmol = {
email = "maximsmol@gmail.com"; email = "maximsmol@gmail.com";
github = "maximsmol"; github = "maximsmol";

View file

@ -661,6 +661,13 @@ in
A new module is available: 'services.pueue'. A new module is available: 'services.pueue'.
''; '';
} }
{
time = "2022-09-05T12:33:11+00:00";
message = ''
A new module is available: 'programs.btop'.
'';
}
]; ];
}; };
} }

View file

@ -59,6 +59,7 @@ let
./programs/bottom.nix ./programs/bottom.nix
./programs/broot.nix ./programs/broot.nix
./programs/browserpass.nix ./programs/browserpass.nix
./programs/btop.nix
./programs/chromium.nix ./programs/chromium.nix
./programs/command-not-found/command-not-found.nix ./programs/command-not-found/command-not-found.nix
./programs/dircolors.nix ./programs/dircolors.nix

64
modules/programs/btop.nix Normal file
View file

@ -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 <filename>btop.conf</filename> file.
See <link xlink:href="https://github.com/aristocratos/btop#configurability"/>
for options.
'';
};
extraConfig = mkOption {
type = types.lines;
default = "";
description = ''
Extra lines added to the <filename>btop.conf</filename> file.
'';
};
};
config = mkIf cfg.enable {
home.packages = [ cfg.package ];
xdg.configFile."btop/btop.conf" =
mkIf (cfg.settings != { }) { text = finalConfig; };
};
}

View file

@ -64,6 +64,7 @@ import nmt {
./modules/programs/bottom ./modules/programs/bottom
./modules/programs/broot ./modules/programs/broot
./modules/programs/browserpass ./modules/programs/browserpass
./modules/programs/btop
./modules/programs/dircolors ./modules/programs/dircolors
./modules/programs/direnv ./modules/programs/direnv
./modules/programs/emacs ./modules/programs/emacs

View file

@ -0,0 +1,4 @@
{
btop-example-settings = ./example-settings.nix;
btop-empty-settings = ./empty-settings.nix;
}

View file

@ -0,0 +1,11 @@
{ ... }:
{
programs.btop.enable = true;
test.stubs.btop = { };
nmt.script = ''
assertPathNotExists home-files/.config/btop
'';
}

View file

@ -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"

View file

@ -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}
'';
}