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 }; 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 ··· 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}
··· 19 }; 20 21 latitude = mkOption { 22 + type = types.nullOr types.str; 23 + default = null; 24 description = '' 25 Your current latitude, between 26 + <literal>-90.0</literal> and <literal>90.0</literal>. Must be provided 27 + along with longitude. 28 ''; 29 }; 30 31 longitude = mkOption { 32 + type = types.nullOr types.str; 33 + default = null; 34 description = '' 35 Your current longitude, between 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. 47 ''; 48 }; 49 ··· 106 }; 107 108 config = mkIf cfg.enable { 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 + { 129 description = "Redshift colour temperature adjuster"; 130 wantedBy = [ "graphical-session.target" ]; 131 partOf = [ "graphical-session.target" ]; 132 serviceConfig = { 133 ExecStart = '' 134 ${cfg.package}/bin/redshift \ 135 + -l ${providerString} \ 136 -t ${toString cfg.temperature.day}:${toString cfg.temperature.night} \ 137 -b ${toString cfg.brightness.day}:${toString cfg.brightness.night} \ 138 ${lib.strings.concatStringsSep " " cfg.extraOptions}