Need help assembling home-manager configuration

  • Config repository
    Hi, I am trying to create a more cohesive home-manager configuration. It is functioning fine for me ATM but I’d like to not have to use sudo every time I change my program configs.

This is my current flake

{
  description = "My first flake";

  inputs = {
    nixpkgs.url = "nixpkgs/nixos-26.05";
    nix-colors.url = "github:misterio77/nix-colors";

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

  outputs = { nixpkgs, home-manager, ... }@inputs:
  let
    system = "x86_64-linux";
    pkgs = inputs.nixpkgs.legacyPackages.${system};
  in {
    homeConfigurations.ari = home-manager.lib.homeManagerConfiguration {
      inherit pkgs;
      extraSpecialArgs = { inherit inputs; };
      modules = [ ./home/ari/home.nix ];
    };
    nixosConfigurations.ari-nixos = nixpkgs.lib.nixosSystem {
      # Pass inputs to all modules
      specialArgs = { inherit inputs; };
      system = system;

      modules = [
        ./configuration.nix
        home-manager.nixosModules.home-manager
        {
          home-manager.useGlobalPkgs = true;
          home-manager.useUserPackages = true;
          home-manager.extraSpecialArgs = { inherit inputs; };
          home-manager.users.ari = import ./home/ari/home.nix;
        }
      ];
    };
  };
}

My original flake can be found on the main branch of the repository. I know for a fact this is incorrect. I had to add home-manager to the system environmentPackages to be able to run the command. Commenting out the home manager config under nixosConfigurations resulted in losing all of my programs until I ran home-manager switch --flake ~/nix-dotfiles/flake.nix. The output of nix flake show looks like this

git+file:///home/ari/nix-dotfiles?ref=refs/heads/home-manager-test&rev=8b7d66830fb9f8015df53c6b29ac77c7451fcd4b
├───homeConfigurations: unknown
└───nixosConfigurations
    └───ari-nixos: NixOS configuration

Hey, please don’t answer with AI. The answer wasn’t what I was looking for and I would not be asking people on the forums if AI gave me a good answer, so all this achieves is to pollute forums where people come for answers from humans. I appreciate the intention though.

I am aware I have a mix of both the standalone and module installation of HM and I failed to mention it in my original post. My intention was to find a method that would install home-manager in a declarative manner but still allow me to use the home-manager command. Help still needed

What do you mean by “install HM in a declarative manor”?

Even though possible with tricks and awful workarounds, it is possible to have HM as a system module while being able to use the HM CLI.

It is by no means officially supported and might have subtle issues.

I am aware of 2 people who actually use it, though I don’t remember their names.

What is the problem with just using standalone?

Hi nobbz! I might be incorrect but I got the impression that a standalone home-manager install adds an additional step to setting up your NixOS. While your configuration is declarative, the actual installation portion of home-manager is implicit, i.e. you need to run an install command on top of nixos-rebuild when installing on a new system (not talking about home-manager switch, i am pretty sure you can also program your rebuilds to run that). That is if you choose the standalone method. Its a minor hiccup and thats exactly what the other method allows, but you dont get the home manager command with that and you need to rebuild when you want to see your user config changes.
Please correct me if I am wrong

Yes, it adds another step to the bootstrapping, though if you want to use the system module for easier bootstrap, you really should stick to applying your user changes using nixos-rebuild rather than home-manager.

Though indeed, if you have an already existing HM config, that you can use with the system, then bootstrapping HM is just nix run github:nix-community/home-manager -- switch --flake … or something alike.

You do not have to follow the nix-shell -A install thing that is in the docs. That is really only needed if you do a full bootstrap and do not even have an initial config, and even then you can use other templates or even start from a bare file in your editor.