summaryrefslogtreecommitdiff
path: root/pkgs/development/compilers/swift/swift-format/default.nix
blob: adb76e7a359a92a1fe072221d58f9cf00976aaa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{
  lib,
  stdenv,
  callPackage,
  swift,
  swiftpm,
  swiftpm2nix,
  installShellFiles,
  Dispatch,
  Foundation,
}:
let
  sources = callPackage ../sources.nix { };
  generated = swiftpm2nix.helpers ./generated;
in
stdenv.mkDerivation {
  pname = "swift-format";

  inherit (sources) version;
  src = sources.swift-format;

  nativeBuildInputs = [
    swift
    swiftpm
    installShellFiles
  ];
  buildInputs = [ Foundation ];

  env.LD_LIBRARY_PATH = lib.optionalString stdenv.hostPlatform.isLinux (
    lib.makeLibraryPath [ Dispatch ]
  );

  configurePhase = generated.configure;

  # We only install the swift-format binary, so don't need the other products.
  swiftpmFlags = [ "--product swift-format" ];

  installPhase = ''
    binPath="$(swiftpmBinPath)"
    mkdir -p $out/bin
    cp $binPath/swift-format $out/bin/

    # Generate shell completions
    for shell in bash zsh fish; do
      $out/bin/swift-format --generate-completion-script $shell > swift-format.$shell
    done

    installShellCompletion --cmd swift-format \
      --bash swift-format.bash \
      --zsh swift-format.zsh \
      --fish swift-format.fish
  '';

  meta = {
    description = "Formatting technology for Swift source code";
    homepage = "https://github.com/apple/swift-format";
    platforms = with lib.platforms; linux ++ darwin;
    license = lib.licenses.asl20;
    teams = [ lib.teams.swift ];
    mainProgram = "swift-format";
  };
}