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