{ nixosConfig, lib, config, pkgs, ... }: let loadSwayTheme = pkgs.writeShellScript "load-sway-theme" '' while IFS= read -r line; do ${pkgs.sway}/bin/swaymsg "$line" done < "$1" ''; applicationConfig = [ { dir = "~/.config/alacritty"; light = "alacritty-light.yml"; dark = "alacritty-dark.yml"; target = "alacritty.yml"; } { dir = "~/.config/wofi"; light = "color-light"; dark = "color-dark"; target = "color"; } { dir = "~/.config/sway"; light = "light-theme"; dark = "dark-theme"; target = "theme"; exec = [ loadSwayTheme "theme" ]; } ]; dynamic-colors = pkgs.writers.writePython3Bin "dynamic-colors" { } '' import json import os import pathlib import subprocess import sys def main(): CONFIG_FILE = "~/.config/dynamic-colors/config.json" with open(pathlib.Path(CONFIG_FILE).expanduser(), "r") as fh: config = json.load(fh) command, = sys.argv[1:] for entry in config: directory = pathlib.Path(entry['dir']).expanduser() target = directory.joinpath(entry['target']) if command in ('light', 'dark'): if target.exists() and target.is_symlink: os.remove(target) src = { 'light': entry['light'], 'dark': entry['dark'], }[command] os.symlink(src, target) else: if target.exists(): continue os.symlink(entry['light'], target) if 'exec' in entry: subprocess.run(entry['exec'], cwd=directory) if __name__ == '__main__': main() ''; in { xdg.configFile."dynamic-colors/config.json" = { text = lib.generators.toJSON { } applicationConfig; onChange = "${dynamic-colors}/bin/dynamic-colors install"; }; home.packages = [ dynamic-colors ]; }