nixos/clight: fix config file generation

This commit is contained in:
Edmund Wu 2020-09-26 11:28:54 -04:00
parent 1ac4c06c08
commit 771199faf3
No known key found for this signature in database
GPG Key ID: 0D62311F6343DE1A

View File

@ -11,14 +11,21 @@ let
else if isBool v then boolToString v else if isBool v then boolToString v
else if isString v then ''"${escape [''"''] v}"'' else if isString v then ''"${escape [''"''] v}"''
else if isList v then "[ " + concatMapStringsSep ", " toConf v + " ]" else if isList v then "[ " + concatMapStringsSep ", " toConf v + " ]"
else if isAttrs v then "\n{\n" + convertAttrs v + "\n}"
else abort "clight.toConf: unexpected type (v = ${v})"; else abort "clight.toConf: unexpected type (v = ${v})";
clightConf = pkgs.writeText "clight.conf" getSep = v:
(concatStringsSep "\n" (mapAttrsToList if isAttrs v then ":"
(name: value: "${toString name} = ${toConf value};") else "=";
convertAttrs = attrs: concatStringsSep "\n" (mapAttrsToList
(name: value: "${toString name} ${getSep value} ${toConf value};")
attrs);
clightConf = pkgs.writeText "clight.conf" (convertAttrs
(filterAttrs (filterAttrs
(_: value: value != null) (_: value: value != null)
cfg.settings))); cfg.settings));
in { in {
options.services.clight = { options.services.clight = {
enable = mkOption { enable = mkOption {
@ -49,9 +56,10 @@ in {
}; };
settings = let settings = let
validConfigTypes = with types; either int (either str (either bool float)); validConfigTypes = with types; oneOf [ int str bool float ];
collectionTypes = with types; oneOf [ validConfigTypes (listOf validConfigTypes) ];
in mkOption { in mkOption {
type = with types; attrsOf (nullOr (either validConfigTypes (listOf validConfigTypes))); type = with types; attrsOf (nullOr (either collectionTypes (attrsOf collectionTypes)));
default = {}; default = {};
example = { captures = 20; gamma_long_transition = true; ac_capture_timeouts = [ 120 300 60 ]; }; example = { captures = 20; gamma_long_transition = true; ac_capture_timeouts = [ 120 300 60 ]; };
description = '' description = ''
@ -69,10 +77,10 @@ in {
services.upower.enable = true; services.upower.enable = true;
services.clight.settings = { services.clight.settings = {
gamma_temp = with cfg.temperature; mkDefault [ day night ]; gamma.temp = with cfg.temperature; mkDefault [ day night ];
} // (optionalAttrs (config.location.provider == "manual") { } // (optionalAttrs (config.location.provider == "manual") {
latitude = mkDefault config.location.latitude; daytime.latitude = mkDefault config.location.latitude;
longitude = mkDefault config.location.longitude; daytime.longitude = mkDefault config.location.longitude;
}); });
services.geoclue2.appConfig.clightc = { services.geoclue2.appConfig.clightc = {