warn
lib.trivial.warn
Docs pulled from | This Revision | 10 minutes ago
warn
message
value
Print a warning before returning the second argument.
See builtins.warn
(Nix >= 2.23).
On older versions, the Nix 2.23 behavior is emulated with builtins.trace
, including the NIX_ABORT_ON_WARN
behavior, but not the nix.conf
setting or command line option.
Inputs
message
(String)-
Warning message to print before evaluating
value
. value
(any value)-
Value to return as-is.
Type
String -> a -> a
Noogle detected
Implementation
The following is the current implementation of this function.
warn =
# Since Nix 2.23, https://github.com/NixOS/nix/pull/10592
builtins.warn or (
let mustAbort = lib.elem (builtins.getEnv "NIX_ABORT_ON_WARN") ["1" "true" "yes"];
in
# Do not eta reduce v, so that we have the same strictness as `builtins.warn`.
msg: v:
# `builtins.warn` requires a string message, so we enforce that in our implementation, so that callers aren't accidentally incompatible with newer Nix versions.
assert isString msg;
if mustAbort
then builtins.trace "[1;31mevaluation warning:[0m ${msg}" (abort "NIX_ABORT_ON_WARN=true; warnings are treated as unrecoverable errors.")
else builtins.trace "[1;35mevaluation warning:[0m ${msg}" v
);