numtide / system-manager

Manage system config using nix on any distro
MIT License
769 stars 21 forks source link

Home-manager as module #109

Open RAVENz46 opened 2 months ago

RAVENz46 commented 2 months ago

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

r-vdp commented 2 months ago

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

booxter commented 2 months ago

@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.