system-manager icon indicating copy to clipboard operation
system-manager copied to clipboard

Home-manager as module

Open RAVENz46 opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe.

Currently, to upgrade packages, we need to run system-manager switch and home-manager switch separetly.

Describe the solution you'd like

It would be nice intagrating home-manager like nixos-modules, nix-darwin, nix-os-droid.

Describe alternatives you've considered

Alias💩?

Additional context

RAVENz46 avatar Aug 20 '24 13:08 RAVENz46

Did you try just including HM in the same way as you do on nixos? Did anything break?

r-vdp avatar Aug 20 '24 17:08 r-vdp

@r-vdp

I've tried to mimic how nix-darwin is configured for home-manager here.

The relevant code is:

    mkHome = username: modules: {
      home-manager = {
        useGlobalPkgs = true;
        useUserPackages = true;
        backupFileExtension = "backup";
        extraSpecialArgs = { inherit inputs username; };
        users."${username}".imports = modules;
      };
    };
    globalModules = { username }: [
      (mkHome username [
        ./modules/home-manager
        inputs.nixvim.homeManagerModules.nixvim
      ])
    ];
    globalModulesSystemManager = { system, username }: globalModules { inherit username; } ++ [
      ./modules/system-manager
      (home-manager system).nixosModules.home-manager
    ];

...


    systemConfigs.default = let
      system = "x86_64-linux";
    in inputs.system-manager.lib.makeSystemConfig {
      extraSpecialArgs = { inherit username; };
      modules = (globalModulesSystemManager { inherit system username; });
    };

When I try to build this, I get the following error:

       … while evaluating the attribute 'value'
         at /nix/store/x615nvk9kw68cmsg01aahd1v0kzv9ifn-source/lib/modules.nix:619:53:
          618|                 (n: value:
          619|                   [{ inherit (module) file; inherit value; }]
             |                                                     ^
          620|                 )

       error: attribute 'name' missing
       at /nix/store/h9yqjv446d8x118pkzx5kxgj5yvds9a5-home-manager/nixos/common.nix:34:27:
           33|
           34|           home.username = config.users.users.${name}.name;
             |                           ^
           35|           home.homeDirectory = config.users.users.${name}.home;

I am not sure why darwin flavor of the home-manager module works, but it looks like the nixosModules.home-manager doesn't get name passed to the module. I tried to add name = username; to extraSpecialArgs but it doesn't seem to help. I am not sure how to bend all of it to make it work, since I am still vague on how all the layers of indirection. I wonder if you have some specific idea on how to fix this.

booxter avatar Sep 09 '24 00:09 booxter

@booxter to pass args to new nixosModules instead of homeManagerModules you rather use specialArgs.

573 avatar Jul 24 '25 09:07 573