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