nixos/services.picom: use libconfig to generate the config (#480156)

This commit is contained in:
Michele Guerini Rocco
2026-01-23 12:20:34 +00:00
committed by GitHub
+17 -86
View File
@@ -20,43 +20,8 @@ let
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 = pkgs.writeText "picom.conf" (toConf cfg.settings);
libconfig = pkgs.formats.libconfig { };
configFile = libconfig.generate "picom.conf" cfg.settings;
in
{
@@ -279,56 +244,22 @@ in
'';
};
settings =
with types;
let
scalar =
oneOf [
bool
int
float
str
]
// {
description = "scalar types";
settings = mkOption {
type = libconfig.type;
default = { };
example = literalExpression ''
blur =
{ method = "gaussian";
size = 10;
deviation = 5.0;
};
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;
};
'';
description = ''
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
CONFIGURATION FILES section at {manpage}`picom(1)`.
'';
};
'';
description = ''
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
CONFIGURATION FILES section at {manpage}`picom(1)`.
'';
};
};
config = mkIf cfg.enable {