Home-manager specializations for light and dark themes

Has anyone here successfully used home-manager specializations (rather than NixOS specialisations) to switch between themes or light/dark modes during runtime with an activation script?

I found this post and looked through rycee’s config to replicate it for myself.

However, I use home-manager as a module in my NixOS flake rather than standalone, which might be conflicting somehow with specializations.

For example, I have options like this:

  options = {
    theme = {
      colors = lib.mkOption {
        type = lib.types.attrs;
        description = "Base16 color scheme.";
        default = (import ../modules/colorscheme/gruvbox).dark;
      };
      dark = lib.mkOption {
        type = lib.types.bool;
        description = "Enable dark mode.";
        default = true;
      };
    };
  };

And config like this:

  config = {
    home-manager.users.${config.user}.specialization.light.configuration = {
      theme = {
        colors = (import ../modules/colorscheme/gruvbox).light;
        dark = false;
      };
    };
  };

But I get errors when rebuilding:

error: The option `home-manager.users.noah.specialization.light.configuration.theme' does not exist.

you misspelled specialisation, everything else looks right, though.

It was actually renamed in 2023 in Home-Manager from specialization.

I haven’t tried it in a few years, though, so it might be worth revisiting to see if it works now. :slight_smile:

oh! that’s absolutely my bad. i use them and they seem to work pretty well, but some fiddling is required for a command to switch between specialisations.

How do you switch between home-manager specializations?

It is a bit fiddly, as you have to figure out the location of the activation script yourself, but it is described in the HM manual:

https://nix-community.github.io/home-manager/options.xhtml#opt-specialisation