nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
7.05k stars 1.82k forks source link

bug: darwin-rebuild switch failing because of htop config #2786

Closed SerhiyMakarenko closed 2 years ago

SerhiyMakarenko commented 2 years ago

Is there an existing issue for this?

Issue description

My configuration is the following.

Content of the darwin-configuration.nix:

{ config, lib, pkgs, ... }:
......
  users = {
    users = {
      serhiy_makarenko = {
        name = "serhiy_makarenko";
        home = "/Users/serhiy_makarenko";
      };
    };
  };

  home-manager = {
    users = {
      serhiy_makarenko = import ./dotfiles/default.nix;
    };
  };

  system.stateVersion = 4;
}

Content of the ./dotfiles/default.nix:

{
  programs = {
    ssh = import ./ssh.nix;
    git = import ./git.nix;
    fish = import ./fish.nix;
    htop = import ./htop.nix;
  };
}

Content of the ./htop.nix, taken from the home-manager documentation:

{ config, ... }:

{
  enable = true;
  settings = {
    color_scheme = 0;
    cpu_count_from_one = 0;
    delay = 15;
    highlight_base_name = 1;
    highlight_megabytes = 1;
    highlight_threads = 1;
    fields = with config.lib.htop.fields; [
      PID
      USER
      PRIORITY
      NICE
      M_SIZE
      M_RESIDENT
      M_SHARE
      STATE
      PERCENT_CPU
      PERCENT_MEM
      TIME
      COMM
    ];
  } // (with config.lib.htop; leftMeters [
    (bar "AllCPUs2")
    (bar "Memory")
    (bar "Swap")
    (text "Zram")
  ]) // (with config.lib.htop; rightMeters [
    (text "Tasks")
    (text "LoadAverage")
    (text "Uptime")
    (text "Systemd")
  ]);
}

When I'm trying to run darwin-rebuild switch I get the following error:

[22:54] serhiy_makarenko [/Users/serhiy_makarenko] > darwin-rebuild switch
building the system configuration...
error: You're trying to declare a value of type `lambda'
       rather than an attribute-set for the option
       `home-manager.users.serhiy_makarenko.programs.htop'!

       This usually happens if `home-manager.users.serhiy_makarenko.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)

Unfortunatley, closed bugs here related to the htop and changes made for settings declaration do not shed the light to the root cause of the issue. Please, advise.

Thank you.

Maintainer CC

@bjpbakker

System information

these 2 paths will be fetched (0.34 MiB download, 2.06 MiB unpacked):
  /nix/store/0cqn0wrpfljm4ng170gflhz2kp1i46h2-bash-interactive-5.1-p12-dev
  /nix/store/afwg2nff6xdfpyi9dkddh1rk6d0sdnld-bash-interactive-5.1-p12-doc
copying path '/nix/store/afwg2nff6xdfpyi9dkddh1rk6d0sdnld-bash-interactive-5.1-p12-doc' from 'https://cache.nixos.org'...
copying path '/nix/store/0cqn0wrpfljm4ng170gflhz2kp1i46h2-bash-interactive-5.1-p12-dev' from 'https://cache.nixos.org'...
 - system: `"aarch64-darwin"`
 - host os: `Darwin 21.3.0, macOS 12.2.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.5.1`
 - channels(root): `"nixpkgs-22.05pre340506.5c37ad87222"`
 - channels(serhiy_makarenko): `"darwin, home-manager-21.11, nixpkgs-stable-21.11pre336282.ed02c2ba038, nixpkgs-unstable-22.05pre358575.ad267cc9cf3"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
bjpbakker commented 2 years ago

When I'm trying to run darwin-rebuild switch I get the following error:


[22:54] serhiy_makarenko [/Users/serhiy_makarenko] > darwin-rebuild switch
building the system configuration...
error: You're trying to declare a value of type `lambda'
       rather than an attribute-set for the option
       `home-manager.users.serhiy_makarenko.programs.htop'!

The error in your configuration is that htop.nix now returns a function that takes an attribute set with config. And programs.htop must be an attribute set, where it now is assigned a function.

The quick way to solve this in the pasted configuration is to manually pass config to the imported htop.nix module. Something like:

./dotfiles/default.nix:

{ config, ... }:

{
  programs = {
    # ..
    htop = import ./htop.nix { inherit config; };
  };
}

You could also consider importing your modules in ./dotfiles/default.nix through imports and let nix pass the attributes. Something like:

./dotfiles/default.nix:

{ config, ... }:

{
  imports = [
    ./fish.nix
    ./git.nix
    ./htop.nix
    ./ssh.nix
  ];
}

And change the modules to set the respective options:

./dotfiles/htop.nix:

{ config, ... }:

programs.htop = {
  enable = true;
  settings = {
    # ..
  };
};

Hope this helps!

SerhiyMakarenko commented 2 years ago

Thank you, @bjpbakker for the advice. The first approach works well, thank you for pushing me in the right direction. I did not try to implement the second approach yet. How do you think, maybe it is worth adding your explanation to the documentation to make it clear that fields, leftMeters, and rightMeters are required to supply attribute set to be able to generate htop config?

berbiche commented 2 years ago

I believe the current documentation identifies the leftMeter and rightMeter function as mentioned. image

I will close this issue since it is resolved. Feel free to reopen.