mirror of
https://github.com/nix-community/home-manager.git
synced 2026-01-12 01:59:37 +08:00
lib: make toHyprconf support strings and attrs in sections
Adds support for
section = [
"abc"
{ a = 123; }
];
Which gets generated to
section=abc
section {
a=123
}
This is very useful with the new windowrule syntax, where you can
create anonymous window rules as strings and named rules as attribute
sets. See <https://wiki.hypr.land/Configuring/Window-Rules/>.
This commit is contained in:
committed by
Robert Helgesson
parent
e4e78a2cbe
commit
d4e4d5cfa3
@@ -21,6 +21,7 @@
|
||||
isList
|
||||
mapAttrsToList
|
||||
replicate
|
||||
attrNames
|
||||
;
|
||||
|
||||
initialIndent = concatStrings (replicate indentLevel " ");
|
||||
@@ -28,31 +29,36 @@
|
||||
toHyprconf' =
|
||||
indent: attrs:
|
||||
let
|
||||
sections = filterAttrs (n: v: isAttrs v || (isList v && all isAttrs v)) attrs;
|
||||
isImportantField =
|
||||
n: _: foldl (acc: prev: if hasPrefix prev n then true else acc) false importantPrefixes;
|
||||
importantFields = filterAttrs isImportantField attrs;
|
||||
withoutImportantFields = fields: removeAttrs fields (attrNames importantFields);
|
||||
|
||||
allSections = filterAttrs (n: v: isAttrs v || isList v) attrs;
|
||||
sections = withoutImportantFields allSections;
|
||||
|
||||
mkSection =
|
||||
n: attrs:
|
||||
if lib.isList attrs then
|
||||
(concatMapStringsSep "\n" (a: mkSection n a) attrs)
|
||||
else
|
||||
if isList attrs then
|
||||
let
|
||||
separator = if all isAttrs attrs then "\n" else "";
|
||||
in
|
||||
(concatMapStringsSep separator (a: mkSection n a) attrs)
|
||||
else if isAttrs attrs then
|
||||
''
|
||||
${indent}${n} {
|
||||
${toHyprconf' " ${indent}" attrs}${indent}}
|
||||
'';
|
||||
''
|
||||
else
|
||||
toHyprconf' indent { ${n} = attrs; };
|
||||
|
||||
mkFields = generators.toKeyValue {
|
||||
listsAsDuplicateKeys = true;
|
||||
inherit indent;
|
||||
};
|
||||
|
||||
allFields = filterAttrs (n: v: !(isAttrs v || (isList v && all isAttrs v))) attrs;
|
||||
|
||||
isImportantField =
|
||||
n: _: foldl (acc: prev: if hasPrefix prev n then true else acc) false importantPrefixes;
|
||||
|
||||
importantFields = filterAttrs isImportantField allFields;
|
||||
|
||||
fields = builtins.removeAttrs allFields (mapAttrsToList (n: _: n) importantFields);
|
||||
allFields = filterAttrs (n: v: !(isAttrs v || isList v)) attrs;
|
||||
fields = withoutImportantFields allFields;
|
||||
in
|
||||
mkFields importantFields
|
||||
+ concatStringsSep "\n" (mapAttrsToList mkSection sections)
|
||||
|
||||
Reference in New Issue
Block a user