[SOLVED] Home-manager creates a new (faulty) generation on reboot

I’m having an issue with home-manager on nixOS 22.05 that I don’t know how to debug: every time I reboot, home-manager gets a new generation. Worse, the new generation is faulty in the sense that it doesn’t reflect what’s in ~/.config/nixpkgs/home.nix.

I can reproduce this as follows. First (and as suggested in the home-manager manual I create a nix-channel for home-manager 22.05 and import it into configuration.nix. Then I create a new user in configuration.nix:

users.users.testuser = {
  isNormalUser = true;
  description = "Test User";
};
home-manager.users.testuser = { pkgs, ... }: {
  programs.bash.enable = true;
};

I run sudo nixos-rebuild switch and then create a /home/testuser/.config/nixpkgs/home.nix configuration that’s just slightly more complicated than the barebones one from the home-manager manual. (By the way, the manual says that "A fresh install of Home Manager will generate a minimal ~/.config/nixpkgs/home.nix", but actually I had to create that file myself.)

# Full contents of home.nix:
{ config, pkgs, ... }:
{
  home.username = "testuser";
  home.homeDirectory = "/home/testuser";
  home.stateVersion = "22.05";
  programs.home-manager.enable = true;
  home.sessionVariables = {
    FOO = 1;
  };
}

Now I run home-manager switch and it’s great. A new generation is created, and my home-manager config is reflected in ~/.nix-profile/etc/profile.d/hm-session-vars.sh, which contains the line export FOO="1"

Now comes the problem. I reboot, and after logging back in as testuser, the environment variable FOO is not set, and the file ~/.nix-profile/etc/profile.d/hm-session-vars.sh no longer contains the line export FOO="1". Using home-manager generations I see that after rebooting there’s one more generation than before the reboot. If I reactivate the previous generation, I get back the line export FOO="1" in my hm-session-vars.sh (but again, it disappears on reboot).

Can anyone help me figure out what’s going on?

Thats for the standalone installation using the nix-env <home-manager> -i install or something.

Why do you? You used the HM nixos module, you are not soposed to run the HM CLI. It is for use with standalone HM only.

Yes, because the systems HM runs its activation on each system boot or switch, so of course you will be reset to whatever HM stuff you have defined in your system configuration.

System module and standalone are mutually exclusive for a single user.

You can though use the system module for user A and standalone for user B if you omit the home-manager.users.B.

2 Likes

Thank you, that makes sense now! :pray:

I also see now that the NixOS wiki is quite clear on this point. I might try making a PR for the home-manager manual, since I still find it a little unclear.

2 Likes