Skip to content

Commit 56340f0

Browse files
authored
Reduce warning spam from nix search (#355271)
2 parents f7727d1 + c62f9b2 commit 56340f0

File tree

6 files changed

+89
-53
lines changed

6 files changed

+89
-53
lines changed

lib/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ let
121121
inherit (self.customisation) overrideDerivation makeOverridable
122122
callPackageWith callPackagesWith extendDerivation hydraJob
123123
makeScope makeScopeWithSplicing makeScopeWithSplicing';
124-
inherit (self.derivations) lazyDerivation optionalDrvAttr;
124+
inherit (self.derivations) lazyDerivation optionalDrvAttr warnOnInstantiate;
125125
inherit (self.meta) addMetaAttrs dontDistribute setName updateName
126126
appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
127127
hiPrioSet licensesSpdx getLicenseFromSpdxId getLicenseFromSpdxIdOr

lib/derivations.nix

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ let
44
inherit (lib)
55
genAttrs
66
isString
7+
mapAttrs
8+
removeAttrs
79
throwIfNot
810
;
911

@@ -206,4 +208,38 @@ in
206208
optionalDrvAttr =
207209
cond:
208210
value: if cond then value else null;
211+
212+
/**
213+
Wrap a derivation such that instantiating it produces a warning.
214+
215+
All attributes apart from `meta`, `name`, and `type` (which are used by
216+
`nix search`) will be wrapped in `lib.warn`.
217+
218+
# Inputs
219+
220+
`msg`
221+
: The warning message to emit (via `lib.warn`).
222+
223+
`drv`
224+
: The derivation to wrap.
225+
226+
# Examples
227+
:::{.example}
228+
## `lib.derivations.warnOnInstantiate` usage example
229+
230+
```nix
231+
{
232+
myPackage = warnOnInstantiate "myPackage has been renamed to my-package" my-package;
233+
}
234+
```
235+
236+
:::
237+
*/
238+
warnOnInstantiate =
239+
msg: drv:
240+
let
241+
drvToWrap = removeAttrs drv [ "meta" "name" "type" ];
242+
in
243+
drv
244+
// mapAttrs (_: lib.warn msg) drvToWrap;
209245
}

pkgs/desktops/lomiri/default.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ let
7070
in
7171
lib.makeScope libsForQt5.newScope packages
7272
// lib.optionalAttrs config.allowAliases {
73-
content-hub = lib.warn "`content-hub` was renamed to `lomiri-content-hub`." pkgs.lomiri.lomiri-content-hub; # Added on 2024-09-11
74-
history-service = lib.warn "`history-service` was renamed to `lomiri-history-service`." pkgs.lomiri.lomiri-history-service; # Added on 2024-11-11
75-
lomiri-system-settings-security-privacy = lib.warn "`lomiri-system-settings-security-privacy` upstream was merged into `lomiri-system-settings`. Please use `pkgs.lomiri.lomiri-system-settings-unwrapped` if you need to directly access the plugins that belonged to this project." pkgs.lomiri.lomiri-system-settings-unwrapped; # Added on 2024-08-08
73+
content-hub = lib.warnOnInstantiate "`content-hub` was renamed to `lomiri-content-hub`." pkgs.lomiri.lomiri-content-hub; # Added on 2024-09-11
74+
history-service = lib.warnOnInstantiate "`history-service` was renamed to `lomiri-history-service`." pkgs.lomiri.lomiri-history-service; # Added on 2024-11-11
75+
lomiri-system-settings-security-privacy = lib.warnOnInstantiate "`lomiri-system-settings-security-privacy` upstream was merged into `lomiri-system-settings`. Please use `pkgs.lomiri.lomiri-system-settings-unwrapped` if you need to directly access the plugins that belonged to this project." pkgs.lomiri.lomiri-system-settings-unwrapped; # Added on 2024-08-08
7676
}

pkgs/servers/home-assistant/custom-lovelace-modules/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@
4747
}
4848
// lib.optionalAttrs pkgs.config.allowAliases {
4949
android-tv-card =
50-
lib.warn "`home-assistant-custom-lovelace-modules.android-tv-card` has been renamed to `universal-remote-card`"
50+
lib.warnOnInstantiate "`home-assistant-custom-lovelace-modules.android-tv-card` has been renamed to `universal-remote-card`"
5151
pkgs.home-assistant-custom-lovelace-modules.universal-remote-card;
5252
}

0 commit comments

Comments
 (0)