2022-05-05 21:56:43 +00:00
|
|
|
{ config, options, lib, pkgs, ... }:
|
2020-03-22 23:56:34 +00:00
|
|
|
|
|
|
|
let
|
2022-05-05 21:56:43 +00:00
|
|
|
inherit (builtins) elemAt isAttrs isBool length mapAttrs toJSON;
|
2022-04-11 11:32:21 +00:00
|
|
|
inherit (lib)
|
2022-05-05 21:56:43 +00:00
|
|
|
boolToString concatMapStringsSep concatStringsSep escape literalExpression
|
2022-07-12 15:52:43 +00:00
|
|
|
mapAttrsToList mkEnableOption mkRenamedOptionModule mkRemovedOptionModule
|
|
|
|
mkDefault mkIf mkOption optional types warn;
|
2020-03-22 23:56:34 +00:00
|
|
|
|
|
|
|
cfg = config.services.picom;
|
2022-05-05 21:56:43 +00:00
|
|
|
opt = options.services.picom;
|
2020-03-22 23:56:34 +00:00
|
|
|
|
2022-05-05 21:56:43 +00:00
|
|
|
pairOf = x:
|
|
|
|
with types;
|
|
|
|
addCheck (listOf x) (y: length y == 2) // {
|
|
|
|
description = "pair of ${x.description}";
|
2020-03-22 23:56:34 +00:00
|
|
|
};
|
|
|
|
|
2022-05-05 21:56:43 +00:00
|
|
|
mkDefaultAttrs = mapAttrs (n: v: mkDefault v);
|
|
|
|
|
|
|
|
# Basically a tinkered lib.generators.mkKeyValueDefault
|
|
|
|
# It either serializes a top-level definition "key: { values };"
|
|
|
|
# or an expression "key = { values };"
|
|
|
|
mkAttrsString = top:
|
|
|
|
mapAttrsToList (k: v:
|
|
|
|
let sep = if (top && isAttrs v) then ": " else " = ";
|
|
|
|
in "${escape [ sep ] k}${sep}${mkValueString v};");
|
|
|
|
|
|
|
|
# This serializes a Nix expression to the libconfig format.
|
|
|
|
mkValueString = v:
|
|
|
|
if types.bool.check v then
|
|
|
|
boolToString v
|
|
|
|
else if types.int.check v then
|
|
|
|
toString v
|
|
|
|
else if types.float.check v then
|
|
|
|
toString v
|
|
|
|
else if types.str.check v then
|
|
|
|
''"${escape [ ''"'' ] v}"''
|
|
|
|
else if builtins.isList v then
|
|
|
|
"[ ${concatMapStringsSep " , " mkValueString v} ]"
|
|
|
|
else if types.attrs.check v then
|
|
|
|
"{ ${concatStringsSep " " (mkAttrsString false v)} }"
|
|
|
|
else
|
|
|
|
throw ''
|
|
|
|
invalid expression used in option services.picom.settings:
|
|
|
|
${v}
|
|
|
|
'';
|
|
|
|
|
|
|
|
toConf = attrs: concatStringsSep "\n" (mkAttrsString true cfg.settings);
|
|
|
|
|
|
|
|
configFile = toConf cfg.settings;
|
2020-03-22 23:56:34 +00:00
|
|
|
|
|
|
|
in {
|
2022-05-05 21:56:43 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "picom" "refreshRate" ]
|
|
|
|
"The option `refresh-rate` has been deprecated by upstream.")
|
2022-11-18 15:59:30 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "picom" "experimentalBackends" ]
|
|
|
|
"The option `--experimental-backends` has been removed by upstream.")
|
2022-05-05 21:56:43 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "picom" "extraOptions" ]
|
|
|
|
"This option has been replaced by `services.picom.settings`.")
|
2022-07-12 15:52:43 +00:00
|
|
|
(mkRenamedOptionModule [ "services" "picom" "opacityRule" ] [
|
|
|
|
"services"
|
|
|
|
"picom"
|
|
|
|
"opacityRules"
|
|
|
|
])
|
2022-05-05 21:56:43 +00:00
|
|
|
];
|
2020-03-22 23:56:34 +00:00
|
|
|
|
|
|
|
options.services.picom = {
|
2023-06-30 23:30:13 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Picom X11 compositor");
|
2020-03-22 23:56:34 +00:00
|
|
|
|
|
|
|
fade = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-03-22 23:56:34 +00:00
|
|
|
Fade windows in and out.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
fadeDelta = mkOption {
|
2022-05-05 21:56:43 +00:00
|
|
|
type = types.ints.positive;
|
2020-03-22 23:56:34 +00:00
|
|
|
default = 10;
|
|
|
|
example = 5;
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-03-22 23:56:34 +00:00
|
|
|
Time between fade animation step (in ms).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
fadeSteps = mkOption {
|
2022-09-29 09:34:00 +00:00
|
|
|
type = pairOf (types.numbers.between 1.0e-2 1);
|
2022-05-05 21:56:43 +00:00
|
|
|
default = [ 2.8e-2 3.0e-2 ];
|
|
|
|
example = [ 4.0e-2 4.0e-2 ];
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-03-22 23:56:34 +00:00
|
|
|
Opacity change between fade steps (in and out).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
fadeExclude = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "window_type *= 'menu'" "name ~= 'Firefox$'" "focused = 1" ];
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-03-22 23:56:34 +00:00
|
|
|
List of conditions of windows that should not be faded.
|
2023-06-30 23:30:13 +00:00
|
|
|
See `picom(1)` man page for more examples.
|
2020-03-22 23:56:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
shadow = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-03-22 23:56:34 +00:00
|
|
|
Draw window shadows.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
shadowOffsets = mkOption {
|
2022-05-05 21:56:43 +00:00
|
|
|
type = pairOf types.int;
|
2020-03-22 23:56:34 +00:00
|
|
|
default = [ (-15) (-15) ];
|
|
|
|
example = [ (-10) (-15) ];
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-05-05 21:56:43 +00:00
|
|
|
Left and right offset for shadows (in pixels).
|
2020-03-22 23:56:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
shadowOpacity = mkOption {
|
2022-09-29 09:34:00 +00:00
|
|
|
type = types.numbers.between 0 1;
|
2022-05-05 21:56:43 +00:00
|
|
|
default = 0.75;
|
|
|
|
example = 0.8;
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-05-05 21:56:43 +00:00
|
|
|
Window shadows opacity.
|
2020-03-22 23:56:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
shadowExclude = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "window_type *= 'menu'" "name ~= 'Firefox$'" "focused = 1" ];
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-03-22 23:56:34 +00:00
|
|
|
List of conditions of windows that should have no shadow.
|
2023-06-30 23:30:13 +00:00
|
|
|
See `picom(1)` man page for more examples.
|
2020-03-22 23:56:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
activeOpacity = mkOption {
|
2022-09-29 09:34:00 +00:00
|
|
|
type = types.numbers.between 0 1;
|
2022-05-05 21:56:43 +00:00
|
|
|
default = 1.0;
|
|
|
|
example = 0.8;
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-03-22 23:56:34 +00:00
|
|
|
Opacity of active windows.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
inactiveOpacity = mkOption {
|
2022-09-29 09:34:00 +00:00
|
|
|
type = types.numbers.between 0.1 1;
|
2022-05-05 21:56:43 +00:00
|
|
|
default = 1.0;
|
|
|
|
example = 0.8;
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-03-22 23:56:34 +00:00
|
|
|
Opacity of inactive windows.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
menuOpacity = mkOption {
|
2022-09-29 09:34:00 +00:00
|
|
|
type = types.numbers.between 0 1;
|
2022-05-05 21:56:43 +00:00
|
|
|
default = 1.0;
|
|
|
|
example = 0.8;
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-03-22 23:56:34 +00:00
|
|
|
Opacity of dropdown and popup menu.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-05-05 21:56:43 +00:00
|
|
|
wintypes = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {
|
|
|
|
popup_menu = { opacity = cfg.menuOpacity; };
|
|
|
|
dropdown_menu = { opacity = cfg.menuOpacity; };
|
|
|
|
};
|
|
|
|
defaultText = literalExpression ''
|
|
|
|
{
|
|
|
|
popup_menu = { opacity = config.${opt.menuOpacity}; };
|
|
|
|
dropdown_menu = { opacity = config.${opt.menuOpacity}; };
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
example = { };
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-05-05 21:56:43 +00:00
|
|
|
Rules for specific window types.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
opacityRules = mkOption {
|
2020-03-22 23:56:34 +00:00
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2022-05-05 21:56:43 +00:00
|
|
|
example = [
|
|
|
|
"95:class_g = 'URxvt' && !_NET_WM_STATE@:32a"
|
|
|
|
"0:_NET_WM_STATE@:32a *= '_NET_WM_STATE_HIDDEN'"
|
|
|
|
];
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-05-05 21:56:43 +00:00
|
|
|
Rules that control the opacity of windows, in format PERCENT:PATTERN.
|
2020-03-22 23:56:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
backend = mkOption {
|
2022-11-27 17:48:48 +00:00
|
|
|
type = types.enum [ "egl" "glx" "xrender" "xr_glx_hybrid" ];
|
2022-05-05 21:56:43 +00:00
|
|
|
default = "xrender";
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Backend to use: `egl`, `glx`, `xrender` or `xr_glx_hybrid`.
|
2020-03-22 23:56:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
vSync = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-03-22 23:56:34 +00:00
|
|
|
Enable vertical synchronization.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-11-18 15:59:30 +00:00
|
|
|
extraArgs = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ ];
|
|
|
|
example = literalExpression ''[ "--legacy-backends" ]'';
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-11-18 15:59:30 +00:00
|
|
|
Extra arguments to be passed to the picom executable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-03-22 23:56:34 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.picom;
|
2021-10-09 09:14:08 +00:00
|
|
|
defaultText = literalExpression "pkgs.picom";
|
|
|
|
example = literalExpression "pkgs.picom";
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-05-05 21:56:43 +00:00
|
|
|
Picom derivation to use.
|
2020-03-22 23:56:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-05-05 21:56:43 +00:00
|
|
|
settings = with types;
|
|
|
|
let
|
|
|
|
scalar = oneOf [ bool int float str ] // {
|
|
|
|
description = "scalar types";
|
|
|
|
};
|
|
|
|
|
|
|
|
libConfig = oneOf [ scalar (listOf libConfig) (attrsOf libConfig) ] // {
|
|
|
|
description = "libconfig type";
|
|
|
|
};
|
|
|
|
|
|
|
|
topLevel = attrsOf libConfig // {
|
|
|
|
description = ''
|
|
|
|
libconfig configuration. The format consists of an attributes
|
|
|
|
set (called a group) of settings. Each setting can be a scalar type
|
|
|
|
(boolean, integer, floating point number or string), a list of
|
|
|
|
scalars or a group itself
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
in mkOption {
|
|
|
|
type = topLevel;
|
|
|
|
default = { };
|
|
|
|
example = literalExpression ''
|
|
|
|
blur =
|
|
|
|
{ method = "gaussian";
|
|
|
|
size = 10;
|
|
|
|
deviation = 5.0;
|
|
|
|
};
|
|
|
|
'';
|
2023-06-30 23:30:13 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-05-05 21:56:43 +00:00
|
|
|
Picom settings. Use this option to configure Picom settings not exposed
|
|
|
|
in a NixOS option or to bypass one. For the available options see the
|
2023-06-30 23:30:13 +00:00
|
|
|
CONFIGURATION FILES section at `picom(1)`.
|
2022-05-05 21:56:43 +00:00
|
|
|
'';
|
|
|
|
};
|
2020-03-22 23:56:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2022-04-24 14:25:54 +00:00
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "services.picom" pkgs
|
|
|
|
lib.platforms.linux)
|
|
|
|
];
|
|
|
|
|
2022-05-05 21:56:43 +00:00
|
|
|
services.picom.settings = mkDefaultAttrs {
|
|
|
|
# fading
|
|
|
|
fading = cfg.fade;
|
|
|
|
fade-delta = cfg.fadeDelta;
|
|
|
|
fade-in-step = elemAt cfg.fadeSteps 0;
|
|
|
|
fade-out-step = elemAt cfg.fadeSteps 1;
|
|
|
|
fade-exclude = cfg.fadeExclude;
|
|
|
|
|
|
|
|
# shadows
|
|
|
|
shadow = cfg.shadow;
|
|
|
|
shadow-offset-x = elemAt cfg.shadowOffsets 0;
|
|
|
|
shadow-offset-y = elemAt cfg.shadowOffsets 1;
|
|
|
|
shadow-opacity = cfg.shadowOpacity;
|
|
|
|
shadow-exclude = cfg.shadowExclude;
|
|
|
|
|
|
|
|
# opacity
|
|
|
|
active-opacity = cfg.activeOpacity;
|
|
|
|
inactive-opacity = cfg.inactiveOpacity;
|
|
|
|
|
|
|
|
wintypes = cfg.wintypes;
|
|
|
|
|
|
|
|
opacity-rule = cfg.opacityRules;
|
|
|
|
|
|
|
|
# other options
|
|
|
|
backend = cfg.backend;
|
|
|
|
vsync = cfg.vSync;
|
|
|
|
};
|
2021-07-07 21:24:27 +00:00
|
|
|
|
2020-03-22 23:56:34 +00:00
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
2022-04-11 11:32:21 +00:00
|
|
|
xdg.configFile."picom/picom.conf".text = configFile;
|
|
|
|
|
2020-03-22 23:56:34 +00:00
|
|
|
systemd.user.services.picom = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Picom X11 compositor";
|
|
|
|
After = [ "graphical-session-pre.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
|
|
|
|
2022-04-11 11:32:21 +00:00
|
|
|
Service = {
|
|
|
|
ExecStart = concatStringsSep " " ([
|
|
|
|
"${cfg.package}/bin/picom"
|
|
|
|
"--config ${config.xdg.configFile."picom/picom.conf".source}"
|
2022-11-18 15:59:30 +00:00
|
|
|
] ++ cfg.extraArgs);
|
2020-03-22 23:56:34 +00:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 3;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-05-05 21:56:43 +00:00
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ thiagokokada ];
|
2020-03-22 23:56:34 +00:00
|
|
|
}
|