Error: attribute 'htop' missing. Desperately need some help

I tried home manager for the first time and config htop in home manager. I installed htop in my configuration.nix file.

I followed the config from programs.htop.settings but it kept showing me attribute missing.

Am I missing something?

at /etc/nixos/home.nix:65:16:

           64|       highlight_base_name = 1;
           65|     } // (with config.lib.htop; leftMeters [
             |                ^
           66|       (bar "AllCPUs4")

Here’s my home.nix config:

{ config, pkgs, ... }:
let
  home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-23.05.tar.gz";
in
{
  imports = [
    (import "${home-manager}/nixos")
  ];
  home-manager.users.<myUserName> = {
    home.stateVersion = "23.05";
    home.packages = with pkgs; [
      gcc
    ];
# HTOP
  programs.htop = {
    enable = true;
    settings = {
fields = with config.lib.htop.fields; [
        PID
        USER
        PRIORITY
        NICE
        M_SHARE
        M_VIRT
        STATE
        M_SWAP
        PERCENT_MEM
        M_RESIDENT
        PERCENT_CPU
        TIME
        COMM
      ];
      highlight_base_name = 1;
    } // (with config.lib.htop; leftMeters [
      (bar "AllCPUs4")
      (bar "CPU")
      (bar "Memory")
      (bar "Swap")
      (bar "HugePages")
    ]) // (with config.lib.htop; rightMeters [
      (text "Tasks")
      (text "LoadAverage")
      (text "Uptime")
      (text "Battery")
      (text "DiskIO")
      (text "NetworkIO")
      (text "MemorySwap")
    ]);
  };
}

PLS SEND HELP, I’M DESPERATE.

{ pkgs, config, ... }:

{

  imports = [

  ];

  # HTOP
  programs.htop = {
    enable = true;
    settings = {
      fields = with config.lib.htop.fields; [
        PID
        USER
        PRIORITY
        NICE
        M_SHARE
        M_VIRT
        STATE
        M_SWAP
        PERCENT_MEM
        M_RESIDENT
        PERCENT_CPU
        TIME
        COMM
      ];
      highlight_base_name = 1;
    } // (with config.lib.htop; leftMeters [
      (bar "AllCPUs4")
      (bar "CPU")
      (bar "Memory")
      (bar "Swap")
      (bar "HugePages")
    ]) // (with config.lib.htop; rightMeters [
      (text "Tasks")
      (text "LoadAverage")
      (text "Uptime")
      (text "Battery")
      (text "DiskIO")
      (text "NetworkIO")
      (text "MemorySwap")
    ]);
  };


}

This code works in nix unstable. :confused: I literally just added htop to my system configuration. Are you running the stable channel?

Yes, i’m running stable channel

Ok… reproducing now. I am getting an error: attribute ‘htop’ missing. Is that right? Then we can find a solution. :smiley:

I’m updating my nixos to unstable channel rn, hope I won’t do any dumb stuff and brick my nixos

yup and I totally jinxed myself

the htop config also didn’t work when i updated to the unstable channel, I’m hopeless.

Oh dang, I had kids get up. I am still working on the issue. Sometimes you have to reboot to have full changes, but I would NOT recommend. I would go back to stable for now.

First, we need to delete M_VIRT from the fields category.

home = {
    packages = [
      pkgs.htop
    ];
  };
  programs.htop = {
    enable = true;
    settings = {
      fields = with config.lib.htop.fields; [
        PID
        USER
        PRIORITY
        NICE
        M_SHARE
        STATE
        M_SWAP
        PERCENT_MEM
        M_RESIDENT
        PERCENT_CPU
        TIME
        COMM
      ];
      highlight_base_name = 1;
    } // (with config.lib.htop; leftMeters [
      (bar "AllCPUs4")
      (bar "CPU")
      (bar "Memory")
      (bar "Swap")
      (bar "HugePages")
    ]) // (with config.lib.htop; rightMeters [
      (text "Tasks")
      (text "LoadAverage")
      (text "Uptime")
      (text "Battery")
      (text "DiskIO")
      (text "NetworkIO")
      (text "MemorySwap")
    ]);
  };

