From 4398adf72ef5e3c37d999a2a83d88e7aed7e0b38 Mon Sep 17 00:00:00 2001 From: Michael Daniels Date: Sun, 15 Mar 2026 15:23:10 -0400 Subject: [PATCH 1/2] octavePackages.buildOctavePackage: add env, nativeBuildInputs args for pkg test --- doc/languages-frameworks/octave.section.md | 11 +++++++++++ doc/redirects.json | 3 +++ .../interpreters/octave/build-octave-package.nix | 10 +++++++++- pkgs/development/interpreters/octave/run-pkg-test.nix | 7 ++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/doc/languages-frameworks/octave.section.md b/doc/languages-frameworks/octave.section.md index 55c5d511581d..44b241c4fc0a 100644 --- a/doc/languages-frameworks/octave.section.md +++ b/doc/languages-frameworks/octave.section.md @@ -76,6 +76,17 @@ See [Symbolic](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/oct `requiredOctavePackages` : This is a special dependency that ensures the specified Octave packages are dependent on others, and are made available simultaneously when loading them in Octave. +### Testing Octave packages {#sssec-testing-octave-packages} + +Octave packages built using the `buildOctavePackage` function do not have a `checkPhase` or `installCheckPhase`. +Instead, the tests `testOctaveBuildEnv` and `testOctavePkgTests` are added to the package's `passthru.tests`. + +`passthru.tests.testOctaveBuildEnv` tests whether the package can be used by `octave.withPackages` successfully. + +`passthru.tests.testOctavePkgTests` runs a `pkg test` command for the package. +If the package needs additional inputs to successfully run the tests, the `nativeOctavePkgTestInputs` attribute can be specified. +If the package needs environment variables to be set to successfully run the tests, ensure that `__structuredAttrs = true;` in the package, then set the environment variables you need in `octavePkgTestEnv` (which should be an attrset where the key is the name of the variable and the value is its value (as a string)). + ### Installing Octave Packages {#sssec-installing-octave-packages} By default, the `buildOctavePackage` function does _not_ install the requested package into Octave for use. diff --git a/doc/redirects.json b/doc/redirects.json index 03285903666e..862a81446182 100644 --- a/doc/redirects.json +++ b/doc/redirects.json @@ -695,6 +695,9 @@ "footnote-stdenv-find-inputs-location.__back.0": [ "index.html#footnote-stdenv-find-inputs-location.__back.0" ], + "sssec-testing-octave-packages": [ + "index.html#sssec-testing-octave-packages" + ], "strictflexarrays1": [ "index.html#strictflexarrays1" ], diff --git a/pkgs/development/interpreters/octave/build-octave-package.nix b/pkgs/development/interpreters/octave/build-octave-package.nix index 66bab3c03b14..ba60b3872902 100644 --- a/pkgs/development/interpreters/octave/build-octave-package.nix +++ b/pkgs/development/interpreters/octave/build-octave-package.nix @@ -46,6 +46,11 @@ # requiredOctavePackages are ALSO installed into octave. requiredOctavePackages ? [ ], + # Dependencies and `env` for octave package tests, + # which are run with .passthru.tests.testOctavePkgTests + nativeOctavePkgTestInputs ? [ ], + octavePkgTestEnv ? { }, + preBuild ? "", meta ? { }, @@ -74,6 +79,7 @@ let # itself, causing everything to fail. attrs' = removeAttrs attrs [ "nativeBuildInputs" + "nativeOctavePkgTestInputs" "passthru" ]; in @@ -143,7 +149,9 @@ stdenv.mkDerivation ( testOctaveBuildEnv = (octave.withPackages (os: [ finalAttrs.finalPackage ])).overrideAttrs (old: { name = "${finalAttrs.name}-pkg-install"; }); - testOctavePkgTests = callPackage ./run-pkg-test.nix { } finalAttrs.finalPackage; + testOctavePkgTests = callPackage ./run-pkg-test.nix { + inherit nativeOctavePkgTestInputs octavePkgTestEnv; + } finalAttrs.finalPackage; } // passthru.tests or { }; }; diff --git a/pkgs/development/interpreters/octave/run-pkg-test.nix b/pkgs/development/interpreters/octave/run-pkg-test.nix index 4665fc92f527..fccf397b41db 100644 --- a/pkgs/development/interpreters/octave/run-pkg-test.nix +++ b/pkgs/development/interpreters/octave/run-pkg-test.nix @@ -1,6 +1,8 @@ { octave, runCommand, + nativeOctavePkgTestInputs, + octavePkgTestEnv, }: package: @@ -8,7 +10,10 @@ runCommand "${package.name}-pkg-test" { nativeBuildInputs = [ (octave.withPackages (os: [ package ])) - ]; + ] + ++ nativeOctavePkgTestInputs; + + env = octavePkgTestEnv; } '' { octave-cli --eval 'pkg test ${package.pname}' || touch FAILED_ERRCODE; } \ From 4ab8ef78eca226ccb0d2e9a6eddb32e6918cefb8 Mon Sep 17 00:00:00 2001 From: Karl Hallsby Date: Wed, 25 Feb 2026 20:55:44 -0600 Subject: [PATCH 2/2] octavePackages.image: add inputs to test environment for graphical tests Some Octave packages require OpenGL for their unit tests, e.g. `octavePackages.image`. Previously, this test script would have erroneous failures because OpenGL could not be found. [1] suggested that we add these to the test environment to remove these incorrect failures. Fixing OpenGL being missing actually meant that gnuplot needed to be pulled in, because these unit tests were plotting AND doing graphics. And because gnuplot needs fonts, we need fontconfig too. [1] https://github.com/NixOS/nixpkgs/pull/491992#issuecomment-3944950414 Co-authored-by: Michael Daniels Co-authored-by: Karl Hallsby --- pkgs/development/octave-modules/image/default.nix | 14 ++++++++++++++ pkgs/top-level/octave-packages.nix | 9 ++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkgs/development/octave-modules/image/default.nix b/pkgs/development/octave-modules/image/default.nix index 37e42d34adfb..4f424e3a4f94 100644 --- a/pkgs/development/octave-modules/image/default.nix +++ b/pkgs/development/octave-modules/image/default.nix @@ -2,6 +2,10 @@ buildOctavePackage, lib, fetchurl, + mesa, + gnuplot, + makeFontsConf, + writableTmpDirAsHomeHook, }: buildOctavePackage rec { @@ -13,6 +17,16 @@ buildOctavePackage rec { sha256 = "sha256-pYY8E5LZd+pPNwzFVH4EsXY8K3fXs6Hyz2zYweXkmRk="; }; + nativeOctavePkgTestInputs = [ + mesa + gnuplot + writableTmpDirAsHomeHook + ]; + + octavePkgTestEnv.FONTCONFIG_FILE = makeFontsConf { fontDirectories = [ ]; }; + + __structuredAttrs = true; + meta = { homepage = "https://gnu-octave.github.io/packages/image/"; license = lib.licenses.gpl3Plus; diff --git a/pkgs/top-level/octave-packages.nix b/pkgs/top-level/octave-packages.nix index e9a8a13608ec..e440e979d5ce 100644 --- a/pkgs/top-level/octave-packages.nix +++ b/pkgs/top-level/octave-packages.nix @@ -116,7 +116,14 @@ makeScope newScope ( inherit (pkgs) gsl; }; - image = callPackage ../development/octave-modules/image { }; + image = callPackage ../development/octave-modules/image { + inherit (pkgs) + mesa + gnuplot + makeFontsConf + writableTmpDirAsHomeHook + ; + }; image-acquisition = callPackage ../development/octave-modules/image-acquisition { };