{ userName, lib, pkgs, config, ... }:
let
  cfg = config.home-manager.users.${userName};

  wrappedLess = pkgs.less.overrideAttrs (oldAttrs: {
    pname = "${oldAttrs.pname or "less"}-wrapper";

    nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) ++ (with pkgs; [makeWrapper]);

    postInstall = ''
      ${oldAttrs.postInstall or ""}

      wrapProgram $out/bin/less \
        --prefix PATH : ${lib.makeBinPath (with pkgs; [binutils])}
    '';
  });
in {
  home-manager.users.${userName} = {
    programs = {
      htop = {
        enable = true;
        settings = {
          delay = 5;
          unicode = true;
          hide_kernel_threads = true;
          hide_userland_threads = false;
          shadow_other_users = true;
          highlight_base_name = true;
          highlight_deleted_exe = true;
          highlight_megabytes = true;
          highlight_threads = true;
          find_comm_in_cmdline = true;
          strip_exe_from_cmdline = true;
          show_cpu_usage = true;
          show_cpu_frequency = true;
          show_cpu_temperature = true;
          tree_view = true;
          sort_key = cfg.lib.htop.fields.PERCENT_CPU;
          tree_sort_key = cfg.lib.htop.fields.PERCENT_CPU;
        } // (with cfg.lib.htop; leftMeters [
          (bar "LeftCPUs")
          (bar "Memory")
          (bar "Zram")
          (bar "PressureStallCPUSome")
          (bar "PressureStallIOSome")
          (bar "PressureStallMemorySome")
        ]) // (with cfg.lib.htop; rightMeters [
          (bar "RightCPUs")
          (bar "Swap")
          (bar "DiskIO")
          (text "Tasks")
          (text "Uptime")
          (text "Systemd")
        ]);
      };

      jq.enable = true;
    };

    home.sessionVariables = {
      LESSCOLORIZER = "pygmentize -O style=rrt";
    };

    home.packages = with pkgs; [
      autossh usbutils pciutils eza silver-searcher pwgen xkcdpass
      unzip magic-wormhole qrencode tty-clock dnsutils openssl sshfs
      psmisc mosh tree vnstat file pv bc zip nmap aspell
      aspellDicts.de aspellDicts.en borgbackup man-pages rsync socat
      inetutils yq cached-nix-shell persistent-nix-shell rage
      smartmontools hdparm nix-output-monitor wrappedLess dscp
      iputils
    ];
  };
}