Skip to content

Commit

Permalink
Switch from checkInputs to nativeCheckInputs on >= NixOS 23.05
Browse files Browse the repository at this point in the history
This unbreaks package tests on the current nixpkgs-unstable branch, as
`buildPythonPackage` has been adjusted to rename `checkInputs` to
`nativeCheckInputs`, breaking existing checkInputs specifications
because of `strictDeps = 1;`. For more information, check out the
corresponding PR at [1]. This implements the proposed workaround[2]
for supporting both the current nixos-unstable and the last release
branch (NixOS 22.11).

[1]: NixOS/nixpkgs#206742
[2]: NixOS/nixpkgs#206742 (comment)

Signed-off-by: Leon Schuermann <leon@is.currently.online>
  • Loading branch information
lschuermann committed Mar 22, 2023
1 parent 67532f5 commit b8eec7f
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pkgs/litedram.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ buildPythonPackage rec {
pytest -v test/
'';

checkInputs = [
# For more information on why this hack is needed, see the
# `pythonCheckInputsMagic.nix` file.
${import ./pythonCheckInputsMagic.nix lib buildPythonPackage} = [
# For test summary
pandas
numpy
Expand Down
4 changes: 3 additions & 1 deletion pkgs/liteeth.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ buildPythonPackage rec {
litex
];

checkInputs = [
# For more information on why this hack is needed, see the
# `pythonCheckInputsMagic.nix` file.
${import ./pythonCheckInputsMagic.nix lib buildPythonPackage} = [
# Some of these are really only required because litex-boards
# needs them for importing all targets in its __init__.py.
liteiclink
Expand Down
4 changes: 3 additions & 1 deletion pkgs/litepcie.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ buildPythonPackage rec {
migen
];

checkInputs = [
# For more information on why this hack is needed, see the
# `pythonCheckInputsMagic.nix` file.
${import ./pythonCheckInputsMagic.nix lib buildPythonPackage} = [
litex-boards
litedram
liteeth
Expand Down
4 changes: 3 additions & 1 deletion pkgs/litescope.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ buildPythonPackage rec {
litex
];

checkInputs = [
# For more information on why this hack is needed, see the
# `pythonCheckInputsMagic.nix` file.
${import ./pythonCheckInputsMagic.nix lib buildPythonPackage} = [
litex
litex-boards
liteiclink
Expand Down
4 changes: 3 additions & 1 deletion pkgs/litex-boards.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ buildPythonPackage rec {

doCheck = true;

checkInputs = [
# For more information on why this hack is needed, see the
# `pythonCheckInputsMagic.nix` file.
${import ./pythonCheckInputsMagic.nix lib buildPythonPackage} = [
pytest
];
checkPhase = ''
Expand Down
4 changes: 3 additions & 1 deletion pkgs/litex/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ buildPythonPackage rec {
packaging
];

checkInputs = [
# For more information on why this hack is needed, see the
# `pythonCheckInputsMagic.nix` file.
${import ../pythonCheckInputsMagic.nix lib buildPythonPackage} = [
litedram
liteeth
liteiclink
Expand Down
44 changes: 44 additions & 0 deletions pkgs/pythonCheckInputsMagic.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# In the current NixOS unstable branch (to be nixos-23.05), `buildPythonPackage`
# has been adjusted to rename `checkInputs` to `nativeCheckInputs`, breaking
# existing checkInputs specifications because of `strictDeps = 1;`. For more
# information, check out the corresponding PR at [1]. This implements the
# proposed workaround[2] for supporting both the current nixos-unstable and the
# last release branch (NixOS 22.11).
#
# It furthermore attempts to identify revisions of the 23.05pre-git
# unstable which did not include this patch.
#
# It returns either "checkInputs" or "nativeCheckInputs", whichever seems
# appropriate.
#
# [1]: https://github.com/NixOS/nixpkgs/pull/206742
# [2]: https://github.com/NixOS/nixpkgs/pull/206742#issuecomment-1417674430

lib: buildPythonPackage:

let
# We check for whether a `buildPythonPackage` derivation with
# `nativeCheckInputs` explicit set propagates this attribute. Commits which
# use `nativeCheckInputs` to actually specify checkPhase dependencies will
# stop this attribute from being propagated.
#
# This does rely on the inner workings of `buildPythonPackage` and hence
# should only be used on revisions where this is known to work.
hasNativeCheckInputs = !(
builtins.hasAttr "nativeCheckInputs" (
buildPythonPackage {
name = "test";
nativeCheckInputs = [ ];
})
);

in

# We limit the nixpkgs revisions of where the `hasNativeCheckInputs` test is
# used to versions older than 23.05 (including 23.05-pre). This is to avoid
# `buildPythonPackage` changing and thus breaking this test in the future.
if lib.versionAtLeast lib.version "23.05" || hasNativeCheckInputs then
"nativeCheckInputs"
else
"checkInputs"

4 changes: 3 additions & 1 deletion pkgs/valentyusb/valentyusb-hw_cdc_eptri.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ buildPythonPackage rec {
litex
];

checkInputs = [
# For more information on why this hack is needed, see the
# `pythonCheckInputsMagic.nix` file.
${import ../pythonCheckInputsMagic.nix lib buildPythonPackage} = [
cocotb
sigrok-cli
verilog
Expand Down

0 comments on commit b8eec7f

Please sign in to comment.