2022-02-21 08:47:16 +00:00
|
|
|
{ lib, stdenv, fetchurl, pkg-config, autoreconfHook, makeWrapper
|
|
|
|
, ncurses, cpio, gperf, cdrkit, flex, bison, qemu, pcre2, augeas, libxml2
|
2020-09-25 04:45:31 +00:00
|
|
|
, acl, libcap, libcap_ng, libconfig, systemd, fuse, yajl, libvirt, hivex, db
|
2021-01-15 22:18:51 +00:00
|
|
|
, gmp, readline, file, numactl, libapparmor, jansson
|
2020-04-24 23:36:52 +00:00
|
|
|
, getopt, perlPackages, ocamlPackages
|
2020-10-16 20:44:37 +00:00
|
|
|
, libtirpc
|
2020-04-24 23:36:52 +00:00
|
|
|
, appliance ? null
|
|
|
|
, javaSupport ? false, jdk ? null }:
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
assert appliance == null || lib.isDerivation appliance;
|
2020-04-24 23:36:52 +00:00
|
|
|
assert javaSupport -> jdk != null;
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "libguestfs";
|
2022-02-21 08:47:16 +00:00
|
|
|
version = "1.46.2";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
2021-09-18 10:52:07 +00:00
|
|
|
url = "https://libguestfs.org/download/${lib.versions.majorMinor version}-stable/${pname}-${version}.tar.gz";
|
2022-02-21 08:47:16 +00:00
|
|
|
sha256 = "0sq092irlj2jf64m7hjx23hn5k4iypqxmlyn9g2z0q0xab56ksp6";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
strictDeps = true;
|
|
|
|
nativeBuildInputs = [
|
|
|
|
autoreconfHook bison cdrkit cpio flex getopt gperf makeWrapper pkg-config qemu
|
2021-10-28 06:52:43 +00:00
|
|
|
] ++ (with perlPackages; [ perl libintl-perl GetoptLong SysVirt ])
|
2021-09-18 10:52:07 +00:00
|
|
|
++ (with ocamlPackages; [ ocaml findlib ]);
|
2020-04-24 23:36:52 +00:00
|
|
|
buildInputs = [
|
2021-09-18 10:52:07 +00:00
|
|
|
ncurses jansson
|
2022-02-21 08:47:16 +00:00
|
|
|
pcre2 augeas libxml2 acl libcap libcap_ng libconfig
|
2020-09-25 04:45:31 +00:00
|
|
|
systemd fuse yajl libvirt gmp readline file hivex db
|
2021-09-18 10:52:07 +00:00
|
|
|
numactl libapparmor perlPackages.ModuleBuild
|
2020-10-16 20:44:37 +00:00
|
|
|
libtirpc
|
2021-09-18 10:52:07 +00:00
|
|
|
] ++ (with ocamlPackages; [ ocamlbuild ocaml_libvirt gettext-stub ounit ])
|
2021-02-05 17:12:51 +00:00
|
|
|
++ lib.optional javaSupport jdk;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
prePatch = ''
|
|
|
|
# build-time scripts
|
|
|
|
substituteInPlace run.in --replace '#!/bin/bash' '#!${stdenv.shell}'
|
2021-09-18 10:52:07 +00:00
|
|
|
substituteInPlace ocaml-link.sh.in --replace '#!/bin/bash' '#!${stdenv.shell}'
|
2020-04-24 23:36:52 +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'
|
|
|
|
|
|
|
|
# some scripts hardcore /usr/bin/env which is not available in the build env
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
2021-09-18 10:52:07 +00: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
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
installFlags = [ "REALLY_INSTALL=yes" ];
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
for bin in $out/bin/*; do
|
|
|
|
wrapProgram "$bin" \
|
|
|
|
--prefix PATH : "$out/bin:${hivex}/bin:${qemu}/bin" \
|
|
|
|
--prefix PERL5LIB : "$out/${perlPackages.perl.libPrefix}"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
postFixup = lib.optionalString (appliance != null) ''
|
2020-04-24 23:36:52 +00:00
|
|
|
mkdir -p $out/{lib,lib64}
|
|
|
|
ln -s ${appliance} $out/lib64/guestfs
|
|
|
|
ln -s ${appliance} $out/lib/guestfs
|
|
|
|
'';
|
|
|
|
|
|
|
|
doInstallCheck = appliance != null;
|
|
|
|
installCheckPhase = ''
|
|
|
|
runHook preInstallCheck
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
runHook postInstallCheck
|
|
|
|
'';
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Tools for accessing and modifying virtual machine disk images";
|
2021-09-18 10:52:07 +00:00
|
|
|
license = with licenses; [ gpl2Plus lgpl21Plus ];
|
2020-10-07 09:15:18 +00:00
|
|
|
homepage = "https://libguestfs.org/";
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = with maintainers; [offline];
|
|
|
|
platforms = platforms.linux;
|
2020-11-03 02:18:15 +00:00
|
|
|
# this is to avoid "output size exceeded"
|
|
|
|
hydraPlatforms = if appliance != null then appliance.meta.hydraPlatforms else platforms.linux;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|