summaryrefslogtreecommitdiff
path: root/pkgs/applications/editors/vim/plugins/non-generated/codesnap-nvim/default.nix
blob: cffd5943fabaa3b09ffa895be74463ebef90af9c (about) (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
63
64
65
66
67
68
69
{
  lib,
  stdenv,
  fetchFromGitHub,
  nix-update-script,
  pkg-config,
  rustPlatform,
  vimUtils,
  libuv,
}:
let
  version = "1.6.1";
  src = fetchFromGitHub {
    owner = "mistricky";
    repo = "codesnap.nvim";
    tag = "v${version}";
    hash = "sha256-OmSgrTYDtNb2plMyzjVvxGrfXB/lGKDpUQhpRqKfAMA=";
  };
  codesnap-lib = rustPlatform.buildRustPackage {
    pname = "codesnap-lib";
    inherit version src;

    sourceRoot = "${src.name}/generator";

    useFetchCargoVendor = true;
    cargoHash = "sha256-tg4BO4tPzHhJTowL7RiAuBo4i440FehpGmnz9stTxfI=";

    nativeBuildInputs = [
      pkg-config
      rustPlatform.bindgenHook
    ];

    buildInputs = [
      libuv.dev
    ];
  };
in
vimUtils.buildVimPlugin {
  pname = "codesnap.nvim";
  inherit version src;

  # - Remove the shipped pre-built binaries
  # - Copy the resulting binary from the codesnap-lib derivation
  # Note: the destination should be generator.so, even on darwin
  # https://github.com/mistricky/codesnap.nvim/blob/main/scripts/build_generator.sh
  postInstall =
    let
      extension = if stdenv.hostPlatform.isDarwin then "dylib" else "so";
    in
    ''
      rm -r $out/lua/*.so
      cp ${codesnap-lib}/lib/libgenerator.${extension} $out/lua/generator.so
    '';

  passthru = {
    updateScript = nix-update-script {
      attrPath = "vimPlugins.codesnap-nvim.codesnap-lib";
    };

    # needed for the update script
    inherit codesnap-lib;
  };

  meta = {
    homepage = "https://github.com/mistricky/codesnap.nvim/";
    changelog = "https://github.com/mistricky/codesnap.nvim/releases/tag/${src.tag}";
    license = lib.licenses.mit;
  };
}