How might I make home-manager "theme activation scripts"?

Hear me out.

I know about wpgtk, but I really like managing all of my configurations with Nix and home-manager. I want to try tackling the challenge of configuring multiple different themes I can switch to for my home configuration.

The naive way I see of doing this is changing some theme variable in my configuration files and running home-manager switch ... every time I want to change themes. This, of course, comes with the burden of waiting for the configuration to build each time, not to mention all the other unnecessary things that have to be done to rebuild.

Here's my idea:

home-manager produces some activate script once the whole configuration is built, right? This sets all configuration files, among other things.

Would it be possible to generate a whole directory of "theme activation scripts", one script for each wallpaper/theme I have? Scripts that don't bother with systemd or other non-theme related actions, only updating symlinks or configuration files as needed to change the colors of my desktop environment window manager. Then, I could run a command (binded to a key shortcut in sway) that would select a random script in that directory and run it to set a wallpaper and a color scheme that matches that wallpaper.

For clarification, each script should contain (a path to) a wallpaper, a color theme matching that wallpaper, and the necessary commands to run that will set the theme of all apps to match the color theme.

Does anyone have any insight on this? Is this possible? Thanks so much in advance :)

TL;DR: I have a lot of wallpapers and want a way to generate an "activation script" for each one from my home-manager configuration. Each script should set the color theme or symlinks to configuration files of my apps based on a palette generated from the wallpaper tied to its activation script.

Posted Jun 14, 2022, 2:49 AM UTC

73
rycee•

You can use specializations for this. For example, I set up a light and dark theme in my configuration.

I typically build the configuration to some directory and then activate the specializations as needed:

./result/specialization/ia-dark/activate

or

./result/specialization/ia-light/activate

Unfortunately, having many specializations affect the build time quite a lot.

8
whizzythorneOP•

I think this is what I'm looking for! I'll give it a shot, thank you so much!

1
jamfour•

I consider such dynamic changes to be state. As such, I generate a script specifically for theme changing and then just run that. It’s not elegant, since it cannot re-use existing theme parts of the config, but it is fast and doesn’t create new generations. As I use impermanence, the theme gets reverted to the declarative setting on reboot.

Note that I wasn’t aware of HM Specializations when I set this up, but I still feel that treating the above as state is “better”, but that’s me.

2