Works good

lib.htop is not available from NixOS’ config. Wrap programs.htop with ({config, ...}: { /* the rest */ }) for it to use Home Manager’s config.

Hey, your not hopeless! in fact your arrived at nix means your one the right bread crumb trail.

You can also get more instant help, on discord, matrix…

the community is very friendly, even those with 30 years of unix experience, when they hit nix, are like total beginners.

and that’s part of the fun…

I don’t know where you are on earth, but https://nix.ug , find a local user group…and you can connect with other nixxers in a room who can get you started.

So, please keep trying… a lot of new users come from Arch…

Welcome…

May the nix be with you, always.

Tried commenting out the M_VIRT, didn’t work.

For FedericoSchonborn’s solution, I tried it as below:

programs.htop = ({config, ...}: {
    enable = true;
    settings = {
      fields = with config.lib.htop.fields; [
        PID
        USER
        PRIORITY
        NICE
        M_SHARE
#        M_VIRT
        STATE
        M_SWAP
        PERCENT_MEM
        M_RESIDENT
        PERCENT_CPU
        TIME
        COMM
      ];
      highlight_base_name = 1;
    } // (with config.lib.htop; leftMeters [
      (bar "AllCPUs4")
      (bar "CPU")
      (bar "Memory")
      (bar "Swap")
      (bar "HugePages")
    ]) // (with config.lib.htop; rightMeters [
      (text "Tasks")
      (text "LoadAverage")
      (text "Uptime")
      (text "Battery")
      (text "DiskIO")
      (text "NetworkIO")
      (text "MemorySwap")
    ]);
  });

Well it throws me some error, don’t know what that even means tho:

error: You're trying to define a value of type `lambda'
       rather than an attribute set for the option
       `programs.htop'!

       This usually happens if `programs.htop' has option
       definitions inside that are not matched. Please check how to properly define
       this option by e.g. referring to `man 5 configuration.nix'!
(use '--show-trace' to show detailed location information)
building Nix...
error: You're trying to define a value of type `lambda'
       rather than an attribute set for the option
       `programs.htop'!

       This usually happens if `programs.htop' has option
       definitions inside that are not matched. Please check how to properly define
       this option by e.g. referring to `man 5 configuration.nix'!
(use '--show-trace' to show detailed location information)
building the system configuration...
error: You're trying to define a value of type `lambda'
       rather than an attribute set for the option
       `programs.htop'!

       This usually happens if `programs.htop' has option
       definitions inside that are not matched. Please check how to properly define
       this option by e.g. referring to `man 5 configuration.nix'!

Try

 ({config, ...}: { programs.htop = {

in order to wrap.

error: syntax error, unexpected '('

       at /etc/nixos/home.nix:26:3:

           25|   # HTOP
           26|   ({config, ...}: { programs.htop = {
             |   ^
           27|     enable = true;

uhh I don’t think so…

This is definitely a problem with dealing with scope. The config in use isn’t the config for home manager. I have inadvertently avoided the entire issue because I used flakes and I am not familiar enough with the nix scripting language to suggest a way forward. You can always look at my code at for example at:

That being said, my code is definitely not very good. I am in Day 4 of trying out NixOS.

I’m using home manager as a nixos module. Idk if that helps but anyone got any solution or suggestion on how to configure htop declaratively?

You want to get the config argument to the home-manager module, so you need to have your Home Manager module expression accept the argument:

-home-manager.users.<myUserName> = {
+home-manager.users.<myUserName> = {config, ...}: {

It is a bit confusing because your home.nix is actually a NixOS module, which also accepts config argument. But then you have home-manager NixOS module, that creates a separate instance of the NixOS module system for Home Manager, which evaluates your Home Manager module (the expression on the right hand side of home-manager.users.<myUserName> =).

1 Like