Home-manager gone after nixos-rebuild switch

I just configured and switched to my standalone home config, but now whenever i do a nixos-rebuild switch. home manager is gone and i need to do nix run home-manager -- switch --flake . to get it running again, this isnt normal right? what is wrong?

Grabbing some snippets

flake.nix

{
  inputs = [
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    # ... other inputs
  ];
  outputs = {
    self,
    nixpkgs,
    home-manager,
    ...
  }@inputs: let
    inherit (self) outputs;
  in {
    # hosts
    nixosConfigurations = {
      # default x86_64-linux config...
    };
    # users
    homeConfigurations = {
      "user" = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages."x86_64-linux";
        modules = [ ./users/user/home.nix ];
        extraSpecialArgs = {
          inherit inputs;
          system = "x86_64-linux";
      };
    };
  };
}

home.nix is your standard home config file

# personal home configuration
{ config, pkgs, ... }:

{
  imports = [
    ../../modules/presets/home
  ];
  home.username = "user";
  home.homeDirectory = "/home/user";

  home.stateVersion = "24.05"; # Please read the comment before changing.

  programs.home-manager.enable = true;
}

i also define in configurations.nix

# ...
users.users.user = {
  isNormalUser = true;
  description = "a user";
  extraGroups = [ "wheel" "networkmanager" ];
  useDefaultShell = true;
  initialpassword = "pass";
};
# ...

Steps to reproduce:

$ cd /path/to/flake
$ nix run home-manager -- switch --flake .#user
// switch runs
$ home-manager build --flake .#user
// build fine
$ nixos-rebuild switch --flake .#default
// re switches to config
$ home-manager build --flake .#user
// error: no home-manager in path

What do you mean by “gone”? Is your shell configuration reverted or something like that?
It would be helpful if you could share snippets of your config.

My best guess would be that you’re both using the NixOS module and the stand-alone configuration.

1 Like

i meant gone, like, the command is gone, when i type it, i receive the error saying its not on my path. also sure lemme grab some snippets

i used to have hm as a module but am moving to standalone… i dont have any mention on hm on my configuration.nix file anymore, i moved everything to the flake and home.nix file

Fixed the error, literally i never added home-manager to environment.packages why is it that almost all tutorials teach using nix-shell instead of showing both. :frowning:

You should probably add it to home.packages instead to ensure the home-manager config is self-contained, and then bootstrap it with nix-shell.

It’s a minor detail and unlikely to come up, but this prevents your home-manager binary version from going out of sync with the actually installed profile.

1 Like

Take a look at home-manager option programs.home-manager.enable. It’s better to put user-level packages in user-level configurations.

2 Likes

but i had that exact line on already on my home.nix. even still whenever i switched my os, it would forget the home-manager command

Combining that with knowledge of your other question, sounds like your home-manager is set up in such a way that its changes to $PATH - and likely environment variables - don’t actually happen.

Make sure you source the relevant rcfile, or that you use home-manager to configure your shell.

oh damn, that must be it, i do have a file installing some tools to my cli like btop or bat. i will try disabling those, but if i wanna have those i have then to declare on my hm right? how to do that?

update: tried turning off options that would add packages for cli like btop, bat and others, but nothing changed. also turned on programs.bash.enable on my home.nix nothing much has changed

And just to be sure, you actually use bash, not zsh, fish or suchlike?

Could you share your whole config? Hard to debug a situation that I have no knowledge of.

i want to use zsh but i havent configured that yet.
i know it hard sorry, i have been trying to isolate the problem in a configuration i can share, will update when i have it done

1 Like

(small update on this) after activating programs.bash.enable i tried creating an alias using programs.bash.alias.switchos = "sudo nixos-rebuild switch"; and it worked, maybe home path is being added and the problem is another.
im still working on a flake to expose

Hey there thanks for waiting, i managed to make my nixos repo public, you can access it here im very clueless on why nixvim is not working/ only working for su user

Hey so turns out very early when i was learning nix and configuring my computer i must have mistaken nix-env by nix-shell and added neovim imperatively.
took me several weeks and removing everything on my computer to figure this out.
after removing everything now works as expected.
thanks all for the help