add backport helpers to lib.backport

main
Felix Stupp 1 month ago
parent 07c9126aa9
commit ef0f816b70
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -0,0 +1,42 @@
{ inputs, self, ... }@flakeArg:
let
inherit (inputs) nixpkgs nixpkgs_unstable;
inherit (nixpkgs) lib; # prevent infinite recursion
inherit (builtins) isString;
inherit (lib.attrsets) attrByPath hasAttrByPath updateManyAttrsByPath;
inherit (lib.options) showOption;
inherit (lib.strings) splitString;
inherit (lib.trivial) flip pipe warnIf;
inherit (self) backportByPath;
in
{
backportByPath =
let
pathInterpret = p: if isString p then splitString "." p else p;
in
new: orig: prefix:
flip pipe [
(map (
path:
let
pathList = pathInterpret path;
pathFull = pathInterpret prefix ++ pathList;
error = abort "attr not found on path ${showOption pathFull}";
newVal = attrByPath pathFull error new;
origVal = attrByPath pathFull newVal orig;
in
{
path = pathList;
update =
_:
warnIf (hasAttrByPath pathFull orig) "${showOption pathFull} no longer needs to be backported"
origVal;
}
))
(flip updateManyAttrsByPath { })
];
backportNixpkg = backportByPath nixpkgs_unstable nixpkgs;
}

@ -11,6 +11,7 @@ nixpkgs.lib
# groups # groups
// mapAttrs (autoExtend nixpkgs.lib) { // mapAttrs (autoExtend nixpkgs.lib) {
attrsets = ./attrsets.nix; attrsets = ./attrsets.nix;
backport = ./backport.nix;
lists = ./lists.nix; lists = ./lists.nix;
math = ./math.nix; math = ./math.nix;
modules = ./modules.nix; modules = ./modules.nix;

Loading…
Cancel
Save