diff --git a/lib/default.nix b/lib/default.nix index 50320669e28..ccae0bbc3ab 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -66,8 +66,9 @@ let stringLength sub substring tail trace; inherit (self.trivial) id const pipe concat or and bitAnd bitOr bitXor bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max - importJSON importTOML warn info showWarnings nixpkgsVersion version mod compare - splitByAndCompare functionArgs setFunctionArgs isFunction toHexString toBaseDigits; + importJSON importTOML warn warnIf info showWarnings nixpkgsVersion version + mod compare splitByAndCompare functionArgs setFunctionArgs isFunction + toHexString toBaseDigits; inherit (self.fixedPoints) fix fix' converge extends composeExtensions composeManyExtensions makeExtensible makeExtensibleWithCustomName; inherit (self.attrsets) attrByPath hasAttrByPath setAttrByPath diff --git a/lib/trivial.nix b/lib/trivial.nix index be6d0115f5b..f6f5da5998f 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -297,12 +297,15 @@ rec { # Usage: # { # foo = lib.warn "foo is deprecated" oldFoo; + # bar = lib.warnIf (bar == "") "Empty bar is deprecated" bar; # } # # TODO: figure out a clever way to integrate location information from # something like __unsafeGetAttrPos. warn = msg: builtins.trace "warning: ${msg}"; + warnIf = cond: msg: if cond then warn msg else id; + info = msg: builtins.trace "INFO: ${msg}"; showWarnings = warnings: res: lib.fold (w: x: warn w x) res warnings;