From 977595f7e8e2f7bfc4a288376d5b4755af7042a8 Mon Sep 17 00:00:00 2001 From: hylodon Date: Sun, 22 Feb 2026 18:46:28 +0000 Subject: [PATCH] Add a monoid to lib that merges objects together --- lib/default.nix | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/default.nix b/lib/default.nix index a9367f8..aa298b3 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,2 +1,29 @@ lib: { + hylonix = { + recursiveMerge = + let + f = + x: y: + if y == null then + x + else if builtins.typeOf x != builtins.typeOf y then + y + else if builtins.typeOf x == "set" then + builtins.listToAttrs ( + builtins.map (name: { + inherit name; + value = f (x.${name} or null) (y.${name} or null); + }) (builtins.attrNames y ++ builtins.attrNames x) + ) + else if builtins.typeOf x == "list" then + x ++ y + else + y; + in + f; + + recursiveMergeAll = builtins.foldl' lib.hylonix.recursiveMerge null; + }; + + inherit (lib.hylonix) recursiveMerge recursiveMergeAll; }