From c324705cc3ac228eeee1d72f4ee4ea46fc5e1283 Mon Sep 17 00:00:00 2001 From: Ryan Burns Date: Sun, 7 Jan 2024 17:43:33 -0800 Subject: [PATCH] treewide: simplify exec format conditionals --- pkgs/build-support/alternatives/blas/default.nix | 4 ++-- pkgs/build-support/alternatives/lapack/default.nix | 4 ++-- pkgs/development/compilers/rust/cargo.nix | 3 +-- pkgs/development/libraries/boost/generic.nix | 3 +-- pkgs/development/libraries/gstreamer/rs/default.nix | 2 +- pkgs/development/libraries/openssl/default.nix | 2 +- pkgs/development/libraries/quictls/default.nix | 2 +- pkgs/development/python-modules/glean-sdk/default.nix | 2 +- pkgs/development/tools/misc/binutils/2.38/default.nix | 8 ++------ pkgs/development/tools/misc/binutils/default.nix | 2 +- .../development/tools/misc/catppuccin-catwalk/default.nix | 3 +-- pkgs/stdenv/generic/default.nix | 2 +- pkgs/top-level/all-packages.nix | 5 +---- 13 files changed, 16 insertions(+), 26 deletions(-) diff --git a/pkgs/build-support/alternatives/blas/default.nix b/pkgs/build-support/alternatives/blas/default.nix index fec2d0526bb3..91001bc85377 100644 --- a/pkgs/build-support/alternatives/blas/default.nix +++ b/pkgs/build-support/alternatives/blas/default.nix @@ -80,7 +80,7 @@ stdenv.mkDerivation { cp -L "$libblas" $out/lib/libblas${canonicalExtension} chmod +w $out/lib/libblas${canonicalExtension} -'' + (if stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf" then '' +'' + (if stdenv.hostPlatform.isElf then '' patchelf --set-soname libblas${canonicalExtension} $out/lib/libblas${canonicalExtension} patchelf --set-rpath "$(patchelf --print-rpath $out/lib/libblas${canonicalExtension}):${lib.getLib blasProvider'}/lib" $out/lib/libblas${canonicalExtension} '' else lib.optionalString (stdenv.hostPlatform.isDarwin) '' @@ -112,7 +112,7 @@ EOF cp -L "$libcblas" $out/lib/libcblas${canonicalExtension} chmod +w $out/lib/libcblas${canonicalExtension} -'' + (if stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf" then '' +'' + (if stdenv.hostPlatform.isElf then '' patchelf --set-soname libcblas${canonicalExtension} $out/lib/libcblas${canonicalExtension} patchelf --set-rpath "$(patchelf --print-rpath $out/lib/libcblas${canonicalExtension}):${lib.getLib blasProvider'}/lib" $out/lib/libcblas${canonicalExtension} '' else lib.optionalString stdenv.hostPlatform.isDarwin '' diff --git a/pkgs/build-support/alternatives/lapack/default.nix b/pkgs/build-support/alternatives/lapack/default.nix index cbc7bf25c797..2d62855b258a 100644 --- a/pkgs/build-support/alternatives/lapack/default.nix +++ b/pkgs/build-support/alternatives/lapack/default.nix @@ -57,7 +57,7 @@ stdenv.mkDerivation { cp -L "$liblapack" $out/lib/liblapack${canonicalExtension} chmod +w $out/lib/liblapack${canonicalExtension} -'' + (lib.optionalString (stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf") '' +'' + (lib.optionalString stdenv.hostPlatform.isElf '' patchelf --set-soname liblapack${canonicalExtension} $out/lib/liblapack${canonicalExtension} patchelf --set-rpath "$(patchelf --print-rpath $out/lib/liblapack${canonicalExtension}):${lapackProvider'}/lib" $out/lib/liblapack${canonicalExtension} '') + '' @@ -86,7 +86,7 @@ EOF cp -L "$liblapacke" $out/lib/liblapacke${canonicalExtension} chmod +w $out/lib/liblapacke${canonicalExtension} -'' + (lib.optionalString (stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf") '' +'' + (lib.optionalString stdenv.hostPlatform.isElf '' patchelf --set-soname liblapacke${canonicalExtension} $out/lib/liblapacke${canonicalExtension} patchelf --set-rpath "$(patchelf --print-rpath $out/lib/liblapacke${canonicalExtension}):${lib.getLib lapackProvider'}/lib" $out/lib/liblapacke${canonicalExtension} '') + '' diff --git a/pkgs/development/compilers/rust/cargo.nix b/pkgs/development/compilers/rust/cargo.nix index ff0ecf45fd23..1377cfad6c6c 100644 --- a/pkgs/development/compilers/rust/cargo.nix +++ b/pkgs/development/compilers/rust/cargo.nix @@ -98,8 +98,7 @@ rustPlatform.buildRustPackage.override { # Disable check phase as there are failures (4 tests fail) doCheck = false; - doInstallCheck = !stdenv.hostPlatform.isStatic && - stdenv.hostPlatform.parsed.kernel.execFormat == lib.systems.parse.execFormats.elf; + doInstallCheck = !stdenv.hostPlatform.isStatic && stdenv.hostPlatform.isElf; installCheckPhase = '' runHook preInstallCheck readelf -a $out/bin/.cargo-wrapped | grep -F 'Shared library: [libcurl.so' diff --git a/pkgs/development/libraries/boost/generic.nix b/pkgs/development/libraries/boost/generic.nix index 080c944c90f5..ad67806398f9 100644 --- a/pkgs/development/libraries/boost/generic.nix +++ b/pkgs/development/libraries/boost/generic.nix @@ -73,8 +73,7 @@ let else if stdenv.hostPlatform.parsed.cpu.name == "s390x" then "s390x" else toString stdenv.hostPlatform.parsed.cpu.family}" # env in host triplet for Mach-O is "macho", but boost binary format for Mach-O is "mach-o" - "binary-format=${if stdenv.hostPlatform.parsed.kernel.execFormat == lib.systems.parse.execFormats.macho - then "mach-o" + "binary-format=${if stdenv.hostPlatform.isMacho then "mach-o" else toString stdenv.hostPlatform.parsed.kernel.execFormat.name}" "target-os=${toString stdenv.hostPlatform.parsed.kernel.name}" diff --git a/pkgs/development/libraries/gstreamer/rs/default.nix b/pkgs/development/libraries/gstreamer/rs/default.nix index ee467f965c81..708a735939af 100644 --- a/pkgs/development/libraries/gstreamer/rs/default.nix +++ b/pkgs/development/libraries/gstreamer/rs/default.nix @@ -234,7 +234,7 @@ stdenv.mkDerivation rec { ''; doInstallCheck = (lib.elem "webp" selectedPlugins) && !stdenv.hostPlatform.isStatic && - stdenv.hostPlatform.parsed.kernel.execFormat == lib.systems.parse.execFormats.elf; + stdenv.hostPlatform.isElf; installCheckPhase = '' runHook preInstallCheck readelf -a $out/lib/gstreamer-1.0/libgstrswebp.so | grep -F 'Shared library: [libwebpdemux.so' diff --git a/pkgs/development/libraries/openssl/default.nix b/pkgs/development/libraries/openssl/default.nix index a8e178c7e6d3..c7234c3da81e 100644 --- a/pkgs/development/libraries/openssl/default.nix +++ b/pkgs/development/libraries/openssl/default.nix @@ -93,7 +93,7 @@ let else if stdenv.hostPlatform.isBSD then if stdenv.hostPlatform.isx86_64 then "./Configure BSD-x86_64" else if stdenv.hostPlatform.isx86_32 - then "./Configure BSD-x86" + lib.optionalString (stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf") "-elf" + then "./Configure BSD-x86" + lib.optionalString stdenv.hostPlatform.isElf "-elf" else "./Configure BSD-generic${toString stdenv.hostPlatform.parsed.cpu.bits}" else if stdenv.hostPlatform.isMinGW then "./Configure mingw${lib.optionalString diff --git a/pkgs/development/libraries/quictls/default.nix b/pkgs/development/libraries/quictls/default.nix index ab53b5cc9b6b..110ecb4907e1 100644 --- a/pkgs/development/libraries/quictls/default.nix +++ b/pkgs/development/libraries/quictls/default.nix @@ -90,7 +90,7 @@ stdenv.mkDerivation (finalAttrs: { else if stdenv.hostPlatform.isBSD && stdenv.hostPlatform.isx86_64 then "./Configure BSD-x86_64" else if stdenv.hostPlatform.isBSD && stdenv.hostPlatform.isx86_32 - then "./Configure BSD-x86" + lib.optionalString (stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf") "-elf" + then "./Configure BSD-x86" + lib.optionalString stdenv.hostPlatform.isElf "-elf" else if stdenv.hostPlatform.isBSD then "./Configure BSD-generic${toString stdenv.hostPlatform.parsed.cpu.bits}" else if stdenv.hostPlatform.isMinGW diff --git a/pkgs/development/python-modules/glean-sdk/default.nix b/pkgs/development/python-modules/glean-sdk/default.nix index 54ea8c5f8ce0..83abb1089e30 100644 --- a/pkgs/development/python-modules/glean-sdk/default.nix +++ b/pkgs/development/python-modules/glean-sdk/default.nix @@ -66,7 +66,7 @@ buildPythonPackage rec { "test_flipping_upload_enabled_respects_order_of_events" ]; - postInstallCheck = lib.optionalString (stdenv.hostPlatform.parsed.kernel.execFormat == lib.systems.parse.execFormats.elf) '' + postInstallCheck = lib.optionalString stdenv.hostPlatform.isElf '' readelf -a $out/${python.sitePackages}/glean/libglean_ffi.so | grep -F 'Shared library: [liblmdb.so' ''; diff --git a/pkgs/development/tools/misc/binutils/2.38/default.nix b/pkgs/development/tools/misc/binutils/2.38/default.nix index 1194cbeb2453..fd9a3277532e 100644 --- a/pkgs/development/tools/misc/binutils/2.38/default.nix +++ b/pkgs/development/tools/misc/binutils/2.38/default.nix @@ -1,7 +1,3 @@ -let - execFormatIsELF = platform: platform.parsed.kernel.execFormat.name == "elf"; -in - { stdenv , autoreconfHook , autoconf269, automake, libtool @@ -18,7 +14,7 @@ in , texinfo , zlib -, enableGold ? execFormatIsELF stdenv.targetPlatform +, enableGold ? stdenv.targetPlatform.isElf , enableShared ? !stdenv.hostPlatform.isStatic # WARN: Enabling all targets increases output size to a multiple. , withAllTargets ? false @@ -26,7 +22,7 @@ in # WARN: configure silently disables ld.gold if it's unsupported, so we need to # make sure that intent matches result ourselves. -assert enableGold -> execFormatIsELF stdenv.targetPlatform; +assert enableGold -> stdenv.targetPlatform.isElf; let diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix index fe9ec6a865f9..2183d45b6f0d 100644 --- a/pkgs/development/tools/misc/binutils/default.nix +++ b/pkgs/development/tools/misc/binutils/default.nix @@ -1,5 +1,5 @@ let - withGold = platform: platform.parsed.kernel.execFormat.name == "elf" && !platform.isRiscV && !platform.isLoongArch64; + withGold = platform: platform.isElf && !platform.isRiscV && !platform.isLoongArch64; in { stdenv diff --git a/pkgs/development/tools/misc/catppuccin-catwalk/default.nix b/pkgs/development/tools/misc/catppuccin-catwalk/default.nix index 2abf3823269b..848ead3d7ed4 100644 --- a/pkgs/development/tools/misc/catppuccin-catwalk/default.nix +++ b/pkgs/development/tools/misc/catppuccin-catwalk/default.nix @@ -31,8 +31,7 @@ rustPlatform.buildRustPackage { --fish <("$out/bin/catwalk" completion fish) ''; - doInstallCheck = !stdenv.hostPlatform.isStatic && - stdenv.hostPlatform.parsed.kernel.execFormat == lib.systems.parse.execFormats.elf; + doInstallCheck = !stdenv.hostPlatform.isStatic && stdenv.hostPlatform.isElf; installCheckPhase = '' runHook preInstallCheck readelf -a $out/bin/catwalk | grep -F 'Shared library: [libwebp.so' diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index cf194be92bd7..e764571869db 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -109,7 +109,7 @@ let # there (yet?) so it goes here until then. preHook = preHook + lib.optionalString buildPlatform.isDarwin '' export NIX_DONT_SET_RPATH_FOR_BUILD=1 - '' + lib.optionalString (hostPlatform.isDarwin || (hostPlatform.parsed.kernel.execFormat != lib.systems.parse.execFormats.elf && hostPlatform.parsed.kernel.execFormat != lib.systems.parse.execFormats.macho)) '' + '' + lib.optionalString (hostPlatform.isDarwin || (!hostPlatform.isElf && !hostPlatform.isMacho)) '' export NIX_DONT_SET_RPATH=1 export NIX_NO_SELF_RPATH=1 '' + lib.optionalString (hostPlatform.isDarwin && hostPlatform.isMacOS) '' diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 75130bb4d03c..68c00c38db30 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -21575,10 +21575,7 @@ with pkgs; mtrace = callPackage ../development/libraries/glibc/mtrace.nix { }; # Provided by libc on Operating Systems that use the Extensible Linker Format. - elf-header = - if stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf" - then null - else elf-header-real; + elf-header = if stdenv.hostPlatform.isElf then null else elf-header-real; elf-header-real = callPackage ../development/libraries/elf-header { };