`builtins.suppressWarnings` builtin
Is your feature request related to a problem?
I have the following flake: https://codeberg.org/Pandapip1/nixos-linux-rt. It automatically walks through all the nixpkgs kernels and creates PREEMPT_RT variants of them. However, because some filtering is necessary, I have to evaluate all of the entries, which triggers warnings:
evaluation warning: linux-rpi series will be removed in a future release. Please change to use nixos-hardware.
evaluation warning: linux-rpi series will be removed in a future release. Please change to use nixos-hardware.
evaluation warning: linux-rpi series will be removed in a future release. Please change to use nixos-hardware.
evaluation warning: linux-rpi series will be removed in a future release. Please change to use nixos-hardware.
Proposed solution
A builtin builtins.suppressWarnings that operates similarly to builtins.tryEval, except it suppresses warnings instead of eval errors.
Alternative solutions
The filtering code is as follows:
upstreamKernels = pkgs.linuxKernel.kernels;
safeKernels = lib.filterAttrs (_: isSafeKernel) upstreamKernels;
rtKernels = lib.mapAttrs (_: mkRtKernel) safeKernels;
If builtins.filterAttrs existed (https://github.com/NixOS/nix/issues/11888), then safeKernels would not require the evaluation of the entirety of upstreamKernels, and I wouldn't have to deal with these warnings.
Additional context
N.A.
Checklist
- [x] checked latest Nix manual (source)
- [x] checked open feature issues and pull requests for possible duplicates
Add :+1: to issues you find important.
This builtin would be a bit quirky. Because call-by-need saves various intermediate results, you would be able to
- have
a = builtins.warn "foo" something; - in package
x:
- evaluate
aas part of asuppressWarningscall, not emitting the warning - ignore the value of
a
- in package
y:
- evaluate
a - use the value of
a
Here y should have triggered the warning, but didn't because of call-by-need.
A crude way to solve this is to create a new evaluator + heap to cut out any sharing, but that risks other side effects (e.g. broken function equality breaking some more). I don't think we'd want to go there.
Ideally you could expose enough information in a way that doesn't trigger the warning?
For example, Nixpkgs has warnOnInstantiate to delay the warning until outPath or similar is accessed.
Maybe something like that could be used in your situation too?
I've been struggling with similar. I run nixos-unstable with zfs, so I iterate all of the kernel packages to find the most recent kernel with zfs support to stay (mostly) pinned to the latest tagged zfs release without twiddling zfs_*version numbers with every release.
I've been getting annoyed with more breaks pushing into my hydra due to getting blocked out of abort-on-warn, and eventually took the time to dig into this and part of that led me here. I landed on just filtering out the linux_rpi* packages by filtering on name prefix before evaluating attributes that warn. Similar might help you with the rpi warnings.
I'd still love a feature like this, or exceptions on abort-on-warn. stdenv.hostPlatform.* warnings have been pretty endless for me from upstream flakes.
abort-on-warn,
As the author, I would recommend to use that as a flag for finding details about warnings and nothing else.
or exceptions on
abort-on-warn
I think you mean making tryEval catch these aborts?
The purpose of the flag is to produce a trace, so getting tryEval to swallow those traces would make it incapable of serving its original purpose.
abort-on-warn,As the author, I would recommend to use that as a flag for finding details about warnings and nothing else.
or exceptions on
abort-on-warnI think you mean making
tryEvalcatch these aborts? The purpose of the flag is to produce a trace, so gettingtryEvalto swallow those traces would make it incapable of serving its original purpose.
I know it's not really intended to be used as a linting tool, but it kind of quacks like one.
I like when I can have it enabled. It draws my attention to upcoming deprecations in otherwise automated flows. If the warnings are local I fix them immediately. If it's upstream I tend to disable abort-on-warn and more issues that would be open PRs waiting for me turn into broken hydra builds waiting for me. Not a huge difference at the end of the day, but I prefer the former. If I could ignore warnings matching a specific string pattern or warning class and attach tracking an issue to that, I'd do that instead.