compton: 6.2 -> 7

This commit is contained in:
Edmund Wu 2019-07-19 09:48:28 -04:00
parent 663542ad04
commit 23ae47a2d0
No known key found for this signature in database
GPG key ID: 76AA3F9F2BD3E3A0
2 changed files with 75 additions and 69 deletions

View file

@ -7,57 +7,35 @@ let
cfg = config.services.compton;
literalAttrs = v:
if isString v then toString v
else if isAttrs v then "{\n"
+ concatStringsSep "\n" (mapAttrsToList
(name: value: "${literalAttrs name} = ${literalAttrs value};")
v)
+ "\n}"
else generators.toPretty {} v;
pairOf = x: with types; addCheck (listOf x) (y: length y == 2);
floatBetween = a: b: with lib; with types;
addCheck str (x: versionAtLeast x a && versionOlder x b);
pairOf = x: with types; addCheck (listOf x) (y: length y == 2);
toConf = attrs: concatStringsSep "\n"
(mapAttrsToList
(k: v: let
sep = if isAttrs v then ":" else "=";
# Basically a tinkered lib.generators.mkKeyValueDefault
mkValueString = v:
if isBool v then boolToString v
else if isInt v then toString v
else if isFloat v then toString v
else if isString v then ''"${escape [ ''"'' ] v}"''
else if isList v then "[ "
+ concatMapStringsSep " , " mkValueString v
+ " ]"
else if isAttrs v then "{ "
+ concatStringsSep " "
(mapAttrsToList
(key: value: "${toString key}=${mkValueString value};")
v)
+ " }"
else abort "compton.mkValueString: unexpected type (v = ${v})";
in "${escape [ sep ] k}${sep}${mkValueString v};")
attrs);
opacityRules = optionalString (length cfg.opacityRules != 0)
(concatMapStringsSep ",\n" (rule: ''"${rule}"'') cfg.opacityRules);
configFile = pkgs.writeText "compton.conf"
(optionalString cfg.fade ''
# fading
fading = true;
fade-delta = ${toString cfg.fadeDelta};
fade-in-step = ${elemAt cfg.fadeSteps 0};
fade-out-step = ${elemAt cfg.fadeSteps 1};
fade-exclude = ${toJSON cfg.fadeExclude};
'' + optionalString cfg.shadow ''
# shadows
shadow = true;
shadow-offset-x = ${toString (elemAt cfg.shadowOffsets 0)};
shadow-offset-y = ${toString (elemAt cfg.shadowOffsets 1)};
shadow-opacity = ${cfg.shadowOpacity};
shadow-exclude = ${toJSON cfg.shadowExclude};
'' + ''
# opacity
active-opacity = ${cfg.activeOpacity};
inactive-opacity = ${cfg.inactiveOpacity};
wintypes:
${literalAttrs cfg.wintypes};
opacity-rule = [
${opacityRules}
];
# other options
backend = ${toJSON cfg.backend};
vsync = ${boolToString cfg.vSync};
refresh-rate = ${toString cfg.refreshRate};
'' + cfg.extraOptions);
configFile = pkgs.writeText "compton.conf" (toConf cfg.settings);
in {
@ -236,23 +214,13 @@ in {
'';
};
package = mkOption {
type = types.package;
default = pkgs.compton;
defaultText = "pkgs.compton";
example = literalExample "pkgs.compton";
description = ''
Compton derivation to use.
'';
};
extraOptions = mkOption {
type = types.lines;
default = "";
example = ''
unredir-if-possible = true;
dbe = true;
'';
settings = let
configTypes = with types; either bool (either int (either float str));
# types.loaOf converts lists to sets
loaOf = t: with types; either (listOf t) (attrsOf t);
in mkOption {
type = loaOf (types.either configTypes (loaOf (types.either configTypes (loaOf configTypes))));
default = {};
description = ''
Additional Compton configuration.
'';
@ -260,6 +228,42 @@ in {
};
config = mkIf cfg.enable {
services.compton.settings = let
# Hard conversion to float, literally lib.toInt but toFloat
toFloat = str: let
may_be_float = builtins.fromJSON str;
in if builtins.isFloat may_be_float
then may_be_float
else throw "Could not convert ${str} to float.";
in {
# fading
fading = mkDefault cfg.fade;
fade-delta = mkDefault cfg.fadeDelta;
fade-in-step = mkDefault (toFloat (elemAt cfg.fadeSteps 0));
fade-out-step = mkDefault (toFloat (elemAt cfg.fadeSteps 1));
fade-exclude = mkDefault cfg.fadeExclude;
# shadows
shadow = mkDefault cfg.shadow;
shadow-offset-x = mkDefault (elemAt cfg.shadowOffsets 0);
shadow-offset-y = mkDefault (elemAt cfg.shadowOffsets 1);
shadow-opacity = mkDefault (toFloat cfg.shadowOpacity);
shadow-exclude = mkDefault cfg.shadowExclude;
# opacity
active-opacity = mkDefault (toFloat cfg.activeOpacity);
inactive-opacity = mkDefault (toFloat cfg.inactiveOpacity);
wintypes = mkDefault cfg.wintypes;
opacity-rule = mkDefault cfg.opacityRules;
# other options
backend = mkDefault cfg.backend;
vsync = mkDefault cfg.vSync;
refresh-rate = mkDefault cfg.refreshRate;
};
systemd.user.services.compton = {
description = "Compton composite manager";
wantedBy = [ "graphical-session.target" ];
@ -271,13 +275,13 @@ in {
};
serviceConfig = {
ExecStart = "${cfg.package}/bin/compton --config ${configFile}";
ExecStart = "${pkgs.compton}/bin/compton --config ${configFile}";
RestartSec = 3;
Restart = "always";
};
};
environment.systemPackages = [ cfg.package ];
environment.systemPackages = [ pkgs.compton ];
};
}

View file

@ -1,11 +1,11 @@
{ stdenv, lib, fetchFromGitHub, pkgconfig, asciidoc, docbook_xml_dtd_45
{ stdenv, lib, fetchFromGitHub, pkgconfig, uthash, asciidoc, docbook_xml_dtd_45
, docbook_xsl, libxslt, libxml2, makeWrapper, meson, ninja
, xorgproto, libxcb ,xcbutilrenderutil, xcbutilimage, pixman, libev
, dbus, libconfig, libdrm, libGL, pcre, libX11
, libXinerama, libXext, xwininfo, libxdg_basedir }:
stdenv.mkDerivation rec {
pname = "compton";
version = "6.2";
version = "7";
COMPTON_VERSION = "v${version}";
@ -13,12 +13,14 @@ stdenv.mkDerivation rec {
owner = "yshui";
repo = "compton";
rev = COMPTON_VERSION;
sha256 = "03fi9q8zw2qrwpkmy1bnavgfh91ci9in5fdi17g4s5s0n2l7yil7";
sha256 = "0f23dv2p1snlpzc91v38q6896ncz4zqzmh2d97yf66j78g21awas";
fetchSubmodules = true;
};
nativeBuildInputs = [
meson ninja
pkgconfig
uthash
asciidoc
docbook_xml_dtd_45
docbook_xsl
@ -41,7 +43,7 @@ stdenv.mkDerivation rec {
];
preBuild = ''
git() { echo "v${version}"; }
git() { echo "$COMPTON_VERSION"; }
export -f git
'';