1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.programs.htop;
8
9 fmt = value:
10 if isList value then concatStringsSep " " (map fmt value) else
11 if isString value then value else
12 if isBool value || isInt value then toString value else
13 throw "Unrecognized type ${typeOf value} in htop settings";
14
15in
16
17{
18
19 options.programs.htop = {
20 package = mkOption {
21 type = types.package;
22 default = pkgs.htop;
23 defaultText = lib.literalExpression "pkgs.htop";
24 description = lib.mdDoc ''
25 The htop package that should be used.
26 '';
27 };
28
29 enable = mkEnableOption (lib.mdDoc "htop process monitor");
30
31 settings = mkOption {
32 type = with types; attrsOf (oneOf [ str int bool (listOf (oneOf [ str int bool ])) ]);
33 default = {};
34 example = {
35 hide_kernel_threads = true;
36 hide_userland_threads = true;
37 };
38 description = lib.mdDoc ''
39 Extra global default configuration for htop
40 which is read on first startup only.
41 Htop subsequently uses ~/.config/htop/htoprc
42 as configuration source.
43 '';
44 };
45 };
46
47 config = mkIf cfg.enable {
48 environment.systemPackages = [
49 cfg.package
50 ];
51
52 environment.etc."htoprc".text = ''
53 # Global htop configuration
54 # To change set: programs.htop.settings.KEY = VALUE;
55 '' + concatStringsSep "\n" (mapAttrsToList (key: value: "${key}=${fmt value}") cfg.settings);
56 };
57
58}