feat(lib): Add warn
All checks were successful
Build all the nodes / bridge01 (push) Successful in 1m19s
Build all the nodes / geo02 (push) Successful in 1m23s
Build all the nodes / geo01 (push) Successful in 1m23s
Build all the nodes / rescue01 (push) Successful in 1m28s
Build all the nodes / compute01 (push) Successful in 1m48s
Build all the nodes / storage01 (push) Successful in 1m9s
Build all the nodes / web02 (push) Successful in 1m3s
Build all the nodes / vault01 (push) Successful in 1m18s
Build all the nodes / web03 (push) Successful in 1m2s
Run pre-commit on all files / check (push) Successful in 26s
Build all the nodes / web01 (push) Successful in 1m42s
All checks were successful
Build all the nodes / bridge01 (push) Successful in 1m19s
Build all the nodes / geo02 (push) Successful in 1m23s
Build all the nodes / geo01 (push) Successful in 1m23s
Build all the nodes / rescue01 (push) Successful in 1m28s
Build all the nodes / compute01 (push) Successful in 1m48s
Build all the nodes / storage01 (push) Successful in 1m9s
Build all the nodes / web02 (push) Successful in 1m3s
Build all the nodes / vault01 (push) Successful in 1m18s
Build all the nodes / web03 (push) Successful in 1m2s
Run pre-commit on all files / check (push) Successful in 26s
Build all the nodes / web01 (push) Successful in 1m42s
This commit is contained in:
parent
f909853119
commit
ae057f480f
1 changed files with 46 additions and 0 deletions
|
@ -413,4 +413,50 @@ rec {
|
||||||
flip =
|
flip =
|
||||||
f: a: b:
|
f: a: b:
|
||||||
f b a;
|
f b a;
|
||||||
|
|
||||||
|
/**
|
||||||
|
`warn` *`message`* *`value`*
|
||||||
|
|
||||||
|
Print a warning before returning the second argument.
|
||||||
|
|
||||||
|
See [`builtins.warn`](https://nix.dev/manual/nix/latest/language/builtins.html#builtins-warn) (Nix >= 2.23).
|
||||||
|
On older versions, the Nix 2.23 behavior is emulated with [`builtins.trace`](https://nix.dev/manual/nix/latest/language/builtins.html#builtins-warn), including the [`NIX_ABORT_ON_WARN`](https://nix.dev/manual/nix/latest/command-ref/conf-file#conf-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
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
warn =
|
||||||
|
# Since Nix 2.23, https://github.com/NixOS/nix/pull/10592
|
||||||
|
builtins.warn or (
|
||||||
|
let
|
||||||
|
mustAbort = builtins.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 builtins.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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue