Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 6 # nativeBuildInputs 7 ninja, 8 makeWrapper, 9 10 # buildInputs 11 fmt, 12 rsync, 13 14 versionCheckHook, 15 nix-update-script, 16}: 17 18stdenv.mkDerivation (finalAttrs: { 19 pname = "lua-language-server"; 20 version = "3.15.0"; 21 22 src = fetchFromGitHub { 23 owner = "luals"; 24 repo = "lua-language-server"; 25 tag = finalAttrs.version; 26 hash = "sha256-frsq5OA3giLOJ/KPcAqVhme+0CtJuZrS3F4zHN1PnFM="; 27 fetchSubmodules = true; 28 }; 29 30 nativeBuildInputs = [ 31 ninja 32 makeWrapper 33 ]; 34 35 buildInputs = [ 36 fmt 37 ] 38 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 39 rsync 40 ]; 41 42 env.NIX_LDFLAGS = "-lfmt"; 43 44 postPatch = '' 45 # filewatch tests are failing on darwin 46 # this feature is not used in lua-language-server 47 substituteInPlace 3rd/bee.lua/test/test.lua \ 48 --replace-fail 'require "test_filewatch"' "" 49 50 # use nixpkgs fmt library 51 for d in 3rd/bee.lua 3rd/luamake/bee.lua 52 do 53 rm -r $d/3rd/fmt/* 54 touch $d/3rd/fmt/format.cc 55 substituteInPlace $d/bee/nonstd/format.h $d/bee/nonstd/print.h \ 56 --replace-fail "include <3rd/fmt/fmt" "include <fmt" 57 done 58 59 # flaky tests on linux 60 # https://github.com/LuaLS/lua-language-server/issues/2926 61 substituteInPlace test/tclient/init.lua \ 62 --replace-fail "require 'tclient.tests.load-relative-library'" "" 63 64 pushd 3rd/luamake 65 '' 66 + lib.optionalString stdenv.hostPlatform.isDarwin ( 67 # This package uses the program clang for C and C++ files. The language 68 # is selected via the command line argument -std, but this do not work 69 # in combination with the nixpkgs clang wrapper. Therefor we have to 70 # find all c++ compiler statements and replace $cc (which expands to 71 # clang) with clang++. 72 '' 73 sed -i compile/ninja/macos.ninja \ 74 -e '/c++/s,$cc,clang++,' \ 75 -e '/test.lua/s,= .*,= true,' \ 76 -e '/ldl/s,$cc,clang++,' 77 sed -i scripts/compiler/gcc.lua \ 78 -e '/cxx_/s,$cc,clang++,' 79 '' 80 # Avoid relying on ditto (impure) 81 + '' 82 substituteInPlace compile/ninja/macos.ninja \ 83 --replace-fail "ditto" "rsync -a" 84 85 substituteInPlace scripts/writer.lua \ 86 --replace-fail "ditto" "rsync -a" 87 '' 88 ); 89 90 ninjaFlags = [ 91 "-fcompile/ninja/${if stdenv.hostPlatform.isDarwin then "macos" else "linux"}.ninja" 92 ]; 93 94 postBuild = '' 95 popd 96 ./3rd/luamake/luamake rebuild 97 ''; 98 99 installPhase = '' 100 runHook preInstall 101 102 install -Dt "$out"/share/lua-language-server/bin bin/lua-language-server 103 install -m644 -t "$out"/share/lua-language-server/bin bin/*.* 104 install -m644 -t "$out"/share/lua-language-server {debugger,main}.lua 105 cp -r locale meta script "$out"/share/lua-language-server 106 107 # necessary for --version to work: 108 install -m644 -t "$out"/share/lua-language-server changelog.md 109 110 makeWrapper "$out"/share/lua-language-server/bin/lua-language-server \ 111 $out/bin/lua-language-server \ 112 --add-flags "-E $out/share/lua-language-server/main.lua \ 113 --logpath=\''${XDG_CACHE_HOME:-\$HOME/.cache}/lua-language-server/log \ 114 --metapath=\''${XDG_CACHE_HOME:-\$HOME/.cache}/lua-language-server/meta" 115 116 runHook postInstall 117 ''; 118 119 # some tests require local networking 120 __darwinAllowLocalNetworking = true; 121 122 nativeInstallCheckInputs = [ 123 versionCheckHook 124 ]; 125 versionCheckProgramArg = "--version"; 126 doInstallCheck = true; 127 128 passthru.updateScript = nix-update-script { }; 129 130 meta = { 131 description = "Language server that offers Lua language support"; 132 homepage = "https://github.com/luals/lua-language-server"; 133 changelog = "https://github.com/LuaLS/lua-language-server/blob/${finalAttrs.version}/changelog.md"; 134 license = lib.licenses.mit; 135 maintainers = with lib.maintainers; [ 136 figsoda 137 gepbird 138 sei40kr 139 ]; 140 mainProgram = "lua-language-server"; 141 platforms = lib.platforms.linux ++ lib.platforms.darwin; 142 }; 143})