nixos/compton: improve options type-checking

This commit is contained in:
rnhmjoj 2017-10-16 23:52:42 +02:00
parent 2a036ca1a5
commit 36bbc3cfda
No known key found for this signature in database
GPG Key ID: 91BE884FBA4B591A

View File

@ -7,12 +7,15 @@ let
cfg = config.services.compton; cfg = config.services.compton;
configFile = let floatBetween = a: b: with lib; with types;
opacityRules = optionalString (length cfg.opacityRules != 0) addCheck str (x: versionAtLeast x a && versionOlder x b);
(concatStringsSep "\n"
(map (a: "opacity-rule = [ \"${a}\" ];") cfg.opacityRules) pairOf = x: with types; addCheck (listOf x) (y: lib.length y == 2);
);
in pkgs.writeText "compton.conf" opacityRules = optionalString (length cfg.opacityRules != 0)
(concatMapStringsSep ",\n" (rule: ''"${rule}"'') cfg.opacityRules);
configFile = pkgs.writeText "compton.conf"
(optionalString cfg.fade '' (optionalString cfg.fade ''
# fading # fading
fading = true; fading = true;
@ -36,7 +39,9 @@ let
inactive-opacity = ${cfg.inactiveOpacity}; inactive-opacity = ${cfg.inactiveOpacity};
menu-opacity = ${cfg.menuOpacity}; menu-opacity = ${cfg.menuOpacity};
${opacityRules} opacity-rule = [
${opacityRules}
];
# other options # other options
backend = ${toJSON cfg.backend}; backend = ${toJSON cfg.backend};
@ -64,7 +69,7 @@ in {
}; };
fadeDelta = mkOption { fadeDelta = mkOption {
type = types.int; type = types.addCheck types.int (x: x > 0);
default = 10; default = 10;
example = 5; example = 5;
description = '' description = ''
@ -73,11 +78,12 @@ in {
}; };
fadeSteps = mkOption { fadeSteps = mkOption {
type = types.listOf types.str; type = pairOf (floatBetween "0.01" "1.01");
default = [ "0.028" "0.03" ]; default = [ "0.028" "0.03" ];
example = [ "0.04" "0.04" ]; example = [ "0.04" "0.04" ];
description = '' description = ''
Opacity change between fade steps (in and out). Opacity change between fade steps (in and out).
(numbers in range 0.01 - 1.0)
''; '';
}; };
@ -104,7 +110,7 @@ in {
}; };
shadowOffsets = mkOption { shadowOffsets = mkOption {
type = types.listOf types.int; type = pairOf types.int;
default = [ (-15) (-15) ]; default = [ (-15) (-15) ];
example = [ (-10) (-15) ]; example = [ (-10) (-15) ];
description = '' description = ''
@ -113,11 +119,11 @@ in {
}; };
shadowOpacity = mkOption { shadowOpacity = mkOption {
type = types.str; type = floatBetween "0.0" "1.01";
default = "0.75"; default = "0.75";
example = "0.8"; example = "0.8";
description = '' description = ''
Window shadows opacity (number in range 0 - 1). Window shadows opacity (number in range 0.0 - 1.0).
''; '';
}; };
@ -136,42 +142,46 @@ in {
}; };
activeOpacity = mkOption { activeOpacity = mkOption {
type = types.str; type = floatBetween "0.0" "1.01";
default = "1.0"; default = "1.0";
example = "0.8"; example = "0.8";
description = '' description = ''
Opacity of active windows. Opacity of active windows (number in range 0.0 - 1.0).
''; '';
}; };
inactiveOpacity = mkOption { inactiveOpacity = mkOption {
type = types.str; type = floatBetween "0.1" "1.01";
default = "1.0"; default = "1.0";
example = "0.8"; example = "0.8";
description = '' description = ''
Opacity of inactive windows. Opacity of inactive windows (number in range 0.1 - 1.0).
''; '';
}; };
menuOpacity = mkOption { menuOpacity = mkOption {
type = types.str; type = floatBetween "0.0" "1.01";
default = "1.0"; default = "1.0";
example = "0.8"; example = "0.8";
description = '' description = ''
Opacity of dropdown and popup menu. Opacity of dropdown and popup menu (number in range 0.0 - 1.0).
''; '';
}; };
opacityRules = mkOption { opacityRules = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = []; default = [];
example = [
"95:class_g = 'URxvt' && !_NET_WM_STATE@:32a"
"0:_NET_WM_STATE@:32a *= '_NET_WM_STATE_HIDDEN'"
];
description = '' description = ''
Opacity rules to be handled by compton. Rules that control the opacity of windows, in format PERCENT:PATTERN.
''; '';
}; };
backend = mkOption { backend = mkOption {
type = types.str; type = types.enum [ "glx" "xrender" ];
default = "glx"; default = "glx";
description = '' description = ''
Backend to use: <literal>glx</literal> or <literal>xrender</literal>. Backend to use: <literal>glx</literal> or <literal>xrender</literal>.
@ -179,17 +189,20 @@ in {
}; };
vSync = mkOption { vSync = mkOption {
type = types.str; type = types.enum [
default = "none"; "none" "drm" "opengl"
example = "opengl-swc"; "opengl-oml" "opengl-swc" "opengl-mswc"
description = '' ];
Enable vertical synchronization using the specified method. default = "none";
See <literal>compton(1)</literal> man page available methods. example = "opengl-swc";
''; description = ''
Enable vertical synchronization using the specified method.
See <literal>compton(1)</literal> man page an explanation.
'';
}; };
refreshRate = mkOption { refreshRate = mkOption {
type = types.int; type = types.addCheck types.int (x: x >= 0);
default = 0; default = 0;
example = 60; example = 60;
description = '' description = ''