at 17.09-beta 2.9 kB view raw
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 description = '' 16 Enable Redshift to change your screen's colour temperature depending on 17 the time of day. 18 ''; 19 }; 20 21 latitude = mkOption { 22 type = types.str; 23 description = '' 24 Your current latitude, between 25 <literal>-90.0</literal> and <literal>90.0</literal>. 26 ''; 27 }; 28 29 longitude = mkOption { 30 type = types.str; 31 description = '' 32 Your current longitude, between 33 between <literal>-180.0</literal> and <literal>180.0</literal>. 34 ''; 35 }; 36 37 temperature = { 38 day = mkOption { 39 type = types.int; 40 default = 5500; 41 description = '' 42 Colour temperature to use during the day, between 43 <literal>1000</literal> and <literal>25000</literal> K. 44 ''; 45 }; 46 night = mkOption { 47 type = types.int; 48 default = 3700; 49 description = '' 50 Colour temperature to use at night, between 51 <literal>1000</literal> and <literal>25000</literal> K. 52 ''; 53 }; 54 }; 55 56 brightness = { 57 day = mkOption { 58 type = types.str; 59 default = "1"; 60 description = '' 61 Screen brightness to apply during the day, 62 between <literal>0.1</literal> and <literal>1.0</literal>. 63 ''; 64 }; 65 night = mkOption { 66 type = types.str; 67 default = "1"; 68 description = '' 69 Screen brightness to apply during the night, 70 between <literal>0.1</literal> and <literal>1.0</literal>. 71 ''; 72 }; 73 }; 74 75 package = mkOption { 76 type = types.package; 77 default = pkgs.redshift; 78 defaultText = "pkgs.redshift"; 79 description = '' 80 redshift derivation to use. 81 ''; 82 }; 83 84 extraOptions = mkOption { 85 type = types.listOf types.str; 86 default = []; 87 example = [ "-v" "-m randr" ]; 88 description = '' 89 Additional command-line arguments to pass to 90 <command>redshift</command>. 91 ''; 92 }; 93 }; 94 95 config = mkIf cfg.enable { 96 systemd.user.services.redshift = { 97 description = "Redshift colour temperature adjuster"; 98 wantedBy = [ "graphical-session.target" ]; 99 partOf = [ "graphical-session.target" ]; 100 serviceConfig = { 101 ExecStart = '' 102 ${cfg.package}/bin/redshift \ 103 -l ${cfg.latitude}:${cfg.longitude} \ 104 -t ${toString cfg.temperature.day}:${toString cfg.temperature.night} \ 105 -b ${toString cfg.brightness.day}:${toString cfg.brightness.night} \ 106 ${lib.strings.concatStringsSep " " cfg.extraOptions} 107 ''; 108 RestartSec = 3; 109 Restart = "always"; 110 }; 111 }; 112 }; 113 114}