diff --git a/doc/builders/testers.chapter.md b/doc/builders/testers.chapter.md index 3d91f096051e..a0f0f97f9d53 100644 --- a/doc/builders/testers.chapter.md +++ b/doc/builders/testers.chapter.md @@ -1,6 +1,19 @@ # Testers {#chap-testers} This chapter describes several testing builders which are available in the testers namespace. +## `hasPkgConfigModule` {#tester-hasPkgConfigModule} + +Checks whether a package exposes a certain `pkg-config` module. + +Example: + +```nix +passthru.tests.pkg-config = testers.hasPkgConfigModule { + package = finalAttrs.finalPackage; + moduleName = "libfoo"; +} +``` + ## `testVersion` {#tester-testVersion} Checks the command output contains the specified version diff --git a/doc/languages-frameworks/index.xml b/doc/languages-frameworks/index.xml index 7d404643d369..3774924c0be4 100644 --- a/doc/languages-frameworks/index.xml +++ b/doc/languages-frameworks/index.xml @@ -32,6 +32,7 @@ + diff --git a/doc/languages-frameworks/pkg-config.section.md b/doc/languages-frameworks/pkg-config.section.md new file mode 100644 index 000000000000..ee0a471be3e5 --- /dev/null +++ b/doc/languages-frameworks/pkg-config.section.md @@ -0,0 +1,9 @@ +# pkg-config {#sec-pkg-config} + +*pkg-config* is a unified interface for declaring and querying built C/C++ libraries. + +Nixpkgs provides a couple of facilities for working with this tool. + + - A [setup hook](#setup-hook-pkg-config) bundled with in the `pkg-config` package, to bring a derivation's declared build inputs into the environment. + - The [`validatePkgConfig` setup hook](https://nixos.org/manual/nixpkgs/stable/#validatepkgconfig), for packages that provide pkg-config modules. + - The `defaultPkgConfigPackages` package set: a set of aliases, named after the modules they provide. This is meant to be used by language-to-nix integrations. Hand-written packages should use the normal Nixpkgs attribute name instead. diff --git a/lib/customisation.nix b/lib/customisation.nix index 101c9e62b9e6..42d711cf5fb9 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -252,7 +252,8 @@ rec { outputsList = map makeOutput outputs; drv' = (lib.head outputsList).value; - in lib.deepSeq drv' drv'; + in if drv == null then null else + lib.deepSeq drv' drv'; /* Make a set of packages with a common scope. All packages called with the provided `callPackage` will be evaluated with the same diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index 6ab0ee843cb0..15694162edde 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -121,4 +121,6 @@ in nixosTesting.simpleTest calledTest; + hasPkgConfigModule = callPackage ./hasPkgConfigModule/tester.nix { }; + } diff --git a/pkgs/build-support/testers/hasPkgConfigModule/tester.nix b/pkgs/build-support/testers/hasPkgConfigModule/tester.nix new file mode 100644 index 000000000000..c8342cdd5c3b --- /dev/null +++ b/pkgs/build-support/testers/hasPkgConfigModule/tester.nix @@ -0,0 +1,47 @@ +# Static arguments +{ runCommand, pkg-config }: + +# Tester arguments +{ package, + moduleName, + testName ? "check-pkg-config-${moduleName}", +}: + +runCommand testName { + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ package ]; + inherit moduleName; + meta = { + description = "Test whether ${package.name} exposes pkg-config module ${moduleName}"; + } + # Make sure licensing info etc is preserved, as this is a concern for e.g. cache.nixos.org, + # as hydra can't check this meta info in dependencies. + # The test itself is just Nixpkgs, with MIT license. + // builtins.intersectAttrs + { + available = throw "unused"; + broken = throw "unused"; + insecure = throw "unused"; + license = throw "unused"; + maintainers = throw "unused"; + platforms = throw "unused"; + unfree = throw "unused"; + unsupported = throw "unused"; + } + package.meta; + } '' + echo "checking pkg-config module $moduleName in $buildInputs" + set +e + version="$(pkg-config --modversion $moduleName)" + r=$? + set -e + if [[ $r = 0 ]]; then + echo "✅ pkg-config module $moduleName exists and has version $version" + echo "$version" > $out + else + echo "These modules were available in the input propagation closure:" + pkg-config --list-all + echo "❌ pkg-config module $moduleName was not found" + false + fi + '' diff --git a/pkgs/build-support/testers/hasPkgConfigModule/tests.nix b/pkgs/build-support/testers/hasPkgConfigModule/tests.nix new file mode 100644 index 000000000000..8005c3f93709 --- /dev/null +++ b/pkgs/build-support/testers/hasPkgConfigModule/tests.nix @@ -0,0 +1,36 @@ +# cd nixpkgs +# nix-build -A tests.testers.hasPkgConfigModule +{ lib, testers, zlib, runCommand }: + +lib.recurseIntoAttrs { + + zlib-has-zlib = testers.hasPkgConfigModule { + package = zlib; + moduleName = "zlib"; + }; + + zlib-does-not-have-ylib = runCommand "zlib-does-not-have-ylib" { + failed = testers.testBuildFailure ( + testers.hasPkgConfigModule { + package = zlib; + moduleName = "ylib"; + } + ); + } '' + echo 'it logs a relevant error message' + { + grep -F "pkg-config module ylib was not found" $failed/testBuildFailure.log + } + + echo 'it logs which pkg-config modules are available, to be helpful' + { + # grep -v: the string zlib does also occur in a store path in an earlier message, which isn't particularly helpful + grep -v "checking pkg-config module" < $failed/testBuildFailure.log \ + | grep -F "zlib" + } + + # done + touch $out + ''; + +} diff --git a/pkgs/build-support/testers/test/default.nix b/pkgs/build-support/testers/test/default.nix index 0a5381b2b738..313c556737fb 100644 --- a/pkgs/build-support/testers/test/default.nix +++ b/pkgs/build-support/testers/test/default.nix @@ -12,6 +12,8 @@ let in lib.recurseIntoAttrs { + hasPkgConfigModule = pkgs.callPackage ../hasPkgConfigModule/tests.nix { }; + # Check that the wiring of nixosTest is correct. # Correct operation of the NixOS test driver should be asserted elsewhere. nixosTest-example = pkgs-with-overlay.testers.nixosTest ({ lib, pkgs, figlet, ... }: { diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 818001018b3a..39039c5950e4 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -51,6 +51,8 @@ with pkgs; php = recurseIntoAttrs (callPackages ./php {}); + pkg-config = recurseIntoAttrs (callPackage ../top-level/pkg-config/tests.nix { }); + rustCustomSysroot = callPackage ./rust-sysroot {}; buildRustCrate = callPackage ../build-support/rust/build-rust-crate/test { }; importCargoLock = callPackage ../build-support/rust/test/import-cargo-lock { }; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 918be082e114..c859120680aa 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -112,6 +112,12 @@ with pkgs; tests = callPackages ../test {}; + defaultPkgConfigPackages = + # We don't want nix-env -q to enter this, because all of these are aliases. + dontRecurseIntoAttrs ( + import ./pkg-config/defaultPkgConfigPackages.nix pkgs + ); + ### Nixpkgs maintainer tools nix-generate-from-cpan = callPackage ../../maintainers/scripts/nix-generate-from-cpan.nix { }; diff --git a/pkgs/top-level/pkg-config/defaultPkgConfigPackages.nix b/pkgs/top-level/pkg-config/defaultPkgConfigPackages.nix new file mode 100644 index 000000000000..b3cf3cdca2fc --- /dev/null +++ b/pkgs/top-level/pkg-config/defaultPkgConfigPackages.nix @@ -0,0 +1,45 @@ +/* A set of aliases to be used in generated expressions. + + In case of ambiguity, this will pick a sensible default. + + This was initially based on cabal2nix's mapping. + + It'd be nice to generate this mapping, based on a set of derivations. + It can not be fully automated, so it should be a expression or tool + that makes suggestions about which pkg-config module names can be added. + */ +pkgs: + +let + inherit (pkgs) lib; + inherit (lib) + all + flip + mapAttrs + mapAttrsToList + getAttrFromPath + importJSON + ; + + data = importJSON ./pkg-config-data.json; + inherit (data) modules; + + platform = pkgs.stdenv.hostPlatform; + + isSupported = moduleData: + moduleData?supportedWhenPlatformAttrsEqual -> + all (x: x) ( + mapAttrsToList + (k: v: platform?${k} && platform.${k} == v) + moduleData.supportedWhenPlatformAttrsEqual + ); + + modulePkgs = flip mapAttrs modules (_moduleName: moduleData: + if moduleData?attrPath && isSupported moduleData then + getAttrFromPath moduleData.attrPath pkgs + else + null + ); + +in + modulePkgs diff --git a/pkgs/top-level/pkg-config/pkg-config-data.json b/pkgs/top-level/pkg-config/pkg-config-data.json new file mode 100644 index 000000000000..61ed9098b919 --- /dev/null +++ b/pkgs/top-level/pkg-config/pkg-config-data.json @@ -0,0 +1,964 @@ +{ + "version": { + "major": 0, + "minor": 1 + }, + "modules": { + "IL": { + "attrPath": [ + "libdevil" + ] + }, + "ImageMagick": { + "attrPath": [ + "imagemagick" + ] + }, + "MagickWand": { + "attrPath": [ + "imagemagick" + ] + }, + "Qt5Concurrent": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5Core": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5DBus": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5Gui": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5Network": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5OpenGL": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5OpenGLExtensions": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5PrintSupport": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5Qml": { + "attrPath": [ + "qt5", + "qtdeclarative" + ] + }, + "Qt5QmlModels": { + "attrPath": [ + "qt5", + "qtdeclarative" + ] + }, + "Qt5Quick": { + "attrPath": [ + "qt5", + "qtdeclarative" + ] + }, + "Qt5QuickTest": { + "attrPath": [ + "qt5", + "qtdeclarative" + ] + }, + "Qt5QuickWidgets": { + "attrPath": [ + "qt5", + "qtdeclarative" + ] + }, + "Qt5Sql": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5Test": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5Widgets": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "Qt5Xml": { + "attrPath": [ + "qt5", + "qtbase" + ] + }, + "SoapySDR": { + "attrPath": [ + "soapysdr" + ] + }, + "alsa": { + "attrPath": [ + "alsa-lib" + ] + }, + "alsa-topology": { + "attrPath": [ + "alsa-lib" + ] + }, + "appindicator-0.1": { + "attrPath": [ + "libappindicator-gtk2" + ] + }, + "appindicator3-0.1": { + "attrPath": [ + "libappindicator-gtk3" + ] + }, + "bzip2": { + "attrPath": [ + "bzip2" + ] + }, + "cairo-gobject": { + "attrPath": [ + "cairo" + ] + }, + "cairo-pdf": { + "attrPath": [ + "cairo" + ] + }, + "cairo-ps": { + "attrPath": [ + "cairo" + ] + }, + "cairo-svg": { + "attrPath": [ + "cairo" + ] + }, + "dbusmenu-glib-0.4": { + "attrPath": [ + "libdbusmenu" + ] + }, + "dbusmenu-gtk3-0.4": { + "attrPath": [ + "libdbusmenu-gtk3" + ] + }, + "egl": { + "attrPath": [ + "libGL" + ], + "supportedWhenPlatformAttrsEqual": { + "isDarwin": false + } + }, + "fftw3": { + "attrPath": [ + "fftw" + ] + }, + "fftw3f": { + "attrPath": [ + "fftwFloat" + ] + }, + "form": { + "attrPath": [ + "ncurses" + ] + }, + "formw": { + "attrPath": [ + "ncurses" + ] + }, + "freealut": { + "attrPath": [ + "freealut" + ] + }, + "freetype2": { + "attrPath": [ + "freetype" + ] + }, + "gdk-2.0": { + "attrPath": [ + "gtk2" + ] + }, + "gdk-3.0": { + "attrPath": [ + "gtk3" + ] + }, + "gdk-pixbuf-2.0": { + "attrPath": [ + "gdk-pixbuf" + ] + }, + "gdk-x11-2.0": { + "attrPath": [ + "gtk2-x11" + ] + }, + "gdk-x11-3.0": { + "attrPath": [ + "gtk3-x11" + ] + }, + "geos": { + "attrPath": [ + "geos" + ] + }, + "gio-2.0": { + "attrPath": [ + "glib" + ] + }, + "gl": { + "attrPath": [ + "libGL" + ] + }, + "glew": { + "attrPath": [ + "glew" + ] + }, + "glu": { + "attrPath": [ + "libGLU" + ] + }, + "glut": { + "attrPath": [ + "freeglut" + ] + }, + "gnome-keyring-1": { + "attrPath": [ + "libgnome-keyring" + ] + }, + "gnome-vfs-2.0": { + "attrPath": [ + "gnome2", + "gnome_vfs" + ] + }, + "gnome-vfs-module-2.0": { + "attrPath": [ + "gnome2", + "gnome_vfs" + ] + }, + "gobject-2.0": { + "attrPath": [ + "glib" + ] + }, + "gobject-introspection-1.0": { + "attrPath": [ + "gobject-introspection" + ] + }, + "gstreamer-audio-1.0": { + "attrPath": [ + "gst_all_1", + "gst-plugins-base" + ] + }, + "gstreamer-base-1.0": { + "attrPath": [ + "gst_all_1", + "gst-plugins-base" + ] + }, + "gstreamer-controller-1.0": { + "attrPath": [ + "gst_all_1", + "gstreamer" + ] + }, + "gstreamer-net-1.0": { + "attrPath": [ + "gst_all_1", + "gst-plugins-base" + ] + }, + "gstreamer-video-1.0": { + "attrPath": [ + "gst_all_1", + "gst-plugins-base" + ] + }, + "gthread-2.0": { + "attrPath": [ + "glib" + ] + }, + "gtk+-2.0": { + "attrPath": [ + "gtk2" + ] + }, + "gtk+-3.0": { + "attrPath": [ + "gtk3" + ] + }, + "gtk+-x11-2.0": { + "attrPath": [ + "gtk2-x11" + ] + }, + "gtksourceview-3.0": { + "attrPath": [ + "gtksourceview3" + ] + }, + "hidapi": { + "attrPath": [ + "hidapi" + ], + "supportedWhenPlatformAttrsEqual": { + "isDarwin": true + } + }, + "hidapi-hidraw": { + "attrPath": [ + "hidapi" + ], + "supportedWhenPlatformAttrsEqual": { + "isDarwin": false + } + }, + "hidapi-libusb": { + "attrPath": [ + "hidapi" + ], + "supportedWhenPlatformAttrsEqual": { + "isDarwin": false + } + }, + "icu-i18n": { + "attrPath": [ + "icu" + ] + }, + "icu-io": { + "attrPath": [ + "icu" + ] + }, + "icu-uc": { + "attrPath": [ + "icu" + ] + }, + "imlib2": { + "attrPath": [ + "imlib2" + ] + }, + "jack": { + "attrPath": [ + "libjack2" + ] + }, + "javascriptcoregtk-4.0": { + "attrPath": [ + "webkitgtk" + ] + }, + "lapack": { + "attrPath": [ + "liblapack" + ] + }, + "libR": { + "attrPath": [ + "R" + ] + }, + "libavutil": { + "attrPath": [ + "ffmpeg" + ] + }, + "libb2": { + "attrPath": [ + "libb2" + ] + }, + "libbrotlidec": { + "attrPath": [ + "brotli" + ] + }, + "libbrotlienc": { + "attrPath": [ + "brotli" + ] + }, + "libcrypto": { + "attrPath": [ + "openssl" + ] + }, + "libecpg": { + "attrPath": [ + "postgresql" + ] + }, + "libecpg_compat": { + "attrPath": [ + "postgresql" + ] + }, + "libgsasl": { + "attrPath": [ + "gsasl" + ] + }, + "libidn": { + "attrPath": [ + "libidn" + ] + }, + "libjpeg": { + "attrPath": [ + "libjpeg" + ] + }, + "liblzma": { + "attrPath": [ + "xz" + ] + }, + "libmagic": { + "attrPath": [ + "file" + ] + }, + "libmnl": { + "attrPath": [ + "libmnl" + ] + }, + "libnotify": { + "attrPath": [ + "libnotify" + ] + }, + "libpcap": { + "attrPath": [ + "libpcap" + ] + }, + "libpcre": { + "attrPath": [ + "pcre" + ] + }, + "libpcre2-16": { + "attrPath": [ + "pcre2" + ] + }, + "libpcre2-32": { + "attrPath": [ + "pcre2" + ] + }, + "libpcre2-8": { + "attrPath": [ + "pcre2" + ] + }, + "libpcre2-posix": { + "attrPath": [ + "pcre2" + ] + }, + "libpgtypes": { + "attrPath": [ + "postgresql" + ] + }, + "libpng": { + "attrPath": [ + "libpng" + ] + }, + "libpq": { + "attrPath": [ + "postgresql" + ] + }, + "libpulse": { + "attrPath": [ + "libpulseaudio" + ] + }, + "libpulse-mainloop-glib": { + "attrPath": [ + "libpulseaudio" + ], + "supportedWhenPlatformAttrsEqual": { + "isDarwin": false + } + }, + "libpulse-simple": { + "attrPath": [ + "libpulseaudio" + ] + }, + "libqrencode": { + "attrPath": [ + "qrencode" + ] + }, + "librtlsdr": { + "attrPath": [ + "rtl-sdr" + ] + }, + "libsass": { + "attrPath": [ + "libsass" + ] + }, + "libsctp": { + "attrPath": [ + "lksctp-tools" + ] + }, + "libsecp256k1": { + "attrPath": [ + "secp256k1" + ] + }, + "libsodium": { + "attrPath": [ + "libsodium" + ] + }, + "libsoup-gnome-2.4": { + "attrPath": [ + "libsoup" + ] + }, + "libssh2": { + "attrPath": [ + "libssh2" + ] + }, + "libssl": { + "attrPath": [ + "openssl" + ] + }, + "libstatgrab": { + "attrPath": [ + "libstatgrab" + ] + }, + "libsystemd": { + "attrPath": [ + "systemd" + ] + }, + "libturbojpeg": { + "attrPath": [ + "libjpeg" + ] + }, + "libudev": { + "attrPath": [ + "systemd" + ] + }, + "libxml-2.0": { + "attrPath": [ + "libxml2" + ] + }, + "libzip": { + "attrPath": [ + "libzip" + ] + }, + "libzmq": { + "attrPath": [ + "zeromq" + ] + }, + "menu": { + "attrPath": [ + "ncurses" + ] + }, + "menuw": { + "attrPath": [ + "ncurses" + ] + }, + "ncurses": { + "attrPath": [ + "ncurses" + ] + }, + "ncurses++": { + "attrPath": [ + "ncurses" + ] + }, + "ncurses++w": { + "attrPath": [ + "ncurses" + ] + }, + "ncursesw": { + "attrPath": [ + "ncurses" + ] + }, + "netsnmp": { + "attrPath": [ + "net_snmp" + ] + }, + "nix-cmd": { + "attrPath": [ + "nix" + ] + }, + "nix-expr": { + "attrPath": [ + "nix" + ] + }, + "nix-main": { + "attrPath": [ + "nix" + ] + }, + "nix-store": { + "attrPath": [ + "nix" + ] + }, + "odbc": { + "attrPath": [ + "unixODBC" + ] + }, + "ompi": { + "attrPath": [ + "openmpi" + ] + }, + "ompi-c": { + "attrPath": [ + "openmpi" + ] + }, + "ompi-cxx": { + "attrPath": [ + "openmpi" + ] + }, + "ompi-f77": { + "attrPath": [ + "openmpi" + ] + }, + "ompi-f90": { + "attrPath": [ + "openmpi" + ] + }, + "ompi-fort": { + "attrPath": [ + "openmpi" + ] + }, + "openblas": { + "attrPath": [ + "openblasCompat" + ] + }, + "openssl": { + "attrPath": [ + "openssl" + ] + }, + "orte": { + "attrPath": [ + "openmpi" + ] + }, + "panel": { + "attrPath": [ + "ncurses" + ] + }, + "panelw": { + "attrPath": [ + "ncurses" + ] + }, + "pangocairo": { + "attrPath": [ + "pango" + ] + }, + "poppler-glib": { + "attrPath": [ + "poppler_gi" + ] + }, + "python": { + "attrPath": [ + "python3" + ] + }, + "ruby-2.7": { + "attrPath": [ + "ruby_2_7" + ] + }, + "ruby-3.0": { + "attrPath": [ + "ruby_3_0" + ] + }, + "ruby-3.1": { + "attrPath": [ + "ruby_3_1" + ] + }, + "sdl2": { + "attrPath": [ + "SDL2" + ] + }, + "sndfile": { + "attrPath": [ + "libsndfile" + ] + }, + "sqlite3": { + "attrPath": [ + "sqlite" + ] + }, + "taglib": { + "attrPath": [ + "taglib" + ] + }, + "taglib_c": { + "attrPath": [ + "taglib" + ] + }, + "tdjson": { + "attrPath": [ + "tdlib" + ] + }, + "tensorflow": { + "attrPath": [ + "libtensorflow" + ] + }, + "uuid": { + "attrPath": [ + "libossp_uuid" + ] + }, + "vte-2.91": { + "attrPath": [ + "vte" + ] + }, + "wayland-client": { + "attrPath": [ + "wayland" + ], + "supportedWhenPlatformAttrsEqual": { + "isDarwin": false + } + }, + "wayland-cursor": { + "attrPath": [ + "wayland" + ], + "supportedWhenPlatformAttrsEqual": { + "isDarwin": false + } + }, + "wayland-scanner": { + "attrPath": [ + "wayland" + ] + }, + "wayland-server": { + "attrPath": [ + "wayland" + ], + "supportedWhenPlatformAttrsEqual": { + "isDarwin": false + } + }, + "webkit2gtk-4.0": { + "attrPath": [ + "webkitgtk" + ] + }, + "webkit2gtk-web-extension-4.0": { + "attrPath": [ + "webkitgtk" + ] + }, + "x11": { + "attrPath": [ + "xorg", + "libX11" + ] + }, + "xau": { + "attrPath": [ + "xorg", + "libXau" + ] + }, + "xcursor": { + "attrPath": [ + "xorg", + "libXcursor" + ] + }, + "xerces-c": { + "attrPath": [ + "xercesc" + ] + }, + "xext": { + "attrPath": [ + "xorg", + "libXext" + ] + }, + "xft": { + "attrPath": [ + "xorg", + "libXft" + ] + }, + "xi": { + "attrPath": [ + "xorg", + "libXi" + ] + }, + "xinerama": { + "attrPath": [ + "xorg", + "libXinerama" + ] + }, + "xkbcommon": { + "attrPath": [ + "libxkbcommon" + ] + }, + "xpm": { + "attrPath": [ + "xorg", + "libXpm" + ] + }, + "xrandr": { + "attrPath": [ + "xorg", + "libXrandr" + ] + }, + "xrender": { + "attrPath": [ + "xorg", + "libXrender" + ] + }, + "xscrnsaver": { + "attrPath": [ + "xorg", + "libXScrnSaver" + ] + }, + "xtst": { + "attrPath": [ + "xorg", + "libXtst" + ] + }, + "xxf86vm": { + "attrPath": [ + "xorg", + "libXxf86vm" + ] + }, + "yaml-0.1": { + "attrPath": [ + "libyaml" + ] + }, + "zlib": { + "attrPath": [ + "zlib" + ] + } + } +} diff --git a/pkgs/top-level/pkg-config/test-defaultPkgConfigPackages.nix b/pkgs/top-level/pkg-config/test-defaultPkgConfigPackages.nix new file mode 100644 index 000000000000..37687117987d --- /dev/null +++ b/pkgs/top-level/pkg-config/test-defaultPkgConfigPackages.nix @@ -0,0 +1,45 @@ +# cd nixpkgs +# nix-build -A tests.pkg-config.defaultPkgConfigPackages +{ lib, pkg-config, defaultPkgConfigPackages, runCommand, testers }: +let + inherit (lib.strings) escapeNixIdentifier; + + allTests = lib.mapAttrs (k: v: if v == null then null else makePkgConfigTestMaybe k v) defaultPkgConfigPackages; + + # nix-build rejects attribute names with periods + # This will build those regardless. + tests-combined = runCommand "pkg-config-checks" { + allTests = lib.attrValues allTests; + } '' + touch $out + ''; + + makePkgConfigTestMaybe = moduleName: pkg: + if ! lib.isDerivation pkg + then + throw "pkg-config module `${escapeNixIdentifier moduleName}` is not defined to be a derivation. Please check the attribute value for `${escapeNixIdentifier moduleName}` in `pkgs/top-level/pkg-config-packages.nix` in Nixpkgs." + + else if ! pkg?meta.unsupported + then + throw "pkg-config module `${escapeNixIdentifier moduleName}` does not have a `meta.unsupported` attribute. This can't be right. Please check the attribute value for `${escapeNixIdentifier moduleName}` in `pkgs/top-level/pkg-config-packages.nix` in Nixpkgs." + + else if pkg.meta.unsupported + then + # We return `null` instead of doing a `filterAttrs`, because with + # `filterAttrs` the evaluator would not be able to return the attribute + # set without first evaluating all of the attribute _values_. This would + # be rather expensive, and severly slow down the use case of getting a + # single test, which we want to do in `passthru.tests`, or interactively. + null + + else if ! pkg?meta.broken + then + throw "pkg-config module `${escapeNixIdentifier moduleName}` does not have a `meta.broken` attribute. This can't be right. Please check the attribute value for `${escapeNixIdentifier moduleName}` in `pkgs/top-level/pkg-config.packages.nix` in Nixpkgs." + + else if pkg.meta.broken + then null + + else testers.hasPkgConfigModule { inherit moduleName; package = pkg; }; + +in + lib.recurseIntoAttrs allTests // { inherit tests-combined; } diff --git a/pkgs/top-level/pkg-config/tests.nix b/pkgs/top-level/pkg-config/tests.nix new file mode 100644 index 000000000000..bcc8e7b4ee3e --- /dev/null +++ b/pkgs/top-level/pkg-config/tests.nix @@ -0,0 +1,21 @@ +# cd nixpkgs +# nix-build -A tests.pkg-config +{ lib, stdenv, ... }: + +let + # defaultPkgConfigPackages test needs a Nixpkgs with allowUnsupportedPlatform + # in order to filter out the unsupported packages without throwing any errors + # tryEval would be too fragile, masking different problems as if they're + # unsupported platform problems. + allPkgs = import ../default.nix { + system = stdenv.hostPlatform.system; + localSystem = stdenv.hostPlatform.system; + config = { + allowUnsupportedSystem = true; + }; + overlays = []; + }; +in +lib.recurseIntoAttrs { + defaultPkgConfigPackages = allPkgs.callPackage ./test-defaultPkgConfigPackages.nix { }; +}