1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.redshift;
8
9in {
10
11 options.services.redshift = {
12 enable = mkOption {
13 type = types.bool;
14 default = false;
15 example = true;
16 description = ''
17 Enable Redshift to change your screen's colour temperature depending on
18 the time of day.
19 '';
20 };
21
22 latitude = mkOption {
23 type = types.str;
24 description = ''
25 Your current latitude.
26 '';
27 };
28
29 longitude = mkOption {
30 type = types.str;
31 description = ''
32 Your current longitude.
33 '';
34 };
35
36 temperature = {
37 day = mkOption {
38 type = types.int;
39 default = 5500;
40 description = ''
41 Colour temperature to use during the day.
42 '';
43 };
44 night = mkOption {
45 type = types.int;
46 default = 3700;
47 description = ''
48 Colour temperature to use at night.
49 '';
50 };
51 };
52
53 brightness = {
54 day = mkOption {
55 type = types.str;
56 default = "1";
57 description = ''
58 Screen brightness to apply during the day,
59 between <literal>0.1</literal> and <literal>1.0</literal>.
60 '';
61 };
62 night = mkOption {
63 type = types.str;
64 default = "1";
65 description = ''
66 Screen brightness to apply during the night,
67 between <literal>0.1</literal> and <literal>1.0</literal>.
68 '';
69 };
70 };
71
72 package = mkOption {
73 type = types.package;
74 default = pkgs.redshift;
75 description = ''
76 redshift derivation to use.
77 '';
78 };
79
80 extraOptions = mkOption {
81 type = types.listOf types.str;
82 default = [];
83 example = [ "-v" "-m randr" ];
84 description = ''
85 Additional command-line arguments to pass to
86 <command>redshift</command>.
87 '';
88 };
89 };
90
91 config = mkIf cfg.enable {
92 systemd.services.redshift = {
93 description = "Redshift colour temperature adjuster";
94 requires = [ "display-manager.service" ];
95 after = [ "display-manager.service" ];
96 wantedBy = [ "graphical.target" ];
97 serviceConfig.ExecStart = ''
98 ${cfg.package}/bin/redshift \
99 -l ${cfg.latitude}:${cfg.longitude} \
100 -t ${toString cfg.temperature.day}:${toString cfg.temperature.night} \
101 -b ${toString cfg.brightness.day}:${toString cfg.brightness.night} \
102 ${lib.strings.concatStringsSep " " cfg.extraOptions}
103 '';
104 environment = { DISPLAY = ":0"; };
105 serviceConfig.Restart = "always";
106 };
107 };
108
109}