The option 'home-manager.users.user.(module)' does not exist error for every single module

Hi, I’m trying to modularize my NixOS configuration. I use Home Manager with flakes and have incorporated it into flakes like in the documentation. and it throws an error for every single module I have in the system.

# configuration.nix
{ config, lib, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  (whole bunch of random stuff)
  nix.settings.experimental-features = [ "nix-command" "flakes" ];

  system.stateVersion = "24.11"; 

}
# flake.nix
{
  description = "nix flake (hopefully i dont lose my sanity configuring all this)";

  # system inputs
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nur = {
      url = "github:nix-community/NUR";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs@{ nixpkgs, home-manager, ... }: {
    nixosConfigurations = {
      sproink-nix = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = { inherit inputs; };

        modules = [
          ./hosts/desktop/configuration.nix
          home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.sproink = import ./hosts/desktop/home.nix;
          }
        ];
      };
    };

    # modules location for all the apps. DO NOT CHANGE.
    homeManagerModules.default = ./modules;
  };
}

Structure:

├── flake.lock
├── flake.nix
├── hosts
│   └── desktop
│       ├── configuration.nix
│       ├── hardware-configuration.nix
│       └── home.nix
└── modules
    ├── module1
       └── module1.nix

We need a lot more info, like what command are you running, what is the full error, what’s in your config?

Also, if the errors are related to those modules you have in ./modules, did you import those into your config anywhere? Does ./modules/default.nix exist, and what does it contain?

I used sudo nixos-rebuild switch and the full error is this:

error: The option `home-manager.users.sproink.(module)' does not exist. Definition values:
       - In `/nix/store/wshnc0kqk1qz7iffb1yqri8a5cy6v7w5-source/flake.nix':
           {
             enable = true;
           }

./modules/default.nix does exist, and I have just imported every single module’s nix file in it.

Can you post a link to the whole config?

1 Like

If you can’t post the whole config, try to create a minimal reproducible example (a SSCCE).

1 Like

I can’t upload the whole configuration, but here’s what every single modules .nix file looks like:

{ inputs, lib, config, pkgs, ... }:
with lib;

let cfg = config.modules.(module);
in {
  options.modules.(module) = { enable = lib.mkEnableOption "(module)"; };

  config = lib.mkIf cfg.enable {
    # package (not necessary if it already comes with nixos)
    home.packages = with pkgs; [
      (package)
    ];

    # configuration goes below (optional)
    home.file."/config/file/location".source = ./config.file; 
  };
}

Also here’s what my default.nix really looks like if you need that

{ pkgs, lib, ... }: {
  imports = [
    ./module1/module1.nix
    ./module2/module2.nix
    ./module3/module3.nix
  ];
}

besides your obfuscations there isnothing out of the ordinary, please provide an SSCCE.

2 Likes

Great, but where in your config do you import this file?
I’m guessing you forgot to do so as I implied in my first comment, and that’s why you have the error.

(Setting homeManagerModules in your flake does not count as importing; that’s not going to automatically make it part of your HM config.)

2 Likes

I didn’t import it. Doesn’t Nix look for a default.nix file without having to import it?

If you import a directory, nix will look for a default.nix in that directory.
But again, I don’t see where you imported modules or modules/default.nix in your config.

# configuration.nix

{ config, lib, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ./../../modules
    ];

  # ...

  system.stateVersion = "24.11"; # Did you read the comment?

}
# home.nix
{ config, pkgs, inputs, ... }:

{
  home.username = "sproink";
  home.homeDirectory = "/home/sproink";

  imports = [
    ./../../modules
  ];

  # ...

  home.stateVersion = "24.11";
  programs.home-manager.enable = true;
}

I’ve imported the modules folder into both configuration.nix and home.nix. It still throws the same error after rebuilding with sudo nixos-rebuild switch.

Then, as requested by about 4 different people, we need a minimal example that demonstrates the issue, i.e. something that we can build and get the same error as you, because we’re not seeing the full picture.

1 Like

Are system and HM importing the same modules folder?

This would then also imply that you import HM modules into system scope and system modules into HM scope.

This is not possible.

Make a clear distinction between system and HM modules and import them into the correct scope

2 Likes

I’ve created 2 folders for HM modules and system modules and imported both of them into flake.nix, and I have a home-manager.nix file in the folder for system modules for the configuration of HM. I now get a different error saying

error:
       … while calling the 'seq' builtin
         at /nix/store/wshnc0kqk1qz7iffb1yqri8a5cy6v7w5-source/lib/modules.nix:334:18:
          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          335|         _module = checked (config._module);

       … while calling the 'throw' builtin
         at /nix/store/wshnc0kqk1qz7iffb1yqri8a5cy6v7w5-source/lib/modules.nix:310:18:
          309|                     ''
          310|             else throw baseMsg
             |                  ^
          311|         else null;

       error: The option `home-manager' does not exist. Definition values:
       - In `/nix/store/w758824abw4miy4hg1m0hdccv0xd8iwf-source/nixosModules/home-manager.nix'

Also here’s what home-manager.nix looks like:

# home-manager.nix
{ inputs, ... }: {
  home-manager = {
    extraSpecialArgs = { inherit inputs; };
    users = {
      modules = [
        ./home.nix
        inputs.self.outputs.homeManagerModules.default
      ];
    };
  };
}

I’m guessing you didn’t import the nixos module that adds the HM options.
But again, I’m guessing, because you haven’t shared a complete example config (or the actual config) as we asked.
I’ll have to leave this thread until you’re willing to provide that.

Alright here’s an SSCCE:

# module

{ pkgs, lib, config, ... }: {
  options = {
    modulename.enable =
      lib.mkEnableOption "modulename";
  };

  config = lib.mkIf config.modulename.enable {
    # ...
  };
}

# flake.nix
{
  # ...

  outputs = { nixpkgs, ... }@inputs: {
    nixosConfigurations = {
      sproink-nix = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = { inherit inputs; };
        modules = [
          ./hosts/desktop/configuration.nix
          ./nixosModules
        ];
      };
    };

    homeManagerModules.default = ./homeManagerModules;
  };
}
# home manager module in nixosModules (home-manager.nix)
{ inputs, ... }: {
  home-manager = {
    extraSpecialArgs = { inherit inputs; };
    users = {
      modules = [
        ./../hosts/desktop/home.nix
        inputs.self.outputs.homeManagerModules.default
      ];
    };
  };
}
# default.nix (homeManagerModules)
{ lib, ... }: {
  imports = [
    # ...
  ];
}

# default.nix (nixosModules)
{ lib, ... }: {
  imports = [
    ./home-manager.nix
  ];
}

This is not a selfcontained example…

There is far too much you left out. In general, in an SSCCE we never have to add or edit something on our own.

Idieall you make your example git cloneable, such that we can easily inspect it locally and play with it, produce traces as we need them etc.

Alright, made a repository for it here: GitHub - fakesproink/nixos-configuration: Personal NixOS configuration with Flakes and Home Manager.

diff --git a/flake.nix b/flake.nix
index 372079f..79ac073 100644
--- a/flake.nix
+++ b/flake.nix
@@ -23,6 +23,7 @@
         system = "x86_64-linux";
         specialArgs = { inherit inputs; };
         modules = [
+          inputs.home-manager.nixosModules.home-manager
           ./hosts/desktop/configuration.nix
           ./nixosModules
         ];
diff --git a/nixosModules/home-manager.nix b/nixosModules/home-manager.nix
index 995485c..a756a88 100644
--- a/nixosModules/home-manager.nix
+++ b/nixosModules/home-manager.nix
@@ -2,7 +2,7 @@
   home-manager = {
     extraSpecialArgs = { inherit inputs; };
     users = {
-      modules = [
+      sproink.imports = [
         ./../hosts/desktop/home.nix
         inputs.self.outputs.homeManagerModules.default
       ];

I’ll leave the remaining “The option … does not exist” to you or another thread. As thats a mixture of hallucinating options and missing programs.* or services.* “prefixes”.


edit

Using the following for nixosModules/home-manager.nix is slightly more idiomatic:

diff --git a/nixosModules/home-manager.nix b/nixosModules/home-manager.nix
index 995485c..b1dfe76 100644
--- a/nixosModules/home-manager.nix
+++ b/nixosModules/home-manager.nix
@@ -1,11 +1,7 @@
 { inputs, ... }: {
   home-manager = {
     extraSpecialArgs = { inherit inputs; };
-    users = {
-      modules = [
-        ./../hosts/desktop/home.nix
-        inputs.self.outputs.homeManagerModules.default
-      ];
-    };
+    sharedModules = [inputs.self.outputs.homeManagerModules.default];
+    users.sproink = ./../hosts/desktop/home.nix;
   };
 }