nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib
2, stdenv
3, callPackage
4, pkg-config
5, swift
6, swiftpm
7, swiftpm2nix
8, Foundation
9, XCTest
10, sqlite
11, ncurses
12, CryptoKit
13, LocalAuthentication
14}:
15let
16 sources = callPackage ../sources.nix { };
17 generated = swiftpm2nix.helpers ./generated;
18
19 # On Darwin, we only want ncurses in the linker search path, because headers
20 # are part of libsystem. Adding its headers to the search path causes strange
21 # mixing and errors.
22 # TODO: Find a better way to prevent this conflict.
23 ncursesInput = if stdenv.isDarwin then ncurses.out else ncurses;
24in
25stdenv.mkDerivation {
26 pname = "sourcekit-lsp";
27
28 inherit (sources) version;
29 src = sources.sourcekit-lsp;
30
31 nativeBuildInputs = [ pkg-config swift swiftpm ];
32 buildInputs = [
33 Foundation
34 XCTest
35 sqlite
36 ncursesInput
37 ] ++ lib.optionals stdenv.isDarwin [ CryptoKit LocalAuthentication ];
38
39 configurePhase = generated.configure + ''
40 swiftpmMakeMutable indexstore-db
41 patch -p1 -d .build/checkouts/indexstore-db -i ${./patches/indexstore-db-macos-target.patch}
42
43 # This toggles a section specific to Xcode XCTest, which doesn't work on
44 # Darwin, where we also use swift-corelibs-xctest.
45 substituteInPlace Sources/LSPTestSupport/PerfTestCase.swift \
46 --replace '#if os(macOS)' '#if false'
47
48 # Required to link with swift-corelibs-xctest on Darwin.
49 export SWIFTTSC_MACOS_DEPLOYMENT_TARGET=10.12
50 '';
51
52 # TODO: BuildServerBuildSystemTests fails
53 #doCheck = true;
54
55 installPhase = ''
56 binPath="$(swiftpmBinPath)"
57 mkdir -p $out/bin
58 cp $binPath/sourcekit-lsp $out/bin/
59 '';
60
61 # Canary to verify output of our Swift toolchain does not depend on the Swift
62 # compiler itself. (Only its 'lib' output.)
63 disallowedRequisites = [ swift.swift ];
64
65 meta = {
66 description = "Language Server Protocol implementation for Swift and C-based languages";
67 homepage = "https://github.com/apple/sourcekit-lsp";
68 platforms = with lib.platforms; linux ++ darwin;
69 license = lib.licenses.asl20;
70 maintainers = with lib.maintainers; [ dtzWill trepetti dduan trundle stephank ];
71 };
72}