stockholm/lass/2configs/themes.nix

67 lines
2.0 KiB
Nix
Raw Normal View History

2022-04-04 16:19:51 +00:00
{ config, lib, pkgs, ... }: let
switch-theme = pkgs.writers.writeDashBin "switch-theme" ''
2022-04-15 16:42:28 +00:00
set -efux
if [ "$1" = toggle ]; then
if [ "$(${pkgs.coreutils}/bin/cat /var/theme/current_theme)" = dark ]; then
${placeholder "out"}/bin/switch-theme light
else
${placeholder "out"}/bin/switch-theme dark
fi
elif test -e "/etc/themes/$1"; then
${pkgs.coreutils}/bin/mkdir -p /var/theme/config
2022-04-04 16:19:51 +00:00
${pkgs.rsync}/bin/rsync --chown=lass:users -a --delete "/etc/themes/$1/" /var/theme/config/
echo "$1" > /var/theme/current_theme
2022-04-15 16:42:28 +00:00
${pkgs.coreutils}/bin/chown lass:users /var/theme/current_theme
2022-05-10 16:57:57 +00:00
${pkgs.xorg.xrdb}/bin/xrdb -merge /var/theme/config/xresources
2022-04-04 16:19:51 +00:00
${pkgs.procps}/bin/pkill -HUP xsettingsd
else
echo "theme $1 not found"
fi
'';
in {
systemd.services.xsettingsd = {
wantedBy = [ "multi-user.target" ];
2022-04-15 16:42:28 +00:00
after = [ "display-manager.service" ];
2022-04-04 16:19:51 +00:00
environment.DISPLAY = ":0";
serviceConfig = {
ExecStart = "${pkgs.xsettingsd}/bin/xsettingsd -c /var/theme/config/xsettings.conf";
User = "lass";
2022-05-10 16:57:57 +00:00
Restart = "always";
RestartSec = "15s";
2022-04-04 16:19:51 +00:00
};
};
systemd.tmpfiles.rules = [
"d /var/theme/ 755 lass users"
];
environment.systemPackages = [
switch-theme
];
environment.etc = {
"themes/light/xsettings.conf".text = ''
Net/ThemeName "Adwaita"
'';
2022-05-10 16:57:57 +00:00
"themes/light/xresources".text = ''
*background: #ffffff
*foreground: #000000
'';
2022-04-04 16:19:51 +00:00
"themes/dark/xsettings.conf".text = ''
Net/ThemeName "Adwaita-dark"
'';
2022-05-10 16:57:57 +00:00
"themes/dark/xresources".text = ''
*background: #000000
*foreground: #ffffff
'';
2022-04-04 16:19:51 +00:00
};
system.activationScripts.theme.text = ''
2022-05-10 16:57:57 +00:00
export DISPLAY=:0
2022-04-04 16:19:51 +00:00
if test -e /var/theme/current_theme; then
${switch-theme}/bin/switch-theme "$(cat /var/theme/current_theme)" ||
${switch-theme}/bin/switch-theme dark
else
${switch-theme}/bin/switch-theme dark
fi
'';
}