Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce warning spam from nix search #355271

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ let
inherit (self.customisation) overrideDerivation makeOverridable
callPackageWith callPackagesWith extendDerivation hydraJob
makeScope makeScopeWithSplicing makeScopeWithSplicing';
inherit (self.derivations) lazyDerivation optionalDrvAttr;
inherit (self.derivations) lazyDerivation optionalDrvAttr warnOnInstantiate;
inherit (self.meta) addMetaAttrs dontDistribute setName updateName
appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
hiPrioSet licensesSpdx getLicenseFromSpdxId getLicenseFromSpdxIdOr
Expand Down
36 changes: 36 additions & 0 deletions lib/derivations.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ let
inherit (lib)
genAttrs
isString
mapAttrs
removeAttrs
throwIfNot
;

Expand Down Expand Up @@ -206,4 +208,38 @@ in
optionalDrvAttr =
cond:
value: if cond then value else null;

/**
Wrap a derivation such that instantiating it produces a warning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also wrap override and overrideAttrs if they exist? That doesn't cover all possible overriding functions (passthru.withFoo = finalAttrs.finalPackage.overrideAttrs ...;) but that's quite rare.

Perhaps it'd be better to cover all attributes except like meta, name and type?

Regardless of what works best, it would be good to document how it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to wrap everything except those three attributes. Also added a sentence on what exactly it does, and a hint that it's related to nix search.

All attributes apart from `meta`, `name`, and `type` (which are used by
`nix search`) will be wrapped in `lib.warn`.

# Inputs

`msg`
: The warning message to emit (via `lib.warn`).

`drv`
: The derivation to wrap.

# Examples
:::{.example}
## `lib.derivations.warnOnInstantiate` usage example

```nix
{
myPackage = warnOnInstantiate "myPackage has been renamed to my-package" my-package;
}
```

:::
*/
warnOnInstantiate =
msg: drv:
let
drvToWrap = removeAttrs drv [ "meta" "name" "type" ];
in
drv
// mapAttrs (_: lib.warn msg) drvToWrap;
}
6 changes: 3 additions & 3 deletions pkgs/desktops/lomiri/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let
in
lib.makeScope libsForQt5.newScope packages
// lib.optionalAttrs config.allowAliases {
content-hub = lib.warn "`content-hub` was renamed to `lomiri-content-hub`." pkgs.lomiri.lomiri-content-hub; # Added on 2024-09-11
history-service = lib.warn "`history-service` was renamed to `lomiri-history-service`." pkgs.lomiri.lomiri-history-service; # Added on 2024-11-11
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
content-hub = lib.warnOnInstantiate "`content-hub` was renamed to `lomiri-content-hub`." pkgs.lomiri.lomiri-content-hub; # Added on 2024-09-11
history-service = lib.warnOnInstantiate "`history-service` was renamed to `lomiri-history-service`." pkgs.lomiri.lomiri-history-service; # Added on 2024-11-11
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
}
// lib.optionalAttrs pkgs.config.allowAliases {
android-tv-card =
lib.warn "`home-assistant-custom-lovelace-modules.android-tv-card` has been renamed to `universal-remote-card`"
lib.warnOnInstantiate "`home-assistant-custom-lovelace-modules.android-tv-card` has been renamed to `universal-remote-card`"
pkgs.home-assistant-custom-lovelace-modules.universal-remote-card;
}
Loading
Loading