From 471c61218e94c1a264a5bb0a9762e97dd98fca3d Mon Sep 17 00:00:00 2001 From: Spotlight Date: Sat, 22 Jul 2023 20:47:53 -0500 Subject: [PATCH] Include pure Swift version of swiftformat This should probably be upstreamed... eventually. --- home/desktop.nix | 1 + pkgs/default.nix | 1 + pkgs/swiftformat.nix | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 pkgs/swiftformat.nix diff --git a/home/desktop.nix b/home/desktop.nix index 099cafe..c0af69c 100644 --- a/home/desktop.nix +++ b/home/desktop.nix @@ -33,6 +33,7 @@ pwgen radare2 rustup + swiftformat tmux unar virt-manager diff --git a/pkgs/default.nix b/pkgs/default.nix index fa69c60..32ce3ef 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,4 +1,5 @@ self: super: { monaco-powerline = super.callPackage ./monaco-powerline/default.nix {}; + swiftformat = super.callPackage ./swiftformat.nix {}; } diff --git a/pkgs/swiftformat.nix b/pkgs/swiftformat.nix new file mode 100644 index 0000000..258153a --- /dev/null +++ b/pkgs/swiftformat.nix @@ -0,0 +1,39 @@ +{ stdenv, lib, fetchFromGitHub, swift, swiftpm, swiftPackages }: + +# This derivation is impure: it relies on an Xcode toolchain being installed +# and available in the expected place. The values of sandboxProfile and +# hydraPlatforms are copied pretty directly from the MacVim derivation, which +# is also impure. + +stdenv.mkDerivation rec { + pname = "swiftformat"; + version = "0.51.13"; + + src = fetchFromGitHub { + owner = "nicklockwood"; + repo = "SwiftFormat"; + rev = version; + sha256 = "sha256-8AvPA8KzejU4BI/BAX+gCjwPi4Xv0jEQbLHj9OCtasw"; + }; + + nativeBuildInputs = [ swift swiftpm ]; + buildInputs = [ swiftPackages.Foundation ]; + + # We only install the swiftformat binary, so don't need the other products. + swiftpmFlags = [ "--product swiftformat" ]; + + installPhase = '' + binPath="$(swiftpmBinPath)" + mkdir -p $out/bin + cp $binPath/swiftformat $out/bin/ + ''; + + meta = with lib; { + description = "A code formatting and linting tool for Swift"; + homepage = "https://github.com/nicklockwood/SwiftFormat"; + license = licenses.mit; + maintainers = [ maintainers.bdesham ]; + platforms = with lib.platforms; linux ++ darwin; + hydraPlatforms = []; + }; +} \ No newline at end of file