From 7a055af8e7ccb3473cfa733818c8100e80f47e4e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 14 Jan 2026 12:13:36 -0800 Subject: [PATCH] nixos/services.picom: use libconfig to generate the config The custom formatter didn't correctly handle arrays (of primitives) versus lists (of composite types), which made it impossible to use the new picom rules system. --- nixos/modules/services/x11/picom.nix | 103 +++++---------------------- 1 file changed, 17 insertions(+), 86 deletions(-) diff --git a/nixos/modules/services/x11/picom.nix b/nixos/modules/services/x11/picom.nix index 33d53930dff0..399f2a66370b 100644 --- a/nixos/modules/services/x11/picom.nix +++ b/nixos/modules/services/x11/picom.nix @@ -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 {