fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.9 KiB71 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5{
6  meta.maintainers = [ maintainers.somasis ];
7
8  options = {
9    services.sctd = {
10      enable = mkEnableOption "sctd";
11
12      baseTemperature = mkOption {
13        type = types.ints.between 2500 9000;
14        default = 4500;
15        description = ''
16          The base color temperature used by sctd, which should be between 2500 and 9000.
17          See
18          {manpage}`sctd(1)`
19          for more details.
20        '';
21      };
22    };
23  };
24
25  config = mkIf config.services.sctd.enable {
26    assertions =
27      [ (hm.assertions.assertPlatform "services.sctd" pkgs platforms.linux) ];
28
29    systemd.user.services.sctd = {
30      Unit = {
31        Description =
32          "Dynamically adjust the screen color temperature twice every minute";
33        After = [ "graphical-session-pre.target" ];
34        PartOf = [ "graphical-session.target" ];
35      };
36
37      Install.WantedBy = [ "graphical-session.target" ];
38
39      Service = {
40        ExecStart = "${pkgs.sct}/bin/sctd ${
41            toString config.services.sctd.baseTemperature
42          }";
43        ExecStopPost = "${pkgs.sct}/bin/sct";
44        Restart = "on-abnormal";
45        SuccessExitStatus = 1;
46
47        Environment = let
48          # HACK: Remove duplicate messages in the journal; `sctd` calls
49          #       both `logger -s` (which outputs the message to stderr)
50          #       *and* outputs to stderr itself. We can at least silence
51          #       `logger`'s output without hiding sctd's own stderr.
52          logger = pkgs.writeShellScriptBin "logger" ''
53            exec 2>/dev/null
54            exec ${pkgs.util-linux}/bin/logger "$@"
55          '';
56        in [
57          "PATH=${
58            lib.makeBinPath [
59              pkgs.bash
60              pkgs.coreutils
61              pkgs.gnused
62              pkgs.which
63              pkgs.sct
64              logger
65            ]
66          }"
67        ];
68      };
69    };
70  };
71}