1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, pkg-config
6, python3
7, zlib
8, libssh2
9, openssl
10, pcre
11, http-parser
12, libiconv
13, Security
14, staticBuild ? stdenv.hostPlatform.isStatic
15# for passthru.tests
16, libgit2-glib
17, python3Packages
18, gitstatus
19}:
20
21stdenv.mkDerivation rec {
22 pname = "libgit2";
23 version = "1.7.2";
24 # also check the following packages for updates: python3Packages.pygit2 and libgit2-glib
25
26 outputs = ["lib" "dev" "out"];
27
28 src = fetchFromGitHub {
29 owner = "libgit2";
30 repo = "libgit2";
31 rev = "v${version}";
32 hash = "sha256-fVPY/byE2/rxmv/bUykcAbmUFMlF3UZogVuTzjOXJUU=";
33 };
34
35 cmakeFlags = [
36 "-DUSE_HTTP_PARSER=system"
37 "-DUSE_SSH=ON"
38 "-DBUILD_SHARED_LIBS=${if staticBuild then "OFF" else "ON"}"
39 ] ++ lib.optionals stdenv.hostPlatform.isWindows [
40 "-DDLLTOOL=${stdenv.cc.bintools.targetPrefix}dlltool"
41 # For ws2_32, refered to by a `*.pc` file
42 "-DCMAKE_LIBRARY_PATH=${stdenv.cc.libc}/lib"
43 ];
44
45 nativeBuildInputs = [ cmake python3 pkg-config ];
46
47 buildInputs = [ zlib libssh2 openssl pcre http-parser ]
48 ++ lib.optional stdenv.isDarwin Security;
49
50 propagatedBuildInputs = lib.optional (!stdenv.isLinux) libiconv;
51
52 doCheck = true;
53 checkPhase = ''
54 testArgs=(-v -xonline)
55
56 # slow
57 testArgs+=(-xclone::nonetwork::bad_urls)
58
59 # failed to set permissions on ...: Operation not permitted
60 testArgs+=(-xrepo::init::extended_1)
61 testArgs+=(-xrepo::template::extended_with_template_and_shared_mode)
62
63 (
64 set -x
65 ./libgit2_tests ''${testArgs[@]}
66 )
67 '';
68
69 passthru.tests = {
70 inherit libgit2-glib;
71 inherit (python3Packages) pygit2;
72 inherit gitstatus;
73 };
74
75 meta = with lib; {
76 description = "Linkable library implementation of Git that you can use in your application";
77 mainProgram = "git2";
78 homepage = "https://libgit2.org/";
79 license = licenses.gpl2Plus;
80 platforms = platforms.all;
81 maintainers = with maintainers; [ SuperSandro2000 ];
82 };
83}