nix-community / home-manager

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

Expose `modules` ? #5280

Open drupol opened 2 months ago

drupol commented 2 months ago

Hello,

I'm working on a project which let you create multiple HM profiles easily, just by creating some directories. To build a profile, I use:

  inputs.home-manager.lib.homeManagerConfiguration {
    modules = [
      (./. + "/../profiles/base/")
      (./. + "/../profiles/${profile}/")
    ];
  };

Then, I extended the features of the project, and it is now able to build a full NixOS configuration including any HM profile.

However, when I build the NixOS vm, typically I use:

  inputs.nixpkgs.lib.nixosSystem {
    inherit system;
    modules = [
      inputs.home-manager.nixosModules.home-manager
      ({
        home-manager = {
          users."${username}".imports = [
            ../profiles/base
            (../profiles + "/${profile}")
          ];
        };
      })
    ];
  };

I'm opening this issue to know if it would be possible to re-use the existing profile when building the NixOS system. Hypothetically, something like this:

  inputs.nixpkgs.lib.nixosSystem {
    inherit system;
    modules = [
      inputs.home-manager.nixosModules.home-manager
      ({
        home-manager = {
          users."${username}".imports = inputs.self.homeConfigurations.profile-name."<something-here>";
        };
      })
    ];
  };

Do you know if there's something similar that can be used?

Thanks!

rycee commented 2 months ago

Something of a wild guess but have you tried

users."${username}".imports = inputs.self.homeConfigurations.profile-name.config;

?

drupol commented 2 months ago

Yes I tried:

users."${username}".imports = inputs.self.homeConfigurations.profile-name.config;

and

users."${username}" = inputs.self.homeConfigurations.profile-name.config;

Without much luck.

terlar commented 2 months ago

What I did earlier for this was to expose the modules themselves without the usage of the homeManagerConfiguration function under something like homeModules. Then they can be used both in Home Manager configurations or under Home Manager nested within NixOS.

drupol commented 2 months ago

That's my last minute safety measure if I don't find a more graceful way to do it.