dotfiles/nix/repo/lib/mk-deprecate.nix

53 lines
1.2 KiB
Nix
Raw Permalink Normal View History

{
inputs,
cell,
}: let
inherit (cell.lib.ty) brand-ctor brand-coalesce-seq unbranded_name;
deprecate_t = a @ {
id ? null,
msg ? null,
ctx_str ? null,
meta ? null,
/*
the higher the more likely to be removed
*/
stage ? 0,
}: let
ctx =
if ctx_str == null
then ""
else ": ${ctx_str}";
_msg =
if msg == null
then
if id == null
then "deprecated${ctx}"
else "${id} is deprecated${ctx}"
else msg;
in
builtins.trace _msg (v: (brand-ctor "deprecate" v) // {inherit stage;} // a);
in {
inherit deprecate_t;
mkDeprecate = inherit_v: a: deprecate_t ({id = builtins.head (builtins.attrNames inherit_v);} // a) (builtins.head (builtins.attrValues inherit_v));
deprecate-seq-handler = trim_stage: s: let
v = builtins.foldl' (lst: {
__value,
__brand,
...
} @ a:
if __brand == "deprecate" && trim_stage < a.stage
then lst
else
lst
++ [
(
if __brand == "deprecate" || __brand == unbranded_name
then __value
else a
)
]) [] (brand-coalesce-seq s);
in
v;
}