redshift: allow using geoclue2 loation provider

authored by Michael Peyton Jones and committed by Domen Kožar 2ac89a61 d96b0ac7

+38 -6
+38 -6
nixos/modules/services/x11/redshift.nix
··· 19 19 }; 20 20 21 21 latitude = mkOption { 22 - type = types.str; 22 + type = types.nullOr types.str; 23 + default = null; 23 24 description = '' 24 25 Your current latitude, between 25 - <literal>-90.0</literal> and <literal>90.0</literal>. 26 + <literal>-90.0</literal> and <literal>90.0</literal>. Must be provided 27 + along with longitude. 26 28 ''; 27 29 }; 28 30 29 31 longitude = mkOption { 30 - type = types.str; 32 + type = types.nullOr types.str; 33 + default = null; 31 34 description = '' 32 35 Your current longitude, between 33 - between <literal>-180.0</literal> and <literal>180.0</literal>. 36 + between <literal>-180.0</literal> and <literal>180.0</literal>. Must be 37 + provided along with latitude. 38 + ''; 39 + }; 40 + 41 + provider = mkOption { 42 + type = types.enum [ "manual" "geoclue2" ]; 43 + default = "manual"; 44 + description = '' 45 + The location provider to use for determining your location. If set to 46 + <literal>manual</literal> you must also provide latitude/longitude. 34 47 ''; 35 48 }; 36 49 ··· 93 106 }; 94 107 95 108 config = mkIf cfg.enable { 96 - systemd.user.services.redshift = { 109 + assertions = [ 110 + { 111 + assertion = 112 + if cfg.provider == "manual" 113 + then (cfg.latitude != null && cfg.longitude != null) 114 + else (cfg.latitude == null && cfg.longitude == null); 115 + message = "Latitude and longitude must be provided together, and with provider set to null."; 116 + } 117 + ]; 118 + 119 + services.geoclue2.enable = mkIf (cfg.provider == "geoclue2") true; 120 + 121 + systemd.user.services.redshift = 122 + let 123 + providerString = 124 + if cfg.provider == "manual" 125 + then "${cfg.latitude}:${cfg.longitude}" 126 + else cfg.provider; 127 + in 128 + { 97 129 description = "Redshift colour temperature adjuster"; 98 130 wantedBy = [ "graphical-session.target" ]; 99 131 partOf = [ "graphical-session.target" ]; 100 132 serviceConfig = { 101 133 ExecStart = '' 102 134 ${cfg.package}/bin/redshift \ 103 - -l ${cfg.latitude}:${cfg.longitude} \ 135 + -l ${providerString} \ 104 136 -t ${toString cfg.temperature.day}:${toString cfg.temperature.night} \ 105 137 -b ${toString cfg.brightness.day}:${toString cfg.brightness.night} \ 106 138 ${lib.strings.concatStringsSep " " cfg.extraOptions}