Merge pull request #114374 from oxalica/lib/platform-support-check

lib.meta: introduce `availableOn` to check package availability on given platform

authored by

Silvan Mosberger and committed by
GitHub
08d94fd2 088da873

+27 -15
+12
lib/meta.nix
··· 87 87 then { system = elem; } 88 88 else { parsed = elem; }; 89 89 in lib.matchAttrs pattern platform; 90 + 91 + /* Check if a package is available on a given platform. 92 + 93 + A package is available on a platform if both 94 + 95 + 1. One of `meta.platforms` pattern matches the given platform. 96 + 97 + 2. None of `meta.badPlatforms` pattern matches the given platform. 98 + */ 99 + availableOn = platform: pkg: 100 + lib.any (platformMatch platform) pkg.meta.platforms && 101 + lib.all (elem: !platformMatch platform elem) (pkg.meta.badPlatforms or []); 90 102 }
+1 -1
nixos/modules/system/boot/kexec.nix
··· 1 1 { pkgs, lib, ... }: 2 2 3 3 { 4 - config = lib.mkIf (lib.any (lib.meta.platformMatch pkgs.stdenv.hostPlatform) pkgs.kexectools.meta.platforms) { 4 + config = lib.mkIf (lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.kexectools) { 5 5 environment.systemPackages = [ pkgs.kexectools ]; 6 6 7 7 systemd.services.prepare-kexec =
+1 -1
pkgs/development/compilers/ghc/8.10.4.nix
··· 18 18 19 19 , # If enabled, GHC will be built with the GPL-free but slower integer-simple 20 20 # library instead of the faster but GPLed integer-gmp library. 21 - enableIntegerSimple ? !(lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp 21 + enableIntegerSimple ? !(lib.meta.availableOn stdenv.hostPlatform gmp), gmp 22 22 23 23 , # If enabled, use -fPIC when compiling static libs. 24 24 enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform
+1 -1
pkgs/development/compilers/ghc/8.8.4.nix
··· 18 18 19 19 , # If enabled, GHC will be built with the GPL-free but slower integer-simple 20 20 # library instead of the faster but GPLed integer-gmp library. 21 - enableIntegerSimple ? !(lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp 21 + enableIntegerSimple ? !(lib.meta.availableOn stdenv.hostPlatform gmp), gmp 22 22 23 23 , # If enabled, use -fPIC when compiling static libs. 24 24 enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform
+1 -1
pkgs/development/compilers/ghc/9.0.1.nix
··· 19 19 20 20 , # If enabled, GHC will be built with the GPL-free but slower integer-simple 21 21 # library instead of the faster but GPLed integer-gmp library. 22 - enableIntegerSimple ? !(lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp 22 + enableIntegerSimple ? !(lib.meta.availableOn stdenv.hostPlatform gmp), gmp 23 23 24 24 , # If enabled, use -fPIC when compiling static libs. 25 25 enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform
+1 -1
pkgs/development/compilers/ghc/head.nix
··· 22 22 23 23 , # If enabled, GHC will be built with the GPL-free but slightly slower native 24 24 # bignum backend instead of the faster but GPLed gmp backend. 25 - enableNativeBignum ? !(lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms) 25 + enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp) 26 26 , gmp 27 27 28 28 , # If enabled, use -fPIC when compiling static libs.
+1 -1
pkgs/development/libraries/wiredtiger/default.nix
··· 14 14 mkEnable = mkFlag "enable-" "disable-"; 15 15 mkWith = mkFlag "with-" "without-"; 16 16 17 - shouldUsePkg = pkg: if pkg != null && lib.any (lib.meta.platformMatch stdenv.hostPlatform) pkg.meta.platforms then pkg else null; 17 + shouldUsePkg = pkg: if pkg != null && lib.meta.availableOn stdenv.hostPlatform pkg then pkg else null; 18 18 19 19 optLz4 = shouldUsePkg lz4; 20 20 optSnappy = shouldUsePkg snappy;
+1 -1
pkgs/misc/jackaudio/default.nix
··· 15 15 with lib; 16 16 let 17 17 inherit (python3Packages) python dbus-python; 18 - shouldUsePkg = pkg: if pkg != null && lib.any (lib.meta.platformMatch stdenv.hostPlatform) pkg.meta.platforms then pkg else null; 18 + shouldUsePkg = pkg: if pkg != null && lib.meta.availableOn stdenv.hostPlatform pkg then pkg else null; 19 19 20 20 libOnly = prefix == "lib"; 21 21
+1 -1
pkgs/misc/jackaudio/jack1.nix
··· 5 5 }: 6 6 7 7 let 8 - shouldUsePkg = pkg: if pkg != null && lib.any (lib.meta.platformMatch stdenv.hostPlatform) pkg.meta.platforms then pkg else null; 8 + shouldUsePkg = pkg: if pkg != null && lib.meta.availableOn stdenv.hostPlatform pkg then pkg else null; 9 9 10 10 optAlsaLib = shouldUsePkg alsaLib; 11 11 optDb = shouldUsePkg db;
+2 -2
pkgs/os-specific/linux/apparmor/default.nix
··· 3 3 , flex, bison 4 4 , linuxHeaders ? stdenv.cc.libc.linuxHeaders 5 5 , gawk 6 - , withPerl ? stdenv.hostPlatform == stdenv.buildPlatform && lib.any (lib.meta.platformMatch stdenv.hostPlatform) perl.meta.platforms, perl 7 - , withPython ? stdenv.hostPlatform == stdenv.buildPlatform && lib.any (lib.meta.platformMatch stdenv.hostPlatform) python.meta.platforms, python 6 + , withPerl ? stdenv.hostPlatform == stdenv.buildPlatform && lib.meta.availableOn stdenv.hostPlatform perl, perl 7 + , withPython ? stdenv.hostPlatform == stdenv.buildPlatform && lib.meta.availableOn stdenv.hostPlatform python, python 8 8 , swig 9 9 , ncurses 10 10 , pam
+2 -2
pkgs/os-specific/linux/systemd/default.nix
··· 51 51 , iptables 52 52 , withSelinux ? false 53 53 , libselinux 54 - , withLibseccomp ? lib.any (lib.meta.platformMatch stdenv.hostPlatform) libseccomp.meta.platforms 54 + , withLibseccomp ? lib.meta.availableOn stdenv.hostPlatform libseccomp 55 55 , libseccomp 56 - , withKexectools ? lib.any (lib.meta.platformMatch stdenv.hostPlatform) kexectools.meta.platforms 56 + , withKexectools ? lib.meta.availableOn stdenv.hostPlatform kexectools 57 57 , kexectools 58 58 , bashInteractive 59 59 , libmicrohttpd
+1 -1
pkgs/servers/shishi/default.nix
··· 14 14 mkWith = mkFlag "with-" "without-"; 15 15 mkOther = mkFlag "" "" true; 16 16 17 - shouldUsePkg = pkg: if pkg != null && lib.any (lib.meta.platformMatch stdenv.hostPlatform) pkg.meta.platforms then pkg else null; 17 + shouldUsePkg = pkg: if pkg != null && lib.meta.availableOn stdenv.hostPlatform pkg then pkg else null; 18 18 19 19 optPam = shouldUsePkg pam; 20 20 optLibidn = shouldUsePkg libidn;
+1 -1
pkgs/tools/misc/tlp/default.nix
··· 88 88 systemd 89 89 util-linux 90 90 ] ++ lib.optional enableRDW networkmanager 91 - ++ lib.optional (lib.any (lib.meta.platformMatch stdenv.hostPlatform) x86_energy_perf_policy.meta.platforms) x86_energy_perf_policy 91 + ++ lib.optional (lib.meta.availableOn stdenv.hostPlatform x86_energy_perf_policy) x86_energy_perf_policy 92 92 ); 93 93 in 94 94 ''
+1 -1
pkgs/tools/package-management/nix/default.nix
··· 21 21 , storeDir 22 22 , stateDir 23 23 , confDir 24 - , withLibseccomp ? lib.any (lib.meta.platformMatch stdenv.hostPlatform) libseccomp.meta.platforms, libseccomp 24 + , withLibseccomp ? lib.meta.availableOn stdenv.hostPlatform libseccomp, libseccomp 25 25 , withAWS ? !enableStatic && (stdenv.isLinux || stdenv.isDarwin), aws-sdk-cpp 26 26 , enableStatic ? stdenv.hostPlatform.isStatic 27 27 , pname, version, suffix ? "", src