1{
2 lib,
3 stdenv,
4 fetchpatch,
5 callPackage,
6 swift,
7 swiftpm,
8 swiftpm2nix,
9 Foundation,
10}:
11let
12 sources = callPackage ../sources.nix { };
13 generated = swiftpm2nix.helpers ./generated;
14in
15stdenv.mkDerivation {
16 pname = "swift-format";
17
18 inherit (sources) version;
19 src = sources.swift-format;
20
21 nativeBuildInputs = [
22 swift
23 swiftpm
24 ];
25 buildInputs = [ Foundation ];
26
27 configurePhase = generated.configure + ''
28 swiftpmMakeMutable swift-tools-support-core
29 patch -p1 -d .build/checkouts/swift-tools-support-core -i ${
30 fetchpatch {
31 url = "https://github.com/apple/swift-tools-support-core/commit/990afca47e75cce136d2f59e464577e68a164035.patch";
32 hash = "sha256-PLzWsp+syiUBHhEFS8+WyUcSae5p0Lhk7SSRdNvfouE=";
33 includes = [ "Sources/TSCBasic/FileSystem.swift" ];
34 }
35 }
36 '';
37
38 # We only install the swift-format binary, so don't need the other products.
39 swiftpmFlags = [ "--product swift-format" ];
40
41 installPhase = ''
42 binPath="$(swiftpmBinPath)"
43 mkdir -p $out/bin
44 cp $binPath/swift-format $out/bin/
45 '';
46
47 meta = {
48 description = "Formatting technology for Swift source code";
49 homepage = "https://github.com/apple/swift-format";
50 platforms = with lib.platforms; linux ++ darwin;
51 license = lib.licenses.asl20;
52 teams = [ lib.teams.swift ];
53 mainProgram = "swift-format";
54 };
55}