After I quit Tradebyte, I'm now only having a single user account. It makes sense to restructure the home-manager configuration.
130 lines
3.4 KiB
Nix
130 lines
3.4 KiB
Nix
{ 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.toml";
|
|
dark = "alacritty-dark.toml";
|
|
target = "alacritty.toml";
|
|
}
|
|
{
|
|
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" ];
|
|
}
|
|
{
|
|
dir = "~/.config/waybar";
|
|
light = "theme-light.css";
|
|
dark = "theme-dark.css";
|
|
target = "theme.css";
|
|
exec = [ "${pkgs.systemd}/bin/systemctl" "--user" "restart" "waybar.service" ];
|
|
}
|
|
{
|
|
exec = (
|
|
if nixosConfig.jalr.gui.enable
|
|
then [ "/usr/bin/env" "gsettings" "set" "org.gnome.desktop.interface" "color-scheme" "prefer-%scheme%" ]
|
|
else null
|
|
);
|
|
}
|
|
];
|
|
dynamic-colors = pkgs.writers.writePython3Bin "dynamic-colors" { } ''
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def main():
|
|
DEFAULT_SCHEME = 'light'
|
|
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:]
|
|
|
|
scheme = None
|
|
if command in ('light', 'dark'):
|
|
scheme = command
|
|
elif command == 'install':
|
|
pass
|
|
else:
|
|
raise NotImplementedError
|
|
|
|
for entry in config:
|
|
directory = (
|
|
pathlib.Path(entry['dir']).expanduser() if 'dir' in entry else None
|
|
)
|
|
if all(key in entry for key in (
|
|
'target',
|
|
'light',
|
|
'dark'
|
|
)):
|
|
target = directory.joinpath(entry['target'])
|
|
|
|
if scheme is None:
|
|
if target.exists():
|
|
continue
|
|
scheme = DEFAULT_SCHEME
|
|
else:
|
|
if target.exists() and target.is_symlink:
|
|
os.remove(target)
|
|
|
|
src = {
|
|
'light': entry['light'],
|
|
'dark': entry['dark'],
|
|
}[scheme]
|
|
|
|
try:
|
|
os.symlink(src, target)
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
if entry.get('exec') is not None:
|
|
command, *args = entry["exec"]
|
|
args = [
|
|
arg.replace(
|
|
'%scheme%', scheme
|
|
if scheme is not None
|
|
else DEFAULT_SCHEME
|
|
)
|
|
for arg in args
|
|
]
|
|
print(command, *args)
|
|
try:
|
|
subprocess.run(
|
|
(command, *args),
|
|
cwd=directory
|
|
)
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
|
|
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
|
|
];
|
|
}
|