git.iko.soy/typeable/nixpkgs
on master help sign in
compton: 6.2 -> 7
commit23ae47a2d040023d5a912e8df44f47ec6ca5c668 authorEdmund Wu <fangkazuto@gmail.com> dateFri 19 Jul 2019, 09:48 (7 years ago) parent663542a
2 files changed+76−70
nixos/modules/services/x11/compton.nix+70−66 pkgs/applications/window-managers/compton/default.nix+6−4
nixos/modules/services/x11/compton.nix+70−66
@@ -7,57 +7,35 @@ let
77
88 cfg = config.services.compton;
99
10− literalAttrs = v:
11− if isString v then toString v
12− else if isAttrs v then "{\n"
13− + concatStringsSep "\n" (mapAttrsToList
14− (name: value: "${literalAttrs name} = ${literalAttrs value};")
15− v)
16− + "\n}"
17− else generators.toPretty {} v;
10+ pairOf = x: with types; addCheck (listOf x) (y: length y == 2);
1811
1912 floatBetween = a: b: with lib; with types;
2013 addCheck str (x: versionAtLeast x a && versionOlder x b);
2114
22− pairOf = x: with types; addCheck (listOf x) (y: length y == 2);
23−
24− opacityRules = optionalString (length cfg.opacityRules != 0)
25− (concatMapStringsSep ",\n" (rule: ''"${rule}"'') cfg.opacityRules);
26−
27− configFile = pkgs.writeText "compton.conf"
28− (optionalString cfg.fade ''
29− # fading
30− fading = true;
31− fade-delta = ${toString cfg.fadeDelta};
32− fade-in-step = ${elemAt cfg.fadeSteps 0};
33− fade-out-step = ${elemAt cfg.fadeSteps 1};
34− fade-exclude = ${toJSON cfg.fadeExclude};
35− '' + optionalString cfg.shadow ''
36−
37− # shadows
38− shadow = true;
39− shadow-offset-x = ${toString (elemAt cfg.shadowOffsets 0)};
40− shadow-offset-y = ${toString (elemAt cfg.shadowOffsets 1)};
41− shadow-opacity = ${cfg.shadowOpacity};
42− shadow-exclude = ${toJSON cfg.shadowExclude};
43− '' + ''
44−
45− # opacity
46− active-opacity = ${cfg.activeOpacity};
47− inactive-opacity = ${cfg.inactiveOpacity};
48−
49− wintypes:
50− ${literalAttrs cfg.wintypes};
51−
52− opacity-rule = [
53− ${opacityRules}
54− ];
55−
56− # other options
57− backend = ${toJSON cfg.backend};
58− vsync = ${boolToString cfg.vSync};
59− refresh-rate = ${toString cfg.refreshRate};
60− '' + cfg.extraOptions);
15+ toConf = attrs: concatStringsSep "\n"
16+ (mapAttrsToList
17+ (k: v: let
18+ sep = if isAttrs v then ":" else "=";
19+ # Basically a tinkered lib.generators.mkKeyValueDefault
20+ mkValueString = v:
21+ if isBool v then boolToString v
22+ else if isInt v then toString v
23+ else if isFloat v then toString v
24+ else if isString v then ''"${escape [ ''"'' ] v}"''
25+ else if isList v then "[ "
26+ + concatMapStringsSep " , " mkValueString v
27+ + " ]"
28+ else if isAttrs v then "{ "
29+ + concatStringsSep " "
30+ (mapAttrsToList
31+ (key: value: "${toString key}=${mkValueString value};")
32+ v)
33+ + " }"
34+ else abort "compton.mkValueString: unexpected type (v = ${v})";
35+ in "${escape [ sep ] k}${sep}${mkValueString v};")
36+ attrs);
37+
38+ configFile = pkgs.writeText "compton.conf" (toConf cfg.settings);
6139
6240in {
6341
@@ -236,23 +214,13 @@ in {
236214 '';
237215 };
238216
239− package = mkOption {
240− type = types.package;
241− default = pkgs.compton;
242− defaultText = "pkgs.compton";
243− example = literalExample "pkgs.compton";
244− description = ''
245− Compton derivation to use.
246− '';
247− };
248−
249− extraOptions = mkOption {
250− type = types.lines;
251− default = "";
252− example = ''
253− unredir-if-possible = true;
254− dbe = true;
255− '';
217+ settings = let
218+ configTypes = with types; either bool (either int (either float str));
219+ # types.loaOf converts lists to sets
220+ loaOf = t: with types; either (listOf t) (attrsOf t);
221+ in mkOption {
222+ type = loaOf (types.either configTypes (loaOf (types.either configTypes (loaOf configTypes))));
223+ default = {};
256224 description = ''
257225 Additional Compton configuration.
258226 '';
@@ -260,6 +228,42 @@ in {
260228 };
261229
262230 config = mkIf cfg.enable {
231+ services.compton.settings = let
232+ # Hard conversion to float, literally lib.toInt but toFloat
233+ toFloat = str: let
234+ may_be_float = builtins.fromJSON str;
235+ in if builtins.isFloat may_be_float
236+ then may_be_float
237+ else throw "Could not convert ${str} to float.";
238+ in {
239+ # fading
240+ fading = mkDefault cfg.fade;
241+ fade-delta = mkDefault cfg.fadeDelta;
242+ fade-in-step = mkDefault (toFloat (elemAt cfg.fadeSteps 0));
243+ fade-out-step = mkDefault (toFloat (elemAt cfg.fadeSteps 1));
244+ fade-exclude = mkDefault cfg.fadeExclude;
245+
246+ # shadows
247+ shadow = mkDefault cfg.shadow;
248+ shadow-offset-x = mkDefault (elemAt cfg.shadowOffsets 0);
249+ shadow-offset-y = mkDefault (elemAt cfg.shadowOffsets 1);
250+ shadow-opacity = mkDefault (toFloat cfg.shadowOpacity);
251+ shadow-exclude = mkDefault cfg.shadowExclude;
252+
253+ # opacity
254+ active-opacity = mkDefault (toFloat cfg.activeOpacity);
255+ inactive-opacity = mkDefault (toFloat cfg.inactiveOpacity);
256+
257+ wintypes = mkDefault cfg.wintypes;
258+
259+ opacity-rule = mkDefault cfg.opacityRules;
260+
261+ # other options
262+ backend = mkDefault cfg.backend;
263+ vsync = mkDefault cfg.vSync;
264+ refresh-rate = mkDefault cfg.refreshRate;
265+ };
266+
263267 systemd.user.services.compton = {
264268 description = "Compton composite manager";
265269 wantedBy = [ "graphical-session.target" ];
@@ -271,13 +275,13 @@ in {
271275 };
272276
273277 serviceConfig = {
274− ExecStart = "${cfg.package}/bin/compton --config ${configFile}";
278+ ExecStart = "${pkgs.compton}/bin/compton --config ${configFile}";
275279 RestartSec = 3;
276280 Restart = "always";
277281 };
278282 };
279283
280− environment.systemPackages = [ cfg.package ];
284+ environment.systemPackages = [ pkgs.compton ];
281285 };
282286
283287}
pkgs/applications/window-managers/compton/default.nix+6−4
@@ -1,11 +1,11 @@
1−{ stdenv, lib, fetchFromGitHub, pkgconfig, asciidoc, docbook_xml_dtd_45
1+{ stdenv, lib, fetchFromGitHub, pkgconfig, uthash, asciidoc, docbook_xml_dtd_45
22, docbook_xsl, libxslt, libxml2, makeWrapper, meson, ninja
33, xorgproto, libxcb ,xcbutilrenderutil, xcbutilimage, pixman, libev
44, dbus, libconfig, libdrm, libGL, pcre, libX11
55, libXinerama, libXext, xwininfo, libxdg_basedir }:
66stdenv.mkDerivation rec {
77 pname = "compton";
8− version = "6.2";
8+ version = "7";
99
1010 COMPTON_VERSION = "v${version}";
1111
@@ -13,12 +13,14 @@ stdenv.mkDerivation rec {
1313 owner = "yshui";
1414 repo = "compton";
1515 rev = COMPTON_VERSION;
16− sha256 = "03fi9q8zw2qrwpkmy1bnavgfh91ci9in5fdi17g4s5s0n2l7yil7";
16+ sha256 = "0f23dv2p1snlpzc91v38q6896ncz4zqzmh2d97yf66j78g21awas";
17+ fetchSubmodules = true;
1718 };
1819
1920 nativeBuildInputs = [
2021 meson ninja
2122 pkgconfig
23+ uthash
2224 asciidoc
2325 docbook_xml_dtd_45
2426 docbook_xsl
@@ -41,7 +43,7 @@ stdenv.mkDerivation rec {
4143 ];
4244
4345 preBuild = ''
44− git() { echo "v${version}"; }
46+ git() { echo "$COMPTON_VERSION"; }
4547 export -f git
4648 '';
4749