blueprint icon indicating copy to clipboard operation
blueprint copied to clipboard

Help needed with understanding standalone vs nixos module for home-manager

Open ecribia opened this issue 8 months ago • 4 comments

Hi. I've read the docs and searched for an answer here on github, but i dont really understand how blueprint handles home-manager.

Users are also standalone Home Manager configurations. A user defined as hosts/pc1/users/max.nix can be applied using the home-manager CLI as .#max@pc1

If home-manager is an input to the flake, each host with any users defined will have the appropriate home-manager module imported and each user created automatically

So if I create hosts/pc1/users/max.nix, will that be treated as a standalone home-manager exclusively? And in the second case with the home-manager imported inside of flake.nix, it will create a nixos module for each user?

Sorry I am a bit confused on how this works in blueprint. I've only worked with vanilla flakes before.

For my specific use case, i need some machines to be a nixos module, and some standalone.

ecribia avatar Apr 21 '25 03:04 ecribia

Since I use three setups – NixOS, nix-darwin, and home-manager standalone – I hope my examples will be helpful.

I used to write my configurations with a vanilla flake.nix, but now I use blueprint, so I'll provide examples of both.

vanilla flake.nix

This is part of my flake.nix when I was using vanilla flakes.

{
  inputs = {
    nixpkgs.url = "nixpkgs/nixos-24.11";
    nixpkgs-darwin.url = "github:nixos/nixpkgs/nixpkgs-24.11-darwin";

    nix-darwin = {
      url = "github:lnl7/nix-darwin/nix-darwin-24.11";
      inputs.nixpkgs.follows = "nixpkgs-darwin";
    };

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

  };

  outputs =
    {
      nixpkgs,
      nix-darwin,
      home-manager,
      ...
    }@inputs:
    {
      # sudo nixos-rebuild switch --flake .
      nixosConfigurations."my-nixos-machine" = nixpkgs.lib.nixosSystem rec {
        system = "x86_64-linux";
        specialArgs = {
          inherit inputs system;
        };
        modules = [
          home-manager.nixosModules.home-manager
          ./hosts/my-nixos-machine/configuration.nix
        ];
      };

      # darwin-rebuild switch --flake .
      darwinConfigurations."my-darwin-machine" = nix-darwin.lib.darwinSystem rec {
        system = "aarch64-darwin";
        specialArgs = {
          inherit inputs system;
        };
        modules = [
          home-manager.darwinModules.home-manager
          ./hosts/my-darwin-machine/darwin-configuration.nix
        ];
      };

      # home-manager switch --flake .
      homeConfigurations."me@my-hm-standalone-machine" = home-manager.lib.homeManagerConfiguration {
        pkgs = import nixpkgs { system = "x86_64-linux"; };
        modules = [ ./hosts/my-hm-standalone-machine/users/me.nix ];
      };

    };
}

blueprint

This is the structure of my machines with blueprint.

├── hosts
│   ├── my-darwin-machine
│   │   ├── darwin-configuration.nix
│   │   └── users
│   │       └── me.nix
│   ├── my-hm-standlone-machine
│   │   └── users
│   │       └── me.nix
│   ├── my-nixos-machine
│   │   ├── configuration.nix
│   │   └── users
│   │       └── me.nix

All the definitions written in vanilla flake.nix are done by blueprints, so you don't need to write them yourself.

https://github.com/numtide/blueprint/blob/49bbd5d072b577072f4a1d07d4b0621ecce768af/lib/default.nix#L352 https://github.com/numtide/blueprint/blob/49bbd5d072b577072f4a1d07d4b0621ecce768af/lib/default.nix#L372 https://github.com/numtide/blueprint/blob/49bbd5d072b577072f4a1d07d4b0621ecce768af/lib/default.nix#L293

sudo nixos-rebuild switch --flake .#my-nixos-machine
darwin-rebuild switch --flake .#my-darwin-machine
home-manager switch --flake .#my-hm-standalone-machine

shirakami-chigusa avatar Apr 21 '25 07:04 shirakami-chigusa

Thanks a lot for the answer!

Sorry, but I think i was unclear with my initial post. All my machines have NixOS installed. But i like to have my PCs use standalone home-managers and servers to run a nixos module for home-manager.

So looking at the source code and the example you sent me, it seems like all declared hosts with NixOS (configuration.nix), will have the module installed instead of a standalone home-manager? Is there a simple way to bypass this, so i can have standalone home-managers for some of these hosts?

Edit: With the help of your information, i understand the other issues created here better. If i understand those correctly, i can put this inside of my host configuration.nix to make them not use the nixos module, and instead the standalone home-manager.

home-manager.users = lib.mkForce { };

Will try it later today and come back with the results :)

ecribia avatar Apr 21 '25 11:04 ecribia

Thanks a lot for the answer!

Sorry, but I think i was unclear with my initial post. All my machines have NixOS installed. But i like to have my PCs use standalone home-managers and servers to run a nixos module for home-manager.

So looking at the source code and the example you sent me, it seems like all declared hosts with NixOS (configuration.nix), will have the module installed instead of a standalone home-manager? Is there a simple way to bypass this, so i can have standalone home-managers for some of these hosts?

Edit: With the help of your information, i understand the other issues created here better. If i understand those correctly, i can put this inside of my host configuration.nix to make them not use the nixos module, and instead the standalone home-manager.

home-manager.users = lib.mkForce { };

Will try it later today and come back with the results :)

there is a pr in the making to have a top level /users for standalone configs #77

JumpIn-Git avatar Apr 21 '25 15:04 JumpIn-Git

Awesome.

Adding home-manager.users = lib.mkForce { }; has worked so far for me :)

Still have a few things to get in order, but I'll get there. Thanks a ton for the help!

ecribia avatar Apr 22 '25 02:04 ecribia