From aa02d6ce2d9019546d5579a7ab301f1564133356 Mon Sep 17 00:00:00 2001 From: iFargle Date: Tue, 2 Jan 2024 22:02:53 +0900 Subject: [PATCH] Tsting systemd timers and services instead of cron --- nixos/common/desktops/plasma6/default.nix | 50 +++++++++++++++++------ 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/nixos/common/desktops/plasma6/default.nix b/nixos/common/desktops/plasma6/default.nix index 70ae719c..bde302b2 100644 --- a/nixos/common/desktops/plasma6/default.nix +++ b/nixos/common/desktops/plasma6/default.nix @@ -35,18 +35,42 @@ tailscale-systray ]; - # Schedule cronjobs for changing the theme - services.cron = { - enable = true; - systemCronJobs = [ - # Set the 'at' jobs for changing the theme - ''0 12 * * * albert curl -s wttr.in?format=j1 > /tmp/wttr.in'' - ''0 * * * * albert sleep 10; echo "plasma-apply-colorscheme -platform offscreen Arc" | at `fx /tmp/wttr.in .weather[0].astronomy[0].sunrise`'' - ''0 * * * * albert sleep 10; echo "plasma-apply-colorscheme -platform offscreen ArcDark" | at `fx /tmp/wttr.in .weather[0].astronomy[0].sunset` '' - # At reboot as well - ''@reboot albert curl -s wttr.in?format=j1 > /tmp/wttr.in'' - ''@reboot albert sleep 10; echo "plasma-apply-colorscheme -platform offscreen Arc" | at `fx /tmp/wttr.in .weather[0].astronomy[0].sunrise`'' - ''@reboot albert sleep 10; echo "plasma-apply-colorscheme -platform offscreen ArcDark" | at `fx /tmp/wttr.in .weather[0].astronomy[0].sunset` '' - ]; + systemd.services = { + "get-theme-times" = { + enable = true; + path = [ pkgs.curl ]; + script = "curl wttr.in > /tmp/wttr.in"; + after = [ "networking-online.target" ]; + serviceConfig.Type = "oneshot"; + onSucces = [ + "light-theme.service" + "dark-theme.service" + ]; + }; + light-theme = { + enable = true; + path = [ pkgs.at pkgs.fx]; + script = ''echo "plasma-apply-colorscheme -platform offscreen Arc" | at `fx /tmp/wttr.in .weather[0].astronomy[0].sunrise`''; + serviceConfig.Type = "oneshot"; + }; + dark-theme = { + enable = true; + path = [ pkgs.at pkgs.fx]; + script = ''echo "plasma-apply-colorscheme -platform offscreen ArcDark" | at `fx /tmp/wttr.in .weather[0].astronomy[0].sunset`''; + serviceConfig.Type = "oneshot"; + }; + }; + + systemd.timers = { + "light-theme" = { + enable = true; + partOf = [ "light-theme.service" ]; + timerConfig.OnCalendar = [ "*-*-* *:*:00" ]; + }; + "dark-theme" = { + enable = true; + partOf = [ "dark-theme.service" ]; + timerConfig.OnCalendar = [ "*-*-* *:*:00" ]; + }; }; }