at 15.09-beta 2.3 kB view raw
1{ config, lib, pkgs, ... }: 2with lib; 3let 4 cfg = config.services.redshift; 5 6in { 7 options = { 8 services.redshift.enable = mkOption { 9 type = types.bool; 10 default = false; 11 example = true; 12 description = "Enable Redshift to change your screen's colour temperature depending on the time of day"; 13 }; 14 15 services.redshift.latitude = mkOption { 16 description = "Your current latitude"; 17 type = types.str; 18 }; 19 20 services.redshift.longitude = mkOption { 21 description = "Your current longitude"; 22 type = types.str; 23 }; 24 25 services.redshift.temperature = { 26 day = mkOption { 27 description = "Colour temperature to use during day time"; 28 default = 5500; 29 type = types.int; 30 }; 31 night = mkOption { 32 description = "Colour temperature to use during night time"; 33 default = 3700; 34 type = types.int; 35 }; 36 }; 37 38 services.redshift.brightness = { 39 day = mkOption { 40 description = "Screen brightness to apply during the day (between 0.1 and 1.0)"; 41 default = "1"; 42 type = types.str; 43 }; 44 night = mkOption { 45 description = "Screen brightness to apply during the night (between 0.1 and 1.0)"; 46 default = "1"; 47 type = types.str; 48 }; 49 }; 50 51 services.redshift.extraOptions = mkOption { 52 type = types.listOf types.str; 53 default = []; 54 example = [ "-v" "-m randr" ]; 55 description = "Additional command-line arguments to pass to the redshift(1) command"; 56 }; 57 }; 58 59 config = mkIf cfg.enable { 60 systemd.services.redshift = { 61 description = "Redshift colour temperature adjuster"; 62 requires = [ "display-manager.service" ]; 63 after = [ "display-manager.service" ]; 64 wantedBy = [ "graphical.target" ]; 65 serviceConfig.ExecStart = '' 66 ${pkgs.redshift}/bin/redshift \ 67 -l ${cfg.latitude}:${cfg.longitude} \ 68 -t ${toString cfg.temperature.day}:${toString cfg.temperature.night} \ 69 -b ${toString cfg.brightness.day}:${toString cfg.brightness.night} \ 70 ${lib.strings.concatStringsSep " " cfg.extraOptions} 71 ''; 72 environment = { DISPLAY = ":0"; }; 73 serviceConfig.Restart = "always"; 74 }; 75 }; 76}