1{ lib, stdenv, fetchurl, system ? builtins.currentSystem, ovftoolBundles ? {}
2, autoPatchelfHook, makeWrapper, unzip
3, glibc, c-ares, libxcrypt-legacy, expat, icu60, xercesc, zlib
4}:
5
6let
7 version = "4.6.2-22220919";
8 version_i686 = "4.6.0-21452615";
9
10 ovftoolZipUnpackPhase = ''
11 runHook preUnpack
12 unzip ${ovftoolSource}
13 extracted=ovftool/
14 if [ -d "$extracted" ]; then
15 echo "ovftool extracted successfully" >&2
16 else
17 echo "Could not find $extracted - are you sure this is ovftool?" >&2
18 exit 1
19 fi
20 runHook postUnpack
21 '';
22
23 ovftoolSystems = let
24 baseUrl = "https://vdc-download.vmware.com/vmwb-repository/dcr-public";
25 in {
26 "i686-linux" = rec {
27 name = "VMware-ovftool-${version_i686}-lin.i386.zip";
28 url = "${baseUrl}/7254abb2-434d-4f5d-83e2-9311ced9752e/57e666a2-874c-48fe-b1d2-4b6381f7fe97/${name}";
29 hash = "sha256-qEOr/3SW643G5ZQQNJTelZbUxB8HmxPd5uD+Gqsoxz0=";
30 unpackPhase = ovftoolZipUnpackPhase;
31 };
32 "x86_64-linux" = rec {
33 name = "VMware-ovftool-${version}-lin.x86_64.zip";
34 url = "${baseUrl}/8a93ce23-4f88-4ae8-b067-ae174291e98f/c609234d-59f2-4758-a113-0ec5bbe4b120/${name}";
35 hash = "sha256-3B1cUDldoTqLsbSARj2abM65nv+Ot0z/Fa35/klJXEY=";
36 unpackPhase = ovftoolZipUnpackPhase;
37 };
38 };
39
40 ovftoolSystem = if builtins.hasAttr system ovftoolSystems then
41 ovftoolSystems.${system}
42 else throw "System '${system}' is unsupported by ovftool";
43
44 ovftoolSource = if builtins.hasAttr system ovftoolBundles then
45 ovftoolBundles.${system}
46 else
47 fetchurl {
48 inherit (ovftoolSystem) name url hash;
49 };
50in
51stdenv.mkDerivation rec {
52 pname = "ovftool";
53 inherit version;
54
55 src = ovftoolSource;
56
57 buildInputs = [
58 glibc
59 libxcrypt-legacy
60 c-ares
61 expat
62 icu60
63 xercesc
64 zlib
65 ];
66
67 nativeBuildInputs = [ autoPatchelfHook makeWrapper unzip ];
68
69 preferLocalBuild = true;
70
71 sourceRoot = ".";
72
73 unpackPhase = ovftoolSystem.unpackPhase;
74
75 # Expects a directory named 'ovftool' containing the ovftool install.
76 # Based on https://aur.archlinux.org/packages/vmware-ovftool/
77 # with the addition of a libexec directory and a Nix-style binary wrapper.
78 installPhase = ''
79 runHook preInstall
80 if [ -d ovftool ]; then
81 # Ensure we're in the staging directory
82 cd ovftool
83 fi
84 # libraries
85 install -m 755 -d "$out/lib/${pname}"
86 # These all appear to be VMWare proprietary except for libgoogleurl and libcurl.
87 # The rest of the libraries that the installer extracts are omitted here,
88 # and provided in buildInputs. Since libcurl depends on VMWare's OpenSSL,
89 # we have to use both here too.
90 #
91 # FIXME: can we replace libgoogleurl? Possibly from Chromium?
92 # FIXME: tell VMware to use a modern version of OpenSSL.
93 #
94 install -m 644 -t "$out/lib/${pname}" \
95 libgoogleurl.so.59 \
96 libssoclient.so \
97 libvim-types.so libvmacore.so libvmomi.so \
98 libcurl.so.4 libcrypto.so.1.0.2 libssl.so.1.0.2
99 # libexec binaries
100 install -m 755 -d "$out/libexec/${pname}"
101 install -m 755 -t "$out/libexec/${pname}" ovftool.bin
102 install -m 644 -t "$out/libexec/${pname}" icudt44l.dat
103 # libexec resources
104 for subdir in "certs" "env" "env/en" "schemas/DMTF" "schemas/vmware"; do
105 install -m 755 -d "$out/libexec/${pname}/$subdir"
106 install -m 644 -t "$out/libexec/${pname}/$subdir" "$subdir"/*.*
107 done
108 # EULA/OSS files
109 install -m 755 -d "$out/share/licenses/${pname}"
110 install -m 644 -t "$out/share/licenses/${pname}" \
111 "vmware.eula" "vmware-eula.rtf" "open_source_licenses.txt"
112 # documentation files
113 install -m 755 -d "$out/share/doc/${pname}"
114 install -m 644 -t "$out/share/doc/${pname}" "README.txt"
115 # binary wrapper; note that LC_CTYPE is defaulted to en_US.UTF-8 by
116 # VMWare's wrapper script. We use C.UTF-8 instead.
117 install -m 755 -d "$out/bin"
118 makeWrapper "$out/libexec/${pname}/ovftool.bin" "$out/bin/ovftool" \
119 --set-default LC_CTYPE C.UTF-8 \
120 --prefix LD_LIBRARY_PATH : "$out/lib"
121 runHook postInstall
122 '';
123
124 preFixup = ''
125 addAutoPatchelfSearchPath "$out/lib"
126 '';
127
128 doInstallCheck = true;
129
130 installCheckPhase = ''
131 # This is a NixOS 22.11 image (doesn't actually matter) with a 1 MiB root disk that's all zero.
132 # Make sure that it converts properly.
133 mkdir -p ovftool-check
134 cd ovftool-check
135
136 $out/bin/ovftool ${./installCheckPhase.ova} nixos.ovf
137 if [ ! -f nixos.ovf ] || [ ! -f nixos.mf ] || [ ! -f nixos-disk1.vmdk ]; then
138 exit 1
139 fi
140 '';
141
142 meta = with lib; {
143 description = "VMWare tools for working with OVF, OVA, and VMX images";
144 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
145 license = licenses.unfree;
146 maintainers = with maintainers; [ numinit wolfangaukang ];
147 platforms = builtins.attrNames ovftoolSystems;
148 };
149}