NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.55k stars 1.5k forks source link

[feature request]: warning builtin #3028

Closed nmattia closed 4 years ago

nmattia commented 5 years ago

I would love to have a built-in for issuing warnings (same type as builtins.trace) that issues warnings after the build. Would would look like this:

$ cat default.nix
let pkgs = import <nixpkgs> {}; in builtins.warn "bad idea" pkgs.nodejs
$ nix-build
these derivations will be built: # stderr                                                         
  /nix/store/ylmml9yxzjlcpvpb5bql2kjx2zkknfz3-hello.drv # stderr                                                                
building '/nix/store/ylmml9yxzjlcpvpb5bql2kjx2zkknfz3-hello.drv'... # stderr
...
WARNING: bad idea # stderr, yellow
/nix/store/.....-hello # stdout

Warnings would be very useful when e.g. some attribute is deprecated, when some hack is not needed anymore (e.g. new Nix version/nixpkgs version), etc. Using trace is tricky because it often just gets lost at the beginning of the build (or whenever it's being evaluated).

jeremyschlatter commented 4 years ago

See #749

nmattia commented 4 years ago

Thanks @jeremyschlatter !

roberth commented 3 months ago

builtins.warn "bad idea" pkgs.nodejs

Done in https://github.com/NixOS/nix/pull/10592

To be released in Nix 2.24 this week.