1{ lib
2, stdenv
3, fetchFromGitHub
4, fetchpatch
5, cmake
6, cmocka
7
8# for passthru.tests
9, libfido2
10, mysql80
11, openssh
12, systemd
13}:
14
15stdenv.mkDerivation (finalAttrs: {
16 pname = "libcbor";
17 version = "unstable-2023-01-29"; # Musl fix hasn't been released yet.
18
19 src = fetchFromGitHub {
20 owner = "PJK";
21 repo = "libcbor";
22 rev = "cb4162f40d94751141b4d43b07c4add83e738a68";
23 sha256 = "sha256-ZTa+wG1g9KsVoqJG/yqxo2fJ7OhPnaI9QcfOmpOT3pg=";
24 };
25
26 outputs = [ "out" "dev" ];
27
28 patches = [
29 # Pull fix pending upstream inclusion to support
30 # `CMAKE_INSTALL_INCLUDEDIR`:
31 # https://github.com/PJK/libcbor/pull/297
32 (fetchpatch {
33 name = "includedir.patch";
34 url = "https://github.com/PJK/libcbor/commit/d00a63e6d6858a2ed6be9b431b42799ed2c99ad8.patch";
35 hash = "sha256-kBCSbAHOCGOs/4Yu6Vh0jcmzA/jYPkkPXPGPrptRfyk=";
36 })
37 ];
38
39 strictDeps = true;
40 nativeBuildInputs = [ cmake ];
41
42 buildInputs = [
43 cmocka # cmake expects cmocka module
44 ];
45
46 cmakeFlags = lib.optional finalAttrs.doCheck "-DWITH_TESTS=ON"
47 ++ lib.optional (!stdenv.hostPlatform.isStatic) "-DBUILD_SHARED_LIBS=ON";
48
49 # Tests are restricted while pkgsStatic.cmocka is broken. Tracked at:
50 # https://github.com/NixOS/nixpkgs/issues/213623
51 doCheck = !stdenv.hostPlatform.isStatic
52 && stdenv.hostPlatform == stdenv.buildPlatform;
53
54 nativeCheckInputs = [ cmocka ];
55
56 passthru.tests = {
57 inherit libfido2 mysql80;
58 openssh = (openssh.override { withFIDO = true; });
59 systemd = (systemd.override {
60 withFido2 = true;
61 withCryptsetup = true;
62 });
63 };
64
65 meta = with lib; {
66 description = "CBOR protocol implementation for C and others";
67 homepage = "https://github.com/PJK/libcbor";
68 license = licenses.mit;
69 maintainers = with maintainers; [ dtzWill ];
70 };
71})