24 # Avoid a circular dependency on Linux systems (systemd depends on tpm2-tss,
25 # tpm2-tss tests depend on procps, procps depends on systemd by default). This
26 # needs to be conditional based on isLinux because procps for other systems
27 # might not support the withSystemd option.
28 procpsWithoutSystemd = procps.override { withSystemd = false; };
29 procps_pkg = if stdenv.hostPlatform.isLinux then procpsWithoutSystemd else procps;
32 stdenv.mkDerivation rec {
36 src = fetchFromGitHub {
37 owner = "tpm2-software";
40 hash = "sha256-BP28utEUI9g1VNv3lCXuiKrDtEImFQxxZfIjLiE3Wr8=";
67 # cmocka is checked in the configure script
68 # when unit and/or integration testing is enabled
69 # cmocka doesn't build with pkgsStatic, and we don't need it anyway
70 # when tests are not run
71 ++ lib.optional doInstallCheck cmocka;
73 nativeInstallCheckInputs = lib.optionals doInstallCheck [
83 preAutoreconf = "./bootstrap";
85 enableParallelBuilding = true;
88 # Do not rely on dynamic loader path
89 # TCTI loader relies on dlopen(), this patch prefixes all calls with the output directory
90 ./no-dynamic-loader-path.patch
92 # Configure script expects tools from shadow (e.g. useradd) but they are
93 # actually optional (and we can’t use them in Nix sandbox anyway). Make the
94 # check in configure.ac a warning instead of an error so that we can run
95 # configure phase on platforms that don’t have shadow package (e.g. macOS).
96 # Note that *on platforms* does not mean *for platform* i.e. this is for
97 # cross-compilation, tpm2-tss does not support macOS, see upstream issue:
98 # https://github.com/tpm2-software/tpm2-tss/issues/2629
100 # https://github.com/tpm2-software/tpm2-tss/blob/6c46325b466f35d40c2ed1043bfdfcfb8a367a34/Makefile.am#L880-L898
107 substituteInPlace src/tss2-tcti/tctildr-dl.c \
108 --replace-fail '@PREFIX@' $out/lib/
109 substituteInPlace ./test/unit/tctildr-dl.c \
110 --replace-fail '@PREFIX@' $out/lib/
111 substituteInPlace ./bootstrap \
112 --replace-fail 'git describe --tags --always --dirty' 'echo "${version}"'
113 for src in src/tss2-tcti/tcti-libtpms.c test/unit/tcti-libtpms.c; do
114 substituteInPlace "$src" \
115 --replace-fail '"libtpms.so"' '"${libtpms.out}/lib/libtpms.so"' \
116 --replace-fail '"libtpms.so.0"' '"${libtpms.out}/lib/libtpms.so.0"'
119 # tcti tests rely on mocking function calls, which appears not to be supported
121 + lib.optionalString stdenv.cc.isClang ''
122 sed -i '/TESTS_UNIT / {
123 /test\/unit\/tcti-swtpm/d;
124 /test\/unit\/tcti-mssim/d;
125 /test\/unit\/tcti-device/d
130 lib.optionals doInstallCheck [
132 "--enable-integration"
134 ++ lib.optionals stdenv.hostPlatform.isDarwin [
135 # sys/prctl.h required
143 # Do not install the upstream udev rules, they rely on specific
144 # users/groups which aren't guaranteed to exist on the system.
150 stdenv.buildPlatform.canExecute stdenv.hostPlatform
151 && !stdenv.hostPlatform.isDarwin
152 # Tests rely on mocking, which can't work with static libs.
153 && !stdenv.hostPlatform.isStatic;
154 # Since we rewrote the load path in the dynamic loader for the TCTI
155 # The various tcti implementation should be placed in their target directory
156 # before we could run tests, so we make turn checkPhase into installCheckPhase
157 installCheckTarget = "check";
160 description = "OSS implementation of the TCG TPM2 Software Stack (TSS2)";
161 homepage = "https://github.com/tpm2-software/tpm2-tss";
162 license = licenses.bsd2;
163 platforms = platforms.unix;
164 maintainers = with maintainers; [ baloo ];