Problems with Home manager installation

Hello, i am right now trying to set up Home-Manager. i followed this and did nearly everything same, but when i run nixos-rebuild, i get some error messages i dont understand.
the complete error message is:
$ sudo nixos-rebuild switch --show-trace

error:
       … while evaluating the attribute 'config'

         at /nix/store/k1i8sghsbwcwgw43mglmf634rc9p9mm8-nixos-23.11/nixos/lib/modules.nix:320:9:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          321|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/store/k1i8sghsbwcwgw43mglmf634rc9p9mm8-nixos-23.11/nixos/lib/modules.nix:320:18:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          321|         _module = checked (config._module);

       … while calling the 'throw' builtin

         at /nix/store/k1i8sghsbwcwgw43mglmf634rc9p9mm8-nixos-23.11/nixos/lib/modules.nix:296:18:

          295|                     ''
          296|             else throw baseMsg
             |                  ^
          297|         else null;

       error: The option `programs.home-manager' does not exist. Definition values:
       - In `/etc/nixos/configuration.nix':
           {
             enable = true;
           }
building Nix...
error:
       … while evaluating the attribute 'config'

         at /nix/store/k1i8sghsbwcwgw43mglmf634rc9p9mm8-nixos-23.11/nixos/lib/modules.nix:320:9:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          321|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/store/k1i8sghsbwcwgw43mglmf634rc9p9mm8-nixos-23.11/nixos/lib/modules.nix:320:18:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          321|         _module = checked (config._module);

       … while calling the 'throw' builtin

         at /nix/store/k1i8sghsbwcwgw43mglmf634rc9p9mm8-nixos-23.11/nixos/lib/modules.nix:296:18:

          295|                     ''
          296|             else throw baseMsg
             |                  ^
          297|         else null;

       error: The option `programs.home-manager' does not exist. Definition values:
       - In `/etc/nixos/configuration.nix':
           {
             enable = true;
           }
building the system configuration...
error:
       … while evaluating the attribute 'config.system.build.toplevel'

         at /nix/store/k1i8sghsbwcwgw43mglmf634rc9p9mm8-nixos-23.11/nixos/lib/modules.nix:320:9:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          321|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/store/k1i8sghsbwcwgw43mglmf634rc9p9mm8-nixos-23.11/nixos/lib/modules.nix:320:18:

          319|         options = checked options;
          320|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          321|         _module = checked (config._module);

       … while calling the 'throw' builtin

         at /nix/store/k1i8sghsbwcwgw43mglmf634rc9p9mm8-nixos-23.11/nixos/lib/modules.nix:296:18:

          295|                     ''
          296|             else throw baseMsg
             |                  ^
          297|         else null;

       error: The option `programs.home-manager' does not exist. Definition values:
       - In `/etc/nixos/configuration.nix':
           {
             enable = true;
           }

my configuration.nix related to Home-Manager:

{config, pkgs, ...}: {
imports = [
  ./hardware-configuration.nix
  <home-manager/nixos>
];

(...)

home-manager.users.username = {pkgs, ...}: {
  home.packages = [];
  programs.zsh.enable = true;
  home.stateVersion = "23.11";
};

(...)

programs.home-manager.enable = true;

(...)

}

i would be very happy if someone had awnsers.

Move this programs.home-manager.enable = true;
between home-manager.users.username { ... }

home-manager.users.username = {pkgs, ...}: {
  # all Home-Manager should be included here.
  # imports = []; # imports works here too options for home-manager != nixos
                  # causing that pretty error.
  home.packages = [];
  programs.zsh.enable = true;
  home.stateVersion = "23.11";
  programs.home-manager.enable = true;
};

But this ‘programs.home-manager.enable’ isn’t required, unless you are trying to configure it without NixOS

1 Like

well, different result. first of all, it gives me a warning while rebuilding:

trace: warning: noof profile: You are using

  Home Manager version 24.11 and
  Nixpkgs version 23.11.

Using mismatched versions is likely to cause errors and unexpected
behavior. It is therefore highly recommended to use a release of Home
Manager that corresponds with your chosen release of Nixpkgs.

If you insist then you can disable this warning by adding

  home.enableNixpkgsReleaseCheck = false;

to your configuration.

also, it fails to start the service home-manager-user.service:

× home-manager-noof.service - Home Manager environment for noof
     Loaded: loaded (/etc/systemd/system/home-manager-noof.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Wed 2024-06-05 07:21:53 CEST; 468ms ago
    Process: 223598 ExecStart=/nix/store/ik7kg6fm1isyvi53xmbkkaxi466ai0yw-hm-setup-env /nix/store-<some id>-home-manager-generation (code=exited, status=1/FAILURE)
   Main PID: 223598 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 564ms

Jun 05 07:21:53 dEll hm-activate-noof[223706]: Please do one of the following:
Jun 05 07:21:53 dEll hm-activate-noof[223706]: - Move or remove the above files and try again.
Jun 05 07:21:53 dEll hm-activate-noof[223706]: - In standalone mode, use 'home-manager switch -b backup' to back up
Jun 05 07:21:53 dEll hm-activate-noof[223706]:   files automatically.
Jun 05 07:21:53 dEll hm-activate-noof[223706]: - When used as a NixOS or nix-darwin module, set
Jun 05 07:21:53 dEll hm-activate-noof[223706]:     'home-manager.backupFileExtension'
Jun 05 07:21:53 dEll hm-activate-noof[223706]:   to, for example, 'backup' and rebuild.
Jun 05 07:21:53 dEll systemd[1]: home-manager-noof.service: Main process exited, code=exited, status=1/FAILURE
Jun 05 07:21:53 dEll systemd[1]: home-manager-noof.service: Failed with result 'exit-code'.
Jun 05 07:21:53 dEll systemd[1]: Failed to start Home Manager environment for noof.
warning: error(s) occurred while switching to the new configuration

Try what this say, but this should be related to an existing file it is trying to change.
But this is only last N lines of log, there are more log info before it, try:

journalctl --user -u home-manager-noof.service