neosyn/lib.nix

32 lines
1.2 KiB
Nix
Raw Permalink Normal View History

2024-11-29 11:35:14 +01:00
final: prev:
let
inherit (builtins)
typeOf isAttrs isList isString
stringLength
mapAttrs;
inherit (final)
filterAttrs
toList
hasPrefix removePrefix concatStringsSep;
in {
extendStringElement = list: pre: sep: ext:
map (elem: if hasPrefix pre elem then concatStringsSep sep
(if stringLength elem == stringLength pre then toList elem else toList elem ++ toList ext) else elem) list;
extendValue = set: name: ext:
assert (set ? ${name} -> typeOf ext == typeOf set.${name});
if isAttrs ext then mapAttrs (final.extendValue set.${name} or { }) ext
else if isList ext then set.${name} or [ ] ++ ext
else if isString ext then set.${name} or "" + "\n" + ext
else ext;
extendAttrs = ext: prevAttrs: mapAttrs (final.extendValue prevAttrs) ext;
extendEnv = ext: prevAttrs: {
env = prevAttrs.env or { }
// (filterAttrs (n: v: !prevAttrs ? ${n}) ext |> mapAttrs (n: v: toList prevAttrs.env.${n} or [ ] ++ v |> toString));
} // (filterAttrs (n: v: prevAttrs ? ${n}) ext |> mapAttrs (n: v: toList prevAttrs.${n} ++ v));
extendDrvAttrs = ext: drv: drv.overrideAttrs (final.extendAttrs ext);
extendDrvEnv = ext: drv: drv.overrideAttrs (final.extendEnv ext);
}