Anthony Rodriguez
6ab835555c
As my NixOS configuration kept growing, I noticed that I don't need home-manager as much as I did before. A lot of what I need is just a way to map nix attrsets to the program's respective configuration format, which is something that I can now do myself, as my nix knowledge got more extensive. After all of this, I decided to completely get rid of home-manager, and switch to a simpler solution called hjem, which just lets me write files to my home directory that are automatically symlinked using `systemd-tmpfiles`. This allows me to simplify my configuration, remove the separation between NixOS and home-manager modules, and cut my eval times by quite a lot (which allows for faster `nixos-rebuild switch`!).
63 lines
1.3 KiB
Nix
63 lines
1.3 KiB
Nix
lib: {
|
|
attrs,
|
|
indentLevel ? 0,
|
|
importantPrefixes ? ["$" "bezier" "name"],
|
|
}: let
|
|
inherit
|
|
(lib)
|
|
all
|
|
concatMapStringsSep
|
|
concatStrings
|
|
concatStringsSep
|
|
filterAttrs
|
|
foldl
|
|
generators
|
|
hasPrefix
|
|
isAttrs
|
|
isList
|
|
mapAttrsToList
|
|
replicate
|
|
;
|
|
|
|
initialIndent = concatStrings (replicate indentLevel " ");
|
|
|
|
toHyprconf' = indent: attrs: let
|
|
sections =
|
|
filterAttrs (_: v: isAttrs v || (isList v && all isAttrs v)) attrs;
|
|
|
|
mkSection = n: attrs:
|
|
if lib.isList attrs
|
|
then (concatMapStringsSep "\n" (a: mkSection n a) attrs)
|
|
else ''
|
|
${indent}${n} {
|
|
${toHyprconf' " ${indent}" attrs}${indent}}
|
|
'';
|
|
|
|
mkFields = generators.toKeyValue {
|
|
listsAsDuplicateKeys = true;
|
|
inherit indent;
|
|
};
|
|
|
|
allFields =
|
|
filterAttrs (_: 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);
|
|
in
|
|
mkFields importantFields
|
|
+ concatStringsSep "\n" (mapAttrsToList mkSection sections)
|
|
+ mkFields fields;
|
|
in
|
|
toHyprconf' initialIndent attrs
|