nixpkgs/pkgs/development/tools/sumneko-lua-language-server/default.nix
Brian Leung 4571db9a88
sumneko-lua-language-server: disable cwd support only on x86-darwin
No reason that we shouldn't have it on aarch64-darwin.
2022-05-16 21:14:39 -07:00

90 lines
2.8 KiB
Nix

{ lib, stdenv, fetchFromGitHub, ninja, makeWrapper, darwin }:
let
target = if stdenv.isDarwin then "macOS" else "Linux";
in
stdenv.mkDerivation rec {
pname = "sumneko-lua-language-server";
version = "3.2.3";
src = fetchFromGitHub {
owner = "sumneko";
repo = "lua-language-server";
rev = version;
sha256 = "sha256-n54PWkiB+vXAqIOZ5FOTUNgGhAdBs81Q1WYxJ2XIb8o=";
fetchSubmodules = true;
};
nativeBuildInputs = [
ninja
makeWrapper
];
buildInputs = lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.Foundation
];
# Disable cwd support on x86 darwin, because it requires macOS>=10.15
preConfigure = lib.optionalString (stdenv.isDarwin && stdenv.isx86_64) ''
for file in 3rd/bee.lua/bee/subprocess/subprocess_posix.cpp 3rd/luamake/3rd/bee.lua/bee/subprocess/subprocess_posix.cpp; do
substituteInPlace $file --replace '#define USE_POSIX_SPAWN 1' ""
done
'';
preBuild = ''
cd 3rd/luamake
''
+ lib.optionalString stdenv.isDarwin ''
# Needed for the test
export HOME=/var/empty
# This package uses the program clang for C and C++ files. The language
# is selected via the command line argument -std, but this do not work
# in combination with the nixpkgs clang wrapper. Therefor we have to
# find all c++ compiler statements and replace $cc (which expands to
# clang) with clang++.
sed -i compile/ninja/macos.ninja \
-e '/c++/s,$cc,clang++,' \
-e '/test.lua/s,= .*,= true,' \
-e '/ldl/s,$cc,clang++,'
sed -i scripts/compiler/gcc.lua \
-e '/cxx_/s,$cc,clang++,'
'';
ninjaFlags = [
"-fcompile/ninja/${lib.toLower target}.ninja"
];
postBuild = ''
cd ../..
./3rd/luamake/luamake rebuild
'';
installPhase = ''
runHook preInstall
install -Dt "$out"/share/lua-language-server/bin bin/lua-language-server
install -m644 -t "$out"/share/lua-language-server/bin bin/*.*
install -m644 -t "$out"/share/lua-language-server {debugger,main}.lua
cp -r locale meta script "$out"/share/lua-language-server
# necessary for --version to work:
install -m644 -t "$out"/share/lua-language-server changelog.md
makeWrapper "$out"/share/lua-language-server/bin/lua-language-server \
$out/bin/lua-language-server \
--add-flags "-E $out/share/lua-language-server/main.lua \
--logpath='~/.cache/sumneko_lua/log' \
--metapath='~/.cache/sumneko_lua/meta'"
runHook postInstall
'';
meta = with lib; {
description = "Lua Language Server coded by Lua";
homepage = "https://github.com/sumneko/lua-language-server";
license = licenses.mit;
maintainers = with maintainers; [ sei40kr ];
platforms = platforms.linux ++ platforms.darwin;
mainProgram = "lua-language-server";
};
}