Home manager `stylix.targets.tmux.enable = false;` has unexpected (and wrong?) behaviour

Today I discovered stylix.
I applied stylix with flake and with minimal configurations:

  stylix = {
    enable = true;
    base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-dark-hard.yaml";
  };

I also use home-manager nixos module.

After a nixos-rebuild switch, it messed up the color of tmux I set in home-manager.
I inspect ~/.config/tmux/tumx.conf, there is a special line responsible to this which was inserted by stylix:

source-file /nix/store/eeeeeeeeeeeeeeeeeeeeee-base16-gruvbox-dark-hard.conf

So I tried to set stylix.targets.tmux.enable = false; in home-manager and do a nixos-rebuild switch to get rid of this line, but it failed.

After some trial and error, I found that I have to explicitly do some tricks with TWO nixos-rebuild swich to achieve it.
The steps are as follow:

  1. Explicitly also set stylix.autoEnable = false; in home-manager and do a nixos-rebuild switch to disable all the theme applied to home-manager by stylix.
  2. Then I remove stylix.autoEnable = false; in home-manager, and explicitly set stylix.targets.tmux.enable = false; in home-manager, and do a nixos-rebuild switch. This time the above source-file /nix/store/eeee....dark-hard.conf disappeared in ~/.config/tmux/tmux.conf

I think nix should not behave this way.

It doesn’t, and none of the code in stylix suggests that anything funky would be happening here.

It’s most likely your configuration just didn’t enable; perhaps you forgot to actually switch, missed an error message, or maybe the home-manager activation script failed because of an unrelated change.

Either way, nix isn’t stateful like this; while I don’t intend to gaslight you, the precise sequence you’re describing is simply not possible. There’s probably a better explanation, but you’re unintentionally omitting part of it. Without replicating your exact scenario it’s impossible to know what happened.

If you’d like to, try reverting to just defining one of the options and then re-enabling the other option. If you really make no other changes in-between, you should no longer be able to reproduce what you’ve seen; If you can, that’s likely a home-manager bug, but you’d need to at least share your logs to see what’s going on (journalctl --user -xe will include the home-manager activation logs).

Thanks for your advice.
I ran journalctl --user -xe and I found that there are some log about nix crash
I think that should be the reason for that.
And actually I am using nh instead of nixos-rebuild, mayby nh may display differently or maybe I missed the message about nix crash.