summary refs log tree commit diff
path: root/nixos/modules/services/x11/redshift.nix
blob: b9ad962d8e46b8ab97049701272f76020cf2011d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{ config, pkgs, ... }:
with pkgs.lib;
let
  cfg = config.services.redshift;

in {
  options = {
    services.redshift.enable = mkOption {
      type = types.bool;
      default = false;
      example = true;
      description = "Enable Redshift to change your screen's colour temperature depending on the time of day";
    };

    services.redshift.latitude = mkOption {
      description = "Your current latitude";
      type = types.string;
    };

    services.redshift.longitude = mkOption {
      description = "Your current longitude";
      type = types.string;
    };

    services.redshift.temperature = {
      day = mkOption {
        description = "Colour temperature to use during day time";
        default = 5500;
        type = types.int;
      };
      night = mkOption {
        description = "Colour temperature to use during night time";
        default = 3700;
        type = types.int;
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.redshift = {
      description = "Redshift colour temperature adjuster";
      requires = [ "display-manager.service" ];
      after = [ "display-manager.service" ];
      script = ''
        ${pkgs.redshift}/bin/redshift \
          -l ${cfg.latitude}:${cfg.longitude} \
          -t ${toString cfg.temperature.day}:${toString cfg.temperature.night}
      '';
      environment = { DISPLAY = ":0"; };
      serviceConfig.Restart = "always";
    };
  };
}