lib.derivations: avoid common double-warn with warnOnInstantiate

Before:

    $ nix-build . -A opensycl
    trace: evaluation warning: 'opensycl' has been renamed to 'adaptivecpp'
    trace: evaluation warning: 'opensycl' has been renamed to 'adaptivecpp'
    /nix/store/8g0lfv82s0sprmqgfj146ggkb7bn3rm6-adaptivecpp-25.02.0

    $ nix-instantiate . -A opensycl
    trace: evaluation warning: 'opensycl' has been renamed to 'adaptivecpp'
    trace: evaluation warning: 'opensycl' has been renamed to 'adaptivecpp'
    warning: you did not specify '--add-root'; the result might be removed by the garbage collector
    /nix/store/b8q5xp94s4n7zfn7as5a9xjvylh6y3pi-adaptivecpp-25.02.0.drv

After:

    $ nix-build . -A opensycl
    trace: evaluation warning: 'opensycl' has been renamed to 'adaptivecpp'
    /nix/store/8g0lfv82s0sprmqgfj146ggkb7bn3rm6-adaptivecpp-25.02.0

    $ nix-instantiate . -A opensycl
    trace: evaluation warning: 'opensycl' has been renamed to 'adaptivecpp'
    warning: you did not specify '--add-root'; the result might be removed by the garbage collector
    /nix/store/b8q5xp94s4n7zfn7as5a9xjvylh6y3pi-adaptivecpp-25.02.0.drv
This commit is contained in:
Peder Bergebakken Sundt 2025-06-07 00:52:13 +02:00
parent d308aa9772
commit 19086768fe

View File

@ -216,8 +216,9 @@ in
/**
Wrap a derivation such that instantiating it produces a warning.
All attributes apart from `meta`, `name`, and `type` (which are used by
`nix search`) will be wrapped in `lib.warn`.
All attributes will be wrapped with `lib.warn` except from `.meta`, `.name`,
and `.type` which are used by `nix search`, and `.outputName` which avoids
double warnings with `nix-instantiate` and `nix-build`.
# Inputs
@ -246,6 +247,7 @@ in
"meta"
"name"
"type"
"outputName"
];
in
drv // mapAttrs (_: lib.warn msg) drvToWrap;