-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Unwanted boilerplate: finalAttrs.finalPackage.doCheck #272978
Description
Currently much cross logic is not included in the finalAttrs fixed point, meaning that if you use finalAttrs.doCheck internally in your derivation then this does not automatically account for whether stdenv.buildPlatform.canExecute stdenv.hostPlatform.
The current most elegant fix is to inject finalPackage into the expression, but this is not documented.
Example
For example, consider:
nixpkgs/pkgs/development/libraries/libspatialindex/default.nix
Lines 25 to 27 in 221b92f
| cmakeFlags = [ | |
| "-DSIDX_BUILD_TESTS=${if finalAttrs.doCheck then "ON" else "OFF"}" | |
| ]; |
nix-repl> libspatialindex.cmakeFlags
[ "-DSIDX_BUILD_TESTS=ON" ]
nix-repl> pkgsCross.aarch64-multiplatform.libspatialindex.cmakeFlags
[ "-DSIDX_BUILD_TESTS=ON" "-DCMAKE_SYSTEM_NAME=Linux" "-DCMAKE_SYSTEM_PROCESSOR=aarch64" "-DCMAKE_HOST_SYSTEM_NAME=Linux" "-DCMAKE_HOST_SYSTEM_PROCESSOR=x86_64" ]
The fix is to inject finalPackage:
nixpkgs/pkgs/development/libraries/libspatialindex/default.nix
Lines 25 to 27 in ad5e744
| cmakeFlags = [ | |
| "-DSIDX_BUILD_TESTS=${if finalAttrs.finalPackage.doCheck then "ON" else "OFF"}" | |
| ]; |
which will get us
nix-repl> libspatialindex.cmakeFlags
[ "-DSIDX_BUILD_TESTS=ON" ]
nix-repl> pkgsCross.aarch64-multiplatform.libspatialindex.cmakeFlags
[ "-DSIDX_BUILD_TESTS=OFF" "-DCMAKE_SYSTEM_NAME=Linux" "-DCMAKE_SYSTEM_PROCESSOR=aarch64" "-DCMAKE_HOST_SYSTEM_NAME=Linux" "-DCMAKE_HOST_SYSTEM_PROCESSOR=x86_64" ]
The current recommendation in the docs (added in 2017) is to hoist the cross logic up into the derivation:
nixpkgs/doc/stdenv/cross-compilation.chapter.md
Lines 148 to 154 in 5a67e32
| #### My package’s testsuite needs to run host platform code. {#cross-testsuite-runs-host-code} | |
| Add the following to your `mkDerivation` invocation. | |
| ```nix | |
| doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform; | |
| ``` |
Tree-wide fixes are simple to apply, but are ultimately a bodge. Hence this issue
Related: #266485
Add a 👍 reaction to issues you find important.
Metadata
Metadata
Assignees
Labels
Fields
Give feedbackProjects
Status