1 { config, pkgs, lib, ... }:
6 cfg = config.services.clight;
9 if builtins.isFloat v then toString v
10 else if isInt v then toString v
11 else if isBool v then boolToString v
12 else if isString v then ''"${escape [''"''] v}"''
13 else if isList v then "[ " + concatMapStringsSep ", " toConf v + " ]"
14 else if isAttrs v then "\n{\n" + convertAttrs v + "\n}"
15 else abort "clight.toConf: unexpected type (v = ${v})";
21 convertAttrs = attrs: concatStringsSep "\n" (mapAttrsToList
22 (name: value: "${toString name} ${getSep value} ${toConf value};")
25 clightConf = pkgs.writeText "clight.conf" (convertAttrs
27 (_: value: value != null)
30 options.services.clight = {
31 enable = mkEnableOption "clight";
38 Colour temperature to use during the day, between
46 Colour temperature to use at night, between
53 validConfigTypes = with types; oneOf [ int str bool float ];
54 collectionTypes = with types; oneOf [ validConfigTypes (listOf validConfigTypes) ];
56 type = with types; attrsOf (nullOr (either collectionTypes (attrsOf collectionTypes)));
58 example = { captures = 20; gamma_long_transition = true; ac_capture_timeouts = [ 120 300 60 ]; };
60 Additional configuration to extend clight.conf. See
61 <https://github.com/FedeDP/Clight/blob/master/Extra/clight.conf> for a
62 sample configuration file.
67 config = mkIf cfg.enable {
69 inRange = v: l: r: v >= l && v <= r;
71 { assertion = config.location.provider == "manual" ->
72 inRange config.location.latitude (-90) 90 && inRange config.location.longitude (-180) 180;
73 message = "You must specify a valid latitude and longitude if manually providing location"; }
76 boot.kernelModules = [ "i2c_dev" ];
77 environment.systemPackages = with pkgs; [ clight clightd ];
78 services.dbus.packages = with pkgs; [ clight clightd ];
79 services.upower.enable = true;
81 services.clight.settings = {
82 gamma.temp = with cfg.temperature; mkDefault [ day night ];
83 } // (optionalAttrs (config.location.provider == "manual") {
84 daytime.latitude = mkDefault config.location.latitude;
85 daytime.longitude = mkDefault config.location.longitude;
88 services.geoclue2.appConfig.clightc = {
93 systemd.services.clightd = {
94 requires = [ "polkit.service" ];
95 wantedBy = [ "multi-user.target" ];
97 description = "Bus service to manage various screen related properties (gamma, dpms, backlight)";
100 BusName = "org.clightd.clightd";
101 Restart = "on-failure";
104 ${pkgs.clightd}/bin/clightd
109 systemd.user.services.clight = {
110 after = [ "upower.service" "clightd.service" ];
111 wants = [ "upower.service" "clightd.service" ];
112 partOf = [ "graphical-session.target" ];
113 wantedBy = [ "graphical-session.target" ];
115 description = "C daemon to adjust screen brightness to match ambient brightness, as computed capturing frames from webcam";
117 Restart = "on-failure";
120 ${pkgs.clight}/bin/clight --conf-file ${clightConf}