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

lib.oldestSupportedReleaseIsAtLeast: rename from bad name #347258

Merged
merged 2 commits into from
Oct 9, 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
4 changes: 2 additions & 2 deletions lib/attrsets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

let
inherit (builtins) head length;
inherit (lib.trivial) isInOldestRelease mergeAttrs warn warnIf;
inherit (lib.trivial) oldestSupportedReleaseIsAtLeast mergeAttrs warn warnIf;
inherit (lib.strings) concatStringsSep concatMapStringsSep escapeNixIdentifier sanitizeDerivationName;
inherit (lib.lists) foldr foldl' concatMap elemAt all partition groupBy take foldl;
in
Expand Down Expand Up @@ -2137,6 +2137,6 @@ rec {
"lib.zip is a deprecated alias of lib.zipAttrsWith." zipAttrsWith;

# DEPRECATED
cartesianProductOfSets = warnIf (isInOldestRelease 2405)
cartesianProductOfSets = warnIf (oldestSupportedReleaseIsAtLeast 2405)
"lib.cartesianProductOfSets is a deprecated alias of lib.cartesianProduct." cartesianProduct;
Comment on lines +2140 to 2141
Copy link
Member

Choose a reason for hiding this comment

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

This is maybe a bit too long, but I think it's a much better description:

Suggested change
cartesianProductOfSets = warnIf (oldestSupportedReleaseIsAtLeast 2405)
"lib.cartesianProductOfSets is a deprecated alias of lib.cartesianProduct." cartesianProduct;
cartesianProductOfSets = warnIf (allSupportedReleasesSupportAlternativeOriginallyIntroducedIn 2405)
"lib.cartesianProductOfSets is a deprecated alias of lib.cartesianProduct." cartesianProduct;

Hard to remove parts without distorting the meaning though :/

Copy link
Member Author

Choose a reason for hiding this comment

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

The difference is that this description includes the policy, whereas mine only describes the mechanism. I think that's a sensible rule of thumb.

The policy should be documented, certainly, but maybe not in the name of the function.

Also, more high level level functions are possible, such as

foo =
  deprecateForAlternativeIn
    2405
    "use bar instead of foo"
    bar;
# or similar to `mkRenamedOptionModule` iirc, though could be misread
foo = deprecate { old = "package foo"; new = "bar"; sinceRelease 2405; } bar;

Also, such a function could both warn and throw if we decide a standard time frame for that.

Anyway, before veering too far off topic, I think we could do with a slightly better named low level function first.
It will save a few brain cycles when developing the higher level ones.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense and again reminds me of NixOS/rfcs#33 :)

}
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ let
inherit (self.trivial) id const pipe concat or and xor bitAnd bitOr bitXor
bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max
importJSON importTOML warn warnIf warnIfNot throwIf throwIfNot checkListOfEnum
info showWarnings nixpkgsVersion version isInOldestRelease
info showWarnings nixpkgsVersion version isInOldestRelease oldestSupportedReleaseIsAtLeast
mod compare splitByAndCompare seq deepSeq lessThan add sub
functionArgs setFunctionArgs isFunction toFunction mirrorFunctionArgs
fromHexString toHexString toBaseDigits inPureEvalMode isBool isInt pathExists
Expand Down
8 changes: 4 additions & 4 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let
isAttrs
isBool
isFunction
isInOldestRelease
oldestSupportedReleaseIsAtLeast
isList
isString
length
Expand Down Expand Up @@ -1030,7 +1030,7 @@ let
mkForce = mkOverride 50;
mkVMOverride = mkOverride 10; # used by ‘nixos-rebuild build-vm’

defaultPriority = warnIf (isInOldestRelease 2305) "lib.modules.defaultPriority is deprecated, please use lib.modules.defaultOverridePriority instead." defaultOverridePriority;
defaultPriority = warnIf (oldestSupportedReleaseIsAtLeast 2305) "lib.modules.defaultPriority is deprecated, please use lib.modules.defaultOverridePriority instead." defaultOverridePriority;

mkFixStrictness = warn "lib.mkFixStrictness has no effect and will be removed. It returns its argument unmodified, so you can just remove any calls." id;

Expand Down Expand Up @@ -1146,8 +1146,8 @@ let
}: doRename {
inherit from to;
visible = false;
warn = isInOldestRelease sinceRelease;
use = warnIf (isInOldestRelease sinceRelease)
warn = oldestSupportedReleaseIsAtLeast sinceRelease;
use = warnIf (oldestSupportedReleaseIsAtLeast sinceRelease)
"Obsolete option `${showOption from}' is used. It was renamed to `${showOption to}'.";
};

Expand Down
6 changes: 3 additions & 3 deletions lib/sources.nix
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,15 @@ let

in {

pathType = lib.warnIf (lib.isInOldestRelease 2305)
pathType = lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2305)
"lib.sources.pathType has been moved to lib.filesystem.pathType."
lib.filesystem.pathType;

pathIsDirectory = lib.warnIf (lib.isInOldestRelease 2305)
pathIsDirectory = lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2305)
"lib.sources.pathIsDirectory has been moved to lib.filesystem.pathIsDirectory."
lib.filesystem.pathIsDirectory;

pathIsRegularFile = lib.warnIf (lib.isInOldestRelease 2305)
pathIsRegularFile = lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2305)
"lib.sources.pathIsRegularFile has been moved to lib.filesystem.pathIsRegularFile."
lib.filesystem.pathIsRegularFile;

Expand Down
2 changes: 1 addition & 1 deletion lib/strings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,7 @@ rec {
isCoercibleToString :: a -> bool
```
*/
isCoercibleToString = lib.warnIf (lib.isInOldestRelease 2305)
isCoercibleToString = lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2305)
"lib.strings.isCoercibleToString is deprecated in favor of either isStringLike or isConvertibleWithToString. Only use the latter if it needs to return true for null, numbers, booleans and list of similarly coercibles."
isConvertibleWithToString;

Expand Down
9 changes: 9 additions & 0 deletions lib/trivial.nix
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ in {
Set it to the upcoming release, matching the nixpkgs/.version file.
*/
isInOldestRelease =
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2411)
"lib.isInOldestRelease is deprecated. Use lib.oldestSupportedReleaseIsAtLeast instead."
lib.oldestSupportedReleaseIsAtLeast;

/**
Alias for `isInOldestRelease` introduced in 24.11.
Use `isInOldestRelease` in expressions outside of Nixpkgs for greater compatibility.
*/
oldestSupportedReleaseIsAtLeast =
release:
release <= lib.trivial.oldestSupportedRelease;

Expand Down
2 changes: 1 addition & 1 deletion nixos/lib/testing/nodes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ in
nodesCompat =
mapAttrs
(name: config: config // {
config = lib.warnIf (lib.isInOldestRelease 2211)
config = lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2211)
"Module argument `nodes.${name}.config` is deprecated. Use `nodes.${name}` instead."
config;
})
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/substitute/substitute.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let
optionalDeprecationWarning =
# substitutions is only available starting 24.05.
# TODO: Remove support for replacements sometime after the next release
lib.warnIf (args ? replacements && lib.isInOldestRelease 2405) ''
lib.warnIf (args ? replacements && lib.oldestSupportedReleaseIsAtLeast 2405) ''
pkgs.substitute: For "${name}", `replacements` is used, which is deprecated since it doesn't support arguments with spaces. Use `substitutions` instead:
substitutions = [ ${deprecationReplacement} ];'';
in
Expand Down
4 changes: 2 additions & 2 deletions pkgs/development/haskell-modules/lib/compose.nix
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ rec {
which is cross aware instead.
*/
generateOptparseApplicativeCompletions = commands: pkg:
lib.warnIf (lib.isInOldestRelease 2211) "haskellLib.generateOptparseApplicativeCompletions is deprecated in favor of haskellPackages.generateOptparseApplicativeCompletions. Please change ${pkg.name} to use the latter and make sure it uses its matching haskell.packages set!"
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2211) "haskellLib.generateOptparseApplicativeCompletions is deprecated in favor of haskellPackages.generateOptparseApplicativeCompletions. Please change ${pkg.name} to use the latter and make sure it uses its matching haskell.packages set!"
(pkgs.lib.foldr __generateOptparseApplicativeCompletion pkg commands);

/*
Expand All @@ -475,7 +475,7 @@ rec {
which is cross aware instead.
*/
generateOptparseApplicativeCompletion = command: pkg:
lib.warnIf (lib.isInOldestRelease 2211) "haskellLib.generateOptparseApplicativeCompletion is deprecated in favor of haskellPackages.generateOptparseApplicativeCompletions (plural!). Please change ${pkg.name} to use the latter and make sure it uses its matching haskell.packages set!"
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2211) "haskellLib.generateOptparseApplicativeCompletion is deprecated in favor of haskellPackages.generateOptparseApplicativeCompletions (plural!). Please change ${pkg.name} to use the latter and make sure it uses its matching haskell.packages set!"
(__generateOptparseApplicativeCompletion command pkg);

# Don't fail at configure time if there are multiple versions of the
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/interpreters/python/passthrufun.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ in rec {
inherit hasDistutilsCxxPatch;
# Remove after 24.11 is released.
pythonForBuild =
lib.warnIf (lib.isInOldestRelease 2311) "`pythonForBuild` (from `python*`) has been renamed to `pythonOnBuildForHost`"
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2311) "`pythonForBuild` (from `python*`) has been renamed to `pythonOnBuildForHost`"
pythonOnBuildForHost_overridden;
pythonOnBuildForHost = pythonOnBuildForHost_overridden;

Expand Down