Open
Conversation
eb6300c to
08760b7
Compare
13 tasks
Adds a test framework for evaluating Nixpkgs within a test derivation. This allows testing things that should warn or throw, for example.
08760b7 to
3081eff
Compare
Restores the python deprecated stdenv override tests removed in 9667e93 and adapts them to also validate the emitted warning.
3081eff to
82c46f5
Compare
MattSturgeon
commented
Jan 15, 2026
Comment on lines
69
to
73
Contributor
Author
There was a problem hiding this comment.
With #477208 merged, we can also expect buildPythonPackage-fp-args-stdenv-deprecated to warn.
Tested with:
From 629af6c9da8cdcb8253a2a9d345ebf1281f745e4 Mon Sep 17 00:00:00 2001
From: Matt Sturgeon <[email protected]>
Date: Thu, 15 Jan 2026 11:27:10 +0000
Subject: [PATCH 1/2] tests.eval: check buildPythonPackage fixpoint args
warning
---
pkgs/test/eval/default.nix | 1 +
1 file changed, 1 insertion(+)
diff --git a/pkgs/test/eval/default.nix b/pkgs/test/eval/default.nix
index 5eb709bab139..08fc6587aec8 100644
--- a/pkgs/test/eval/default.nix
+++ b/pkgs/test/eval/default.nix
@@ -70,6 +70,7 @@ runCommand "nixpkgs-pkgs-tests-eval"
overridePythonAttrs-stdenv-deprecated
overridePythonAttrs-override-clangStdenv-deprecated-nested
buildPythonPackage-stdenv-deprecated
+ buildPythonPackage-fp-args-stdenv-deprecated
)
expected_warning='evaluation warning: python-package-stub: Passing `stdenv` directly to `buildPythonPackage` or `buildPythonApplication` is deprecated.'
--
2.52.0From ff90863b81c129fb07d342056dd1dd5148f7976b Mon Sep 17 00:00:00 2001
From: Matt Sturgeon <[email protected]>
Date: Thu, 15 Jan 2026 11:36:29 +0000
Subject: [PATCH 2/2] buildPython*: include package name in fixpoint-args
stdenv warning
In the simple case we attempt to get a name from the input args, as this
avoids evaluating the initial `result`.
In the fixpoint-args scenario, this isn't possible. Therefore, we should
extract the name from `result`.
---
.../python/python-packages-base.nix | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/pkgs/development/interpreters/python/python-packages-base.nix b/pkgs/development/interpreters/python/python-packages-base.nix
index 9537844d10a8..b62ec897de87 100644
--- a/pkgs/development/interpreters/python/python-packages-base.nix
+++ b/pkgs/development/interpreters/python/python-packages-base.nix
@@ -55,24 +55,27 @@ let
args:
let
result = f args;
- applyMsgStdenvArg = lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511) ''
- ${
- args.name or args.pname or "<unnamed>"
- }: Passing `stdenv` directly to `buildPythonPackage` or `buildPythonApplication` is deprecated. You should use their `.override` function instead, e.g:
- buildPythonPackage.override { stdenv = customStdenv; } { }
- '';
+ getName = x: x.pname or (lib.getName (x.name or "<unnamed>"));
+ applyMsgStdenvArg =
+ name:
+ lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511) ''
+ ${name}: Passing `stdenv` directly to `buildPythonPackage` or `buildPythonApplication` is deprecated. You should use their `.override` function instead, e.g:
+ buildPythonPackage.override { stdenv = customStdenv; } { }
+ '';
in
if lib.isFunction args then
if result ? __stdenvPythonCompat then
# Less reliable, as constructing with the wrong `stdenv` might lead to evaluation errors in the package definition.
- f'.override { stdenv = applyMsgStdenvArg result.__stdenvPythonCompat; } (
+ f'.override { stdenv = applyMsgStdenvArg (getName result) result.__stdenvPythonCompat; } (
finalAttrs: removeAttrs (args finalAttrs) [ "stdenv" ]
)
else
result
else if args ? stdenv then
# More reliable, but only works when args is not `(finalAttrs: { })`
- f'.override { stdenv = applyMsgStdenvArg args.stdenv; } (removeAttrs args [ "stdenv" ])
+ f'.override { stdenv = applyMsgStdenvArg (getName args) args.stdenv; } (
+ removeAttrs args [ "stdenv" ]
+ )
else
result
)
--
2.52.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces
pkgs/test/eval, which allows making assertions against a nix evaluation that is run within a test derivation's build script.This is heavily inspired by lib/tests/test-with-nix.nix and Ci's eval comparison, which use the same technique of running nix within a derivation build script.
While this may be useful for any sufficiently complex pkgs tests, adding it is initially motivated by python's deprecated
stdenvoverriding. This needs test coverage but emits warnings, so cannot be directly included in thepkgs.testsevaluation. By using the eval within a build technique, we can not only retain test coverage, we can also make assertion about the emitted warning itself!This is an alternative to the
handleMsgStdenvArgworkaround proposed in #477208 - cc @ShamrockLeeThings done
Add a 👍 reaction to pull requests you find important.