mirror of
https://github.com/NixOS/nixpkgs
synced 2024-10-19 03:47:13 -04:00
e0464e4788
In preparation for the deprecation of `stdenv.isX`. These shorthands are not conducive to cross-compilation because they hide the platforms. Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way One example of why this is bad and especially affects compiler packages https://www.github.com/NixOS/nixpkgs/pull/343059 There are too many files to go through manually but a treewide should get users thinking when they see a `hostPlatform.isX` in a place where it doesn't make sense. ``` fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is" fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is" ```
53 lines
1.7 KiB
Nix
53 lines
1.7 KiB
Nix
{ lib,
|
|
stdenv,
|
|
writeShellScriptBin }:
|
|
{ versions ? [ ] , xcodeBaseDir ? "/Applications/Xcode.app" }:
|
|
|
|
assert stdenv.hostPlatform.isDarwin;
|
|
let
|
|
xcodebuildPath = "${xcodeBaseDir}/Contents/Developer/usr/bin/xcodebuild";
|
|
|
|
xcodebuildWrapper = writeShellScriptBin "xcodebuild" ''
|
|
currentVer="$(${xcodebuildPath} -version | awk 'NR==1{print $2}')"
|
|
wrapperVers=(${lib.concatStringsSep " " versions})
|
|
|
|
for ver in "''${wrapperVers[@]}"; do
|
|
if [[ "$currentVer" == "$ver" ]]; then
|
|
# here exec replaces the shell without creating a new process
|
|
# https://www.gnu.org/software/bash/manual/bash.html#index-exec
|
|
exec "${xcodebuildPath}" "$@"
|
|
fi
|
|
done
|
|
|
|
echo "The installed Xcode version ($currentVer) does not match any of the allowed versions: ${lib.concatStringsSep ", " versions}"
|
|
echo "Please update your local Xcode installation to match one of the allowed versions"
|
|
exit 1
|
|
'';
|
|
in
|
|
stdenv.mkDerivation {
|
|
name = "xcode-wrapper-impure";
|
|
# Fails in sandbox. Use `--option sandbox relaxed` or `--option sandbox false`.
|
|
__noChroot = true;
|
|
buildCommand = ''
|
|
mkdir -p $out/bin
|
|
cd $out/bin
|
|
${if versions == [ ] then ''
|
|
ln -s "${xcodebuildPath}"
|
|
'' else ''
|
|
ln -s "${xcodebuildWrapper}/bin/xcode-select"
|
|
''}
|
|
ln -s /usr/bin/security
|
|
ln -s /usr/bin/codesign
|
|
ln -s /usr/bin/xcrun
|
|
ln -s /usr/bin/plutil
|
|
ln -s /usr/bin/clang
|
|
ln -s /usr/bin/lipo
|
|
ln -s /usr/bin/file
|
|
ln -s /usr/bin/rev
|
|
ln -s "${xcodeBaseDir}/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator"
|
|
|
|
cd ..
|
|
ln -s "${xcodeBaseDir}/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs"
|
|
'';
|
|
}
|