overrideAttrs: init

This commit is contained in:
Oystein Kristoffer Tveit 2024-10-27 15:32:01 +01:00
parent 3a6322f7c6
commit ec3006ab6f
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
2 changed files with 26 additions and 0 deletions

View File

@ -14,5 +14,6 @@
getAttrs = import ./src/getAttrs.nix lib; getAttrs = import ./src/getAttrs.nix lib;
subtractLists = import ./src/subtractLists.nix lib; subtractLists = import ./src/subtractLists.nix lib;
unique = import ./src/unique.nix lib; unique = import ./src/unique.nix lib;
overrideExisting = import ./src/overrideExisting.nix lib;
}; };
} }

25
src/overrideExisting.nix Normal file
View File

@ -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);
}