From ec3006ab6fecded108e0c187c5b390012c42cb2b Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 27 Oct 2024 15:32:01 +0100 Subject: [PATCH] overrideAttrs: init --- flake.nix | 1 + src/overrideExisting.nix | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/overrideExisting.nix diff --git a/flake.nix b/flake.nix index 123eed6..7f74a34 100644 --- a/flake.nix +++ b/flake.nix @@ -14,5 +14,6 @@ getAttrs = import ./src/getAttrs.nix lib; subtractLists = import ./src/subtractLists.nix lib; unique = import ./src/unique.nix lib; + overrideExisting = import ./src/overrideExisting.nix lib; }; } diff --git a/src/overrideExisting.nix b/src/overrideExisting.nix new file mode 100644 index 0000000..1e166ea --- /dev/null +++ b/src/overrideExisting.nix @@ -0,0 +1,25 @@ +lib: +let + overrideExistingOld = + old: + new: + builtins.mapAttrs (name: value: new.${name} or value) old; + + overrideExistingNew = + old: + new: + old // (builtins.intersectAttrs old new); + + bigdata = lib.genAttrs (lib.imap0 (i: _: toString i) (lib.replicate 999999 null)) (_: null); + attrsToOverride = { + "1" = "lmao"; + "183" = "lmao"; + "1823" = "lmao"; + "1223" = "lmao"; + "ads;fkjasdlfkja" = "no"; + }; +in { + old = overrideExistingOld bigdata attrsToOverride; + new = overrideExistingNew bigdata attrsToOverride; + sanity = (overrideExistingOld bigdata attrsToOverride) == (overrideExistingNew bigdata attrsToOverride); +}