From 0ca0b91088a462d4cac888baad3c3732d6dedb51 Mon Sep 17 00:00:00 2001 From: Kylie McClain Date: Wed, 18 May 2022 21:46:53 -0400 Subject: [PATCH] sctd: add module This adds a module for enabling the `sctd` daemon, as well as setting the preferred base temperature. --- .github/CODEOWNERS | 2 ++ modules/misc/news.nix | 8 +++++ modules/modules.nix | 1 + modules/services/sctd.nix | 74 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 modules/services/sctd.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 30b4f4730..ffd63ea0b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -478,3 +478,5 @@ Makefile @thiagokokada /modules/programs/ion.nix @jo1gi /modules/services/plex-mpv-shim.nix @starcraft66 + +/modules/services/sctd.nix @somasis diff --git a/modules/misc/news.nix b/modules/misc/news.nix index a1e4db3aa..e11d81039 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -575,6 +575,14 @@ in A new module is available: 'programs.pistol'. ''; } + + { + time = "2022-06-26T19:29:25+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.sctd'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 5546825ae..3c8ca3296 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -246,6 +246,7 @@ let ./services/redshift-gammastep/redshift.nix ./services/rsibreak.nix ./services/screen-locker.nix + ./services/sctd.nix ./services/spotifyd.nix ./services/stalonetray.nix ./services/status-notifier-watcher.nix diff --git a/modules/services/sctd.nix b/modules/services/sctd.nix new file mode 100644 index 000000000..54cf53e45 --- /dev/null +++ b/modules/services/sctd.nix @@ -0,0 +1,74 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + meta.maintainers = [ maintainers.somasis ]; + + options = { + services.sctd = { + enable = mkEnableOption "sctd"; + + baseTemperature = mkOption { + type = types.ints.between 2500 9000; + default = 4500; + description = '' + The base color temperature used by sctd, which should be between 2500 and 9000. + See + + sctd + 1 + + for more details. + ''; + }; + }; + }; + + config = mkIf config.services.sctd.enable { + assertions = + [ (hm.assertions.assertPlatform "services.sctd" pkgs platforms.linux) ]; + + systemd.user.services.sctd = { + Unit = { + Description = + "Dynamically adjust the screen color temperature twice every minute"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Install.WantedBy = [ "graphical-session.target" ]; + + Service = { + ExecStart = "${pkgs.sct}/bin/sctd ${ + toString config.services.sctd.baseTemperature + }"; + ExecStopPost = "${pkgs.sct}/bin/sct"; + Restart = "on-abnormal"; + SuccessExitStatus = 1; + + Environment = let + # HACK: Remove duplicate messages in the journal; `sctd` calls + # both `logger -s` (which outputs the message to stderr) + # *and* outputs to stderr itself. We can at least silence + # `logger`'s output without hiding sctd's own stderr. + logger = pkgs.writeShellScriptBin "logger" '' + exec 2>/dev/null + exec ${pkgs.util-linux}/bin/logger "$@" + ''; + in [ + "PATH=${ + lib.makeBinPath [ + pkgs.bash + pkgs.coreutils + pkgs.gnused + pkgs.which + pkgs.sct + logger + ] + }" + ]; + }; + }; + }; +}