1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchpatch,
6 cmake,
7 pkg-config,
8 python3,
9 zlib,
10 libssh2,
11 openssl,
12 pcre2,
13 libiconv,
14 staticBuild ? stdenv.hostPlatform.isStatic,
15 # for passthru.tests
16 libgit2-glib,
17 python3Packages,
18 gitstatus,
19 llhttp,
20 withGssapi ? false,
21 krb5,
22}:
23
24stdenv.mkDerivation (finalAttrs: {
25 pname = "libgit2";
26 version = "1.9.1";
27 # also check the following packages for updates: python3Packages.pygit2 and libgit2-glib
28
29 outputs = [
30 "lib"
31 "dev"
32 "out"
33 ];
34
35 src = fetchFromGitHub {
36 owner = "libgit2";
37 repo = "libgit2";
38 rev = "v${finalAttrs.version}";
39 hash = "sha256-/xI3v7LNhpgfjv/m+sZwYDhhYvS6kQYxiiiG3+EF8Mw=";
40 };
41
42 cmakeFlags = [
43 "-DREGEX_BACKEND=pcre2"
44 "-DUSE_HTTP_PARSER=llhttp"
45 "-DUSE_SSH=ON"
46 (lib.cmakeBool "USE_GSSAPI" withGssapi)
47 "-DBUILD_SHARED_LIBS=${if staticBuild then "OFF" else "ON"}"
48 ]
49 ++ lib.optionals stdenv.hostPlatform.isWindows [
50 "-DDLLTOOL=${stdenv.cc.bintools.targetPrefix}dlltool"
51 # For ws2_32, referred to by a `*.pc` file
52 "-DCMAKE_LIBRARY_PATH=${stdenv.cc.libc}/lib"
53 ]
54 ++ lib.optionals stdenv.hostPlatform.isOpenBSD [
55 # openbsd headers fail with default c90
56 "-DCMAKE_C_STANDARD=99"
57 ];
58
59 nativeBuildInputs = [
60 cmake
61 python3
62 pkg-config
63 ];
64
65 buildInputs = [
66 zlib
67 libssh2
68 openssl
69 pcre2
70 llhttp
71 ]
72 ++ lib.optional withGssapi krb5;
73
74 propagatedBuildInputs = lib.optional (!stdenv.hostPlatform.isLinux) libiconv;
75
76 doCheck = true;
77 checkPhase = ''
78 testArgs=(-v -xonline)
79
80 # slow
81 testArgs+=(-xclone::nonetwork::bad_urls)
82
83 # failed to set permissions on ...: Operation not permitted
84 testArgs+=(-xrepo::init::extended_1)
85 testArgs+=(-xrepo::template::extended_with_template_and_shared_mode)
86
87 (
88 set -x
89 ./libgit2_tests ''${testArgs[@]}
90 )
91 '';
92
93 passthru.tests = lib.mapAttrs (_: v: v.override { libgit2 = finalAttrs.finalPackage; }) {
94 inherit libgit2-glib;
95 inherit (python3Packages) pygit2;
96 inherit gitstatus;
97 };
98
99 meta = with lib; {
100 description = "Linkable library implementation of Git that you can use in your application";
101 mainProgram = "git2";
102 homepage = "https://libgit2.org/";
103 license = licenses.gpl2Only;
104 platforms = platforms.all;
105 maintainers = with maintainers; [ SuperSandro2000 ];
106 };
107})