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