diff --git a/nixos/common/desktops/plasma6/default.nix b/nixos/common/desktops/plasma6/default.nix index 23b8f00f..66290bcb 100644 --- a/nixos/common/desktops/plasma6/default.nix +++ b/nixos/common/desktops/plasma6/default.nix @@ -1,4 +1,9 @@ { pkgs, ... }: { + + imports = [ + # ./set-darkmode-service.nix + ]; + # Enable sound with pipewire. security.rtkit.enable = true; services.pipewire = { @@ -29,68 +34,4 @@ services.xrdp.defaultWindowManager = "startplasma-x11"; services.displayManager.sddm.settings.General.DisplayServer = "x11-user"; services.geoclue2.enable = true; - - systemd.user.services = { - "get-theme-times" = { - enable = false; - path = [ pkgs.curl pkgs.fx ]; - script = '' - echo "Activating get-theme-times systemd service" - curl -s "https://api.sunrise-sunset.org/json?lat=35.680&lng=135.03&tzid=Asia/Tokyo" | fx .results.sunrise > /tmp/wttr.sunrise - curl -s "https://api.sunrise-sunset.org/json?lat=35.680&lng=135.03&tzid=Asia/Tokyo" | fx .results.sunset > /tmp/wttr.sunset - chmod ogu+rw /tmp/wttr.sunset /tmp/wttr.sunrise - echo "get-theme-times - complete" - ''; - after = [ "networking-online.target" ]; - serviceConfig.Type = "oneshot"; - onSuccess = [ "set-theme.service" ]; - }; - set-theme = { - enable = false; - script = '' - #!/bin/env bash - echo "set-theme.service - Checking for theme settings" - if [ ! -f /tmp/wttr.sunrise ] ; then - systemctl --user start get-theme-times.service - fi - echo "Getting dates:" - SUNRISE=`date --date="$(cat /tmp/wttr.sunrise)" +%s` - echo "Sunrise: $SUNRISE" - SUNSET=`date --date="$(cat /tmp/wttr.sunset)" +%s` - echo "Sunset: $SUNSET" - CURRENT=`date +%s` - echo "Current: $CURRENT" - if [ $CURRENT -gt $SUNRISE -a $CURRENT -lt $SUNSET ] ; then - # /run/current-system/sw/bin/plasma-apply-colorscheme -system offscreen Arc - /run/current-system/sw/bin/plasma-apply-colorscheme Arc - else - # /run/current-system/sw/bin/plasma-apply-colorscheme -system offscreen ArcDark - /run/current-system/sw/bin/plasma-apply-colorscheme ArcDark - fi - echo "set-theme.service - Complete" - ''; - serviceConfig.Type = "oneshot"; - }; - }; - - systemd.user.timers = { - "get-theme-times" = { - enable = false; - wantedBy = [ "default.target" ]; - timerConfig = { - Unit = "get-theme-times.service"; - OnCalendar = [ "*:00" ]; - OnBootSec = [ "1min" ]; - }; - }; - "set-theme" = { - enable = false; - wantedBy = [ "default.target" ]; - timerConfig = { - Unit = "set-theme.service"; - OnCalendar = [ "*:0..59" ]; - OnBootSec = [ "2min" ]; - }; - }; - }; } diff --git a/nixos/common/desktops/plasma6/set-darkmode-service.nix b/nixos/common/desktops/plasma6/set-darkmode-service.nix new file mode 100644 index 00000000..815733b8 --- /dev/null +++ b/nixos/common/desktops/plasma6/set-darkmode-service.nix @@ -0,0 +1,65 @@ +{ pkgs, ... }: { + systemd.user.services = { + "get-theme-times" = { + enable = false; + path = [ pkgs.curl pkgs.fx ]; + script = '' + echo "Activating get-theme-times systemd service" + curl -s "https://api.sunrise-sunset.org/json?lat=35.680&lng=135.03&tzid=Asia/Tokyo" | fx .results.sunrise > /tmp/wttr.sunrise + curl -s "https://api.sunrise-sunset.org/json?lat=35.680&lng=135.03&tzid=Asia/Tokyo" | fx .results.sunset > /tmp/wttr.sunset + chmod ogu+rw /tmp/wttr.sunset /tmp/wttr.sunrise + echo "get-theme-times - complete" + ''; + after = [ "networking-online.target" ]; + serviceConfig.Type = "oneshot"; + onSuccess = [ "set-theme.service" ]; + }; + set-theme = { + enable = false; + script = '' + #!/bin/env bash + echo "set-theme.service - Checking for theme settings" + if [ ! -f /tmp/wttr.sunrise ] ; then + systemctl --user start get-theme-times.service + fi + echo "Getting dates:" + SUNRISE=`date --date="$(cat /tmp/wttr.sunrise)" +%s` + echo "Sunrise: $SUNRISE" + SUNSET=`date --date="$(cat /tmp/wttr.sunset)" +%s` + echo "Sunset: $SUNSET" + CURRENT=`date +%s` + echo "Current: $CURRENT" + if [ $CURRENT -gt $SUNRISE -a $CURRENT -lt $SUNSET ] ; then + # /run/current-system/sw/bin/plasma-apply-colorscheme -system offscreen Arc + /run/current-system/sw/bin/plasma-apply-colorscheme Arc + else + # /run/current-system/sw/bin/plasma-apply-colorscheme -system offscreen ArcDark + /run/current-system/sw/bin/plasma-apply-colorscheme ArcDark + fi + echo "set-theme.service - Complete" + ''; + serviceConfig.Type = "oneshot"; + }; + }; + + systemd.user.timers = { + "get-theme-times" = { + enable = false; + wantedBy = [ "default.target" ]; + timerConfig = { + Unit = "get-theme-times.service"; + OnCalendar = [ "*:00" ]; + OnBootSec = [ "1min" ]; + }; + }; + "set-theme" = { + enable = false; + wantedBy = [ "default.target" ]; + timerConfig = { + Unit = "set-theme.service"; + OnCalendar = [ "*:0..59" ]; + OnBootSec = [ "2min" ]; + }; + }; + }; +}