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