2021-08-27 13:00:59 +01:00
|
|
|
{ lib, stdenv, fetchurl, fetchpatch, pkg-config, autoreconfHook, makeWrapper
|
2018-12-15 03:50:31 +00:00
|
|
|
, ncurses, cpio, gperf, cdrkit, flex, bison, qemu, pcre, augeas, libxml2
|
2020-08-23 03:41:35 +01:00
|
|
|
, acl, libcap, libcap_ng, libconfig, systemd, fuse, yajl, libvirt, hivex, db
|
2021-01-09 19:51:33 +00:00
|
|
|
, gmp, readline, file, numactl, libapparmor, jansson
|
2018-01-09 13:36:37 +00:00
|
|
|
, getopt, perlPackages, ocamlPackages
|
2020-08-21 13:55:40 +01:00
|
|
|
, libtirpc
|
2018-03-21 13:05:34 +00:00
|
|
|
, appliance ? null
|
2018-01-09 13:36:37 +00:00
|
|
|
, javaSupport ? false, jdk ? null }:
|
|
|
|
|
2021-01-21 17:00:13 +00:00
|
|
|
assert appliance == null || lib.isDerivation appliance;
|
2018-01-09 13:36:37 +00:00
|
|
|
assert javaSupport -> jdk != null;
|
2014-11-06 10:32:59 +00:00
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
2019-08-15 13:41:18 +01:00
|
|
|
pname = "libguestfs";
|
2021-08-27 13:00:59 +01:00
|
|
|
version = "1.44.1";
|
2014-11-06 10:32:59 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
2021-08-27 13:00:59 +01:00
|
|
|
url = "https://libguestfs.org/download/${lib.versions.majorMinor version}-stable/${pname}-${version}.tar.gz";
|
|
|
|
sha256 = "09dhmlbfdwirlmkasa28x69vqs5xndq0lnng6b4if76s6bfxrdvj";
|
2014-11-06 10:32:59 +00:00
|
|
|
};
|
|
|
|
|
2021-08-27 23:56:19 +01:00
|
|
|
strictDeps = true;
|
|
|
|
nativeBuildInputs = [
|
|
|
|
autoreconfHook bison cdrkit cpio flex getopt gperf makeWrapper pkg-config qemu
|
2021-10-23 21:49:10 +01:00
|
|
|
] ++ (with perlPackages; [ perl libintl-perl GetoptLong SysVirt ])
|
2021-08-27 23:56:19 +01:00
|
|
|
++ (with ocamlPackages; [ ocaml findlib ]);
|
2014-11-06 10:32:59 +00:00
|
|
|
buildInputs = [
|
2021-08-27 23:56:19 +01:00
|
|
|
ncurses jansson
|
|
|
|
pcre augeas libxml2 acl libcap libcap_ng libconfig
|
2020-08-23 03:41:35 +01:00
|
|
|
systemd fuse yajl libvirt gmp readline file hivex db
|
2021-08-27 23:56:19 +01:00
|
|
|
numactl libapparmor perlPackages.ModuleBuild
|
2020-08-21 13:55:40 +01:00
|
|
|
libtirpc
|
2021-08-27 23:56:19 +01:00
|
|
|
] ++ (with ocamlPackages; [ ocamlbuild ocaml_libvirt gettext-stub ounit ])
|
2021-01-21 17:00:13 +00:00
|
|
|
++ lib.optional javaSupport jdk;
|
2014-11-06 10:32:59 +00:00
|
|
|
|
2017-02-22 06:01:09 +00:00
|
|
|
prePatch = ''
|
|
|
|
# build-time scripts
|
2019-01-15 22:41:31 +00:00
|
|
|
substituteInPlace run.in --replace '#!/bin/bash' '#!${stdenv.shell}'
|
2021-08-27 13:00:59 +01:00
|
|
|
substituteInPlace ocaml-link.sh.in --replace '#!/bin/bash' '#!${stdenv.shell}'
|
2017-02-22 06:01:09 +00:00
|
|
|
|
|
|
|
# $(OCAMLLIB) is read-only "${ocamlPackages.ocaml}/lib/ocaml"
|
|
|
|
substituteInPlace ocaml/Makefile.am --replace '$(DESTDIR)$(OCAMLLIB)' '$(out)/lib/ocaml'
|
|
|
|
substituteInPlace ocaml/Makefile.in --replace '$(DESTDIR)$(OCAMLLIB)' '$(out)/lib/ocaml'
|
2017-05-19 12:29:29 +01:00
|
|
|
|
|
|
|
# some scripts hardcore /usr/bin/env which is not available in the build env
|
|
|
|
patchShebangs .
|
2017-02-22 06:01:09 +00:00
|
|
|
'';
|
2021-08-27 13:00:59 +01:00
|
|
|
configureFlags = [
|
|
|
|
"--disable-appliance"
|
|
|
|
"--disable-daemon"
|
|
|
|
"--with-distro=NixOS"
|
|
|
|
"--with-guestfs-path=${placeholder "out"}/lib/guestfs"
|
|
|
|
] ++ lib.optionals (!javaSupport) [ "--without-java" ];
|
|
|
|
patches = [
|
|
|
|
./libguestfs-syms.patch
|
|
|
|
# Set HAVE_RPM, HAVE_DPKG, HAVE_PACMAN
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/libguestfs/libguestfs/commit/210959cc344d6a4a1e3afa26d276b130651def74.patch";
|
|
|
|
sha256 = "121l58mk2mwhhqc3rcisdw3di7y729b30hyffc8a50mq5k7fvsdb";
|
|
|
|
})
|
|
|
|
];
|
2015-10-05 12:23:01 +01:00
|
|
|
NIX_CFLAGS_COMPILE="-I${libxml2.dev}/include/libxml2/";
|
2019-11-05 01:10:31 +00:00
|
|
|
installFlags = [ "REALLY_INSTALL=yes" ];
|
2017-05-19 12:29:29 +01:00
|
|
|
enableParallelBuilding = true;
|
2014-11-06 10:32:59 +00:00
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
for bin in $out/bin/*; do
|
|
|
|
wrapProgram "$bin" \
|
2018-03-21 13:05:34 +00:00
|
|
|
--prefix PATH : "$out/bin:${hivex}/bin:${qemu}/bin" \
|
2018-12-15 03:50:31 +00:00
|
|
|
--prefix PERL5LIB : "$out/${perlPackages.perl.libPrefix}"
|
2014-11-06 10:32:59 +00:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2021-01-21 17:00:13 +00:00
|
|
|
postFixup = lib.optionalString (appliance != null) ''
|
2018-03-21 13:05:34 +00:00
|
|
|
mkdir -p $out/{lib,lib64}
|
|
|
|
ln -s ${appliance} $out/lib64/guestfs
|
|
|
|
ln -s ${appliance} $out/lib/guestfs
|
|
|
|
'';
|
|
|
|
|
2018-03-22 07:19:12 +00:00
|
|
|
doInstallCheck = appliance != null;
|
2018-03-21 13:05:34 +00:00
|
|
|
installCheckPhase = ''
|
2019-10-31 20:48:19 +00:00
|
|
|
runHook preInstallCheck
|
|
|
|
|
2018-03-21 13:05:34 +00:00
|
|
|
export HOME=$(mktemp -d) # avoid access to /homeless-shelter/.guestfish
|
|
|
|
|
|
|
|
${qemu}/bin/qemu-img create -f qcow2 disk1.img 10G
|
|
|
|
|
|
|
|
$out/bin/guestfish <<'EOF'
|
|
|
|
add-drive disk1.img
|
|
|
|
run
|
|
|
|
list-filesystems
|
|
|
|
part-disk /dev/sda mbr
|
|
|
|
mkfs ext2 /dev/sda1
|
|
|
|
list-filesystems
|
|
|
|
EOF
|
2019-10-31 20:48:19 +00:00
|
|
|
|
|
|
|
runHook postInstallCheck
|
2014-11-06 10:32:59 +00:00
|
|
|
'';
|
|
|
|
|
2021-01-21 17:00:13 +00:00
|
|
|
meta = with lib; {
|
2014-11-06 10:32:59 +00:00
|
|
|
description = "Tools for accessing and modifying virtual machine disk images";
|
2021-08-27 23:59:33 +01:00
|
|
|
license = with licenses; [ gpl2Plus lgpl21Plus ];
|
2020-10-02 08:58:50 +01:00
|
|
|
homepage = "https://libguestfs.org/";
|
2014-11-06 10:32:59 +00:00
|
|
|
maintainers = with maintainers; [offline];
|
2015-11-17 20:29:29 +00:00
|
|
|
platforms = platforms.linux;
|
2020-10-29 18:47:29 +00:00
|
|
|
# this is to avoid "output size exceeded"
|
|
|
|
hydraPlatforms = if appliance != null then appliance.meta.hydraPlatforms else platforms.linux;
|
2014-11-06 10:32:59 +00:00
|
|
|
};
|
|
|
|
}
|