2021-02-17 03:59:57 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2021-09-15 17:36:31 +00:00
|
|
|
, fetchFromGitHub
|
2021-02-17 03:59:57 +00:00
|
|
|
, autoreconfHook
|
|
|
|
, pkg-config
|
2021-09-14 16:23:28 +00:00
|
|
|
, libtasn1, openssl, fuse, glib, libseccomp, json-glib
|
2021-02-17 03:59:57 +00:00
|
|
|
, libtpms
|
|
|
|
, unixtools, expect, socat
|
|
|
|
, gnutls
|
|
|
|
, perl
|
2021-09-15 17:36:31 +00:00
|
|
|
|
|
|
|
# Tests
|
|
|
|
, python3, which
|
2022-02-20 11:56:45 +00:00
|
|
|
, nixosTests
|
2021-02-17 03:59:57 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "swtpm";
|
2022-03-10 22:15:24 +00:00
|
|
|
version = "0.7.2";
|
2021-02-17 03:59:57 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "stefanberger";
|
|
|
|
repo = "swtpm";
|
|
|
|
rev = "v${version}";
|
2022-03-10 22:15:24 +00:00
|
|
|
sha256 = "sha256-qeyPCJTNnwuaCosHzqnrQc0JNznGBfDTLsuDmuKREjU=";
|
2021-02-17 03:59:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config unixtools.netstat expect socat
|
|
|
|
perl # for pod2man
|
2022-03-10 14:34:40 +00:00
|
|
|
python3
|
2021-02-17 03:59:57 +00:00
|
|
|
autoreconfHook
|
|
|
|
];
|
2021-11-11 17:14:39 +00:00
|
|
|
|
2021-09-15 17:36:31 +00:00
|
|
|
checkInputs = [
|
2022-03-10 14:34:40 +00:00
|
|
|
which
|
2021-09-15 17:36:31 +00:00
|
|
|
];
|
|
|
|
|
2021-02-17 03:59:57 +00:00
|
|
|
buildInputs = [
|
|
|
|
libtpms
|
2022-03-10 14:34:40 +00:00
|
|
|
openssl libtasn1
|
|
|
|
glib json-glib
|
2021-02-17 03:59:57 +00:00
|
|
|
gnutls
|
2022-03-10 14:34:40 +00:00
|
|
|
] ++ lib.optionals stdenv.isLinux [
|
|
|
|
fuse
|
|
|
|
libseccomp
|
2021-02-17 03:59:57 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
configureFlags = [
|
2021-10-15 13:37:12 +00:00
|
|
|
"--localstatedir=/var"
|
2022-03-10 14:34:40 +00:00
|
|
|
] ++ lib.optionals stdenv.isLinux [
|
|
|
|
"--with-cuse"
|
2021-02-17 03:59:57 +00:00
|
|
|
];
|
|
|
|
|
2021-11-11 17:14:39 +00:00
|
|
|
postPatch = ''
|
2021-09-15 17:36:31 +00:00
|
|
|
patchShebangs tests/*
|
|
|
|
|
2021-10-14 19:27:54 +00:00
|
|
|
# Makefile tries to create the directory /var/lib/swtpm-localca, which fails
|
2021-10-15 13:37:12 +00:00
|
|
|
substituteInPlace samples/Makefile.am \
|
|
|
|
--replace 'install-data-local:' 'do-not-execute:'
|
|
|
|
|
|
|
|
# Use the correct path to the certtool binary
|
|
|
|
# instead of relying on it being in the environment
|
2022-03-10 14:34:40 +00:00
|
|
|
substituteInPlace src/swtpm_localca/swtpm_localca.c \
|
|
|
|
--replace \
|
|
|
|
'# define CERTTOOL_NAME "gnutls-certtool"' \
|
|
|
|
'# define CERTTOOL_NAME "${gnutls}/bin/certtool"' \
|
|
|
|
--replace \
|
2021-10-15 13:37:12 +00:00
|
|
|
'# define CERTTOOL_NAME "certtool"' \
|
|
|
|
'# define CERTTOOL_NAME "${gnutls}/bin/certtool"'
|
2022-03-10 14:34:40 +00:00
|
|
|
|
|
|
|
substituteInPlace tests/common --replace \
|
|
|
|
'CERTTOOL=gnutls-certtool;;' \
|
|
|
|
'CERTTOOL=certtool;;'
|
|
|
|
|
|
|
|
# Fix error on macOS:
|
|
|
|
# stat: invalid option -- '%'
|
|
|
|
# This is caused by the stat program not being the BSD version,
|
|
|
|
# as is expected by the test
|
|
|
|
substituteInPlace tests/common --replace \
|
|
|
|
'if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-) ]]; then' \
|
|
|
|
'if [[ "$(uname -s)" =~ (Linux|Darwin|CYGWIN_NT-) ]]; then'
|
|
|
|
|
|
|
|
# Otherwise certtool seems to pick up the system language on macOS,
|
|
|
|
# which might cause a test to fail
|
|
|
|
substituteInPlace tests/test_swtpm_setup_create_cert --replace \
|
|
|
|
'$CERTTOOL' \
|
|
|
|
'LC_ALL=C.UTF-8 $CERTTOOL'
|
2021-10-15 13:37:12 +00:00
|
|
|
'';
|
|
|
|
|
2021-09-15 17:36:31 +00:00
|
|
|
doCheck = true;
|
2021-02-17 03:59:57 +00:00
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
outputs = [ "out" "man" ];
|
|
|
|
|
2022-02-20 11:56:45 +00:00
|
|
|
passthru.tests = { inherit (nixosTests) systemd-cryptenroll; };
|
|
|
|
|
2021-02-17 03:59:57 +00:00
|
|
|
meta = with lib; {
|
|
|
|
description = "Libtpms-based TPM emulator";
|
|
|
|
homepage = "https://github.com/stefanberger/swtpm";
|
|
|
|
license = licenses.bsd3;
|
|
|
|
maintainers = [ maintainers.baloo ];
|
|
|
|
};
|
|
|
|
}
|