nixpkgs/pkgs/development/libraries/libvirt/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

341 lines
7.8 KiB
Nix
Raw Normal View History

2021-09-05 03:06:15 +00:00
{ lib
, autoreconfHook
2022-03-14 07:33:21 +00:00
, bash-completion
, bridge-utils
, cmake
2021-09-05 03:06:15 +00:00
, coreutils
2022-03-14 07:33:21 +00:00
, curl
, darwin
, dbus
, dnsmasq
, docutils
2022-03-14 07:33:21 +00:00
, fetchFromGitLab
, fetchurl
, gettext
2022-03-14 07:33:21 +00:00
, glib
, gnutls
, iproute2
2021-09-05 03:06:15 +00:00
, iptables
, libgcrypt
, libpcap
2022-03-14 07:33:21 +00:00
, libtasn1
, libxml2
2021-09-05 03:06:15 +00:00
, libxslt
2022-03-14 07:33:21 +00:00
, makeWrapper
2021-09-05 03:06:15 +00:00
, meson
, ninja
2022-03-14 07:33:21 +00:00
, perl
, perlPackages
2021-09-05 03:06:15 +00:00
, pkg-config
2022-03-14 07:33:21 +00:00
, pmutils
, python3
, readline
, rpcsvc-proto
, stdenv
, xhtml1
, yajl
# Linux
, acl ? null
, attr ? null
, audit ? null
, dmidecode ? null
, fuse ? null
, kmod ? null
, libapparmor ? null
, libcap_ng ? null
, libnl ? null
, libpciaccess ? null
, libtirpc ? null
, lvm2 ? null
, numactl ? null
, numad ? null
, parted ? null
, systemd ? null
, util-linux ? null
# Darwin
, gmp ? null
, libiconv ? null
, Carbon ? null
, AppKit ? null
# Options
, enableCeph ? false
2022-03-14 07:33:21 +00:00
, ceph ? null
, enableGlusterfs ? false
2022-03-14 07:33:21 +00:00
, glusterfs ? null
, enableIscsi ? false
, openiscsi ? null
, libiscsi ? null
, enableXen ? false
, xen ? null
, enableZfs ? stdenv.isLinux
, zfs ? null
}:
2017-03-23 20:26:37 +00:00
with lib;
2017-03-23 20:26:37 +00:00
2018-02-26 22:50:46 +00:00
let
2022-03-14 07:33:21 +00:00
inherit (stdenv) isDarwin isLinux isx86_64;
binPath = makeBinPath ([
dnsmasq
] ++ optionals isLinux [
bridge-utils
dmidecode
dnsmasq
iproute2
iptables
kmod
lvm2
numactl
numad
pmutils
systemd
] ++ optionals enableIscsi [
libiscsi
openiscsi
]);
2021-09-05 03:06:15 +00:00
in
2022-03-14 07:33:21 +00:00
assert enableXen -> isLinux && isx86_64;
assert enableCeph -> isLinux;
assert enableGlusterfs -> isLinux;
assert enableZfs -> isLinux;
# if you update, also bump <nixpkgs/pkgs/development/python-modules/libvirt/default.nix> and SysVirt in <nixpkgs/pkgs/top-level/perl-packages.nix>
2021-09-05 03:06:15 +00:00
stdenv.mkDerivation rec {
pname = "libvirt";
2022-03-14 07:33:21 +00:00
# NOTE: You must also bump:
# <nixpkgs/pkgs/development/python-modules/libvirt/default.nix>
# SysVirt in <nixpkgs/pkgs/top-level/perl-packages.nix>
version = "7.10.0";
2018-02-26 22:50:46 +00:00
src =
2022-03-14 07:33:21 +00:00
if isDarwin then
2021-09-05 03:06:15 +00:00
fetchurl
{
url = "https://libvirt.org/sources/${pname}-${version}.tar.xz";
sha256 = "sha256-yzGAFK8JcyeSjG49cpIuO+AqPmQBJHsqpS2auOC0gPk=";
2021-09-05 03:06:15 +00:00
}
2018-02-26 22:50:46 +00:00
else
2021-10-12 20:05:07 +00:00
fetchFromGitLab
{
owner = pname;
repo = pname;
rev = "v${version}";
sha256 = "sha256-bB8LsjZFeJbMmmC0YRPyMag2MBhwagUFC7aB1KhZEkA=";
2021-10-12 20:05:07 +00:00
fetchSubmodules = true;
};
patches = [
./0001-meson-patch-in-an-install-prefix-for-building-on-nix.patch
];
2022-03-14 07:33:21 +00:00
# remove some broken tests
postPatch = ''
sed -i '/commandtest/d' tests/meson.build
sed -i '/virnetsockettest/d' tests/meson.build
# delete only the first occurrence of this
sed -i '0,/qemuxml2argvtest/{/qemuxml2argvtest/d;}' tests/meson.build
'';
nativeBuildInputs = [
2021-09-05 03:06:15 +00:00
meson
2022-03-14 07:33:21 +00:00
2021-09-05 03:06:15 +00:00
cmake
2022-03-14 07:33:21 +00:00
docutils
2021-09-05 03:06:15 +00:00
makeWrapper
2022-03-14 07:33:21 +00:00
ninja
2021-09-05 03:06:15 +00:00
pkg-config
2022-03-14 07:33:21 +00:00
]
++ optional (!isDarwin) rpcsvc-proto
# NOTE: needed for rpcgen
++ optional isDarwin darwin.developer_cmds;
2020-08-17 17:50:54 +00:00
buildInputs = [
2021-09-05 03:06:15 +00:00
bash-completion
2022-03-14 07:33:21 +00:00
curl
dbus
gettext
glib
gnutls
2022-03-14 07:33:21 +00:00
libgcrypt
libpcap
libtasn1
libxml2
libxslt
2021-09-05 03:06:15 +00:00
perl
2022-03-14 07:33:21 +00:00
perlPackages.XMLXPath
pkg-config
2021-09-05 03:06:15 +00:00
python3
readline
xhtml1
2022-03-14 07:33:21 +00:00
yajl
] ++ optionals isLinux [
acl
attr
2021-09-05 03:06:15 +00:00
audit
2022-03-14 07:33:21 +00:00
fuse
libapparmor
libcap_ng
2022-03-14 07:33:21 +00:00
libnl
libpciaccess
libtirpc
lvm2
numactl
2022-03-14 07:33:21 +00:00
numad
2021-09-05 03:06:15 +00:00
parted
2022-03-14 07:33:21 +00:00
systemd
util-linux
] ++ optionals isDarwin [
AppKit
2022-03-14 07:33:21 +00:00
Carbon
gmp
libiconv
]
++ optionals enableCeph [ ceph ]
++ optionals enableGlusterfs [ glusterfs ]
++ optionals enableIscsi [ libiscsi openiscsi ]
++ optionals enableXen [ xen ]
++ optionals enableZfs [ zfs ];
2021-09-05 03:06:15 +00:00
preConfigure =
let
overrides = {
QEMU_BRIDGE_HELPER = "/run/wrappers/bin/qemu-bridge-helper";
QEMU_PR_HELPER = "/run/libvirt/nix-helpers/qemu-pr-helper";
};
2022-03-14 07:33:21 +00:00
2021-09-05 03:06:15 +00:00
patchBuilder = var: value: ''
sed -i meson.build -e "s|conf.set_quoted('${var}',.*|conf.set_quoted('${var}','${value}')|"
'';
in
''
2022-03-14 07:33:21 +00:00
PATH="${binPath}:$PATH"
2021-09-05 03:06:15 +00:00
# the path to qemu-kvm will be stored in VM's .xml and .save files
# do not use "''${qemu_kvm}/bin/qemu-kvm" to avoid bound VMs to particular qemu derivations
substituteInPlace src/lxc/lxc_conf.c \
--replace 'lxc_path,' '"/run/libvirt/nix-emulators/libvirt_lxc",'
2022-03-14 07:33:21 +00:00
2021-09-13 04:20:00 +00:00
substituteInPlace build-aux/meson.build \
--replace "gsed" "sed" \
--replace "gmake" "make" \
--replace "ggrep" "grep"
2022-03-14 07:33:21 +00:00
2021-09-05 03:06:15 +00:00
patchShebangs .
''
+ (lib.concatStringsSep "\n" (lib.mapAttrsToList patchBuilder overrides));
mesonAutoFeatures = "auto";
2021-09-05 03:06:15 +00:00
mesonFlags =
let
2022-03-14 07:33:21 +00:00
cfg = option: val: "-D${option}=${val}";
feat = option: enable: cfg option (if enable then "enabled" else "disabled");
driver = name: feat "driver_${name}";
storage = name: feat "storage_${name}";
2021-09-05 03:06:15 +00:00
in
[
"--sysconfdir=/var/lib"
2022-03-14 07:33:21 +00:00
(cfg "install_prefix" (placeholder "out"))
(cfg "localstatedir" "/var")
(cfg "runstatedir" "/run")
(cfg "init_script" (if isDarwin then "none" else "systemd"))
(feat "apparmor" isLinux)
(feat "attr" isLinux)
(feat "audit" isLinux)
(feat "bash_completion" true)
(feat "blkid" isLinux)
(feat "capng" isLinux)
(feat "curl" true)
(feat "docs" true)
(feat "expensive_tests" true)
(feat "firewalld" isLinux)
(feat "firewalld_zone" isLinux)
(feat "fuse" isLinux)
(feat "glusterfs" enableGlusterfs)
(feat "host_validate" true)
(feat "libiscsi" enableIscsi)
(feat "libnl" isLinux)
(feat "libpcap" true)
(feat "libssh2" true)
(feat "login_shell" isLinux)
(feat "nss" isLinux)
(feat "numactl" isLinux)
(feat "numad" isLinux)
(feat "pciaccess" isLinux)
(feat "polkit" true)
(feat "readline" true)
(feat "secdriver_apparmor" isLinux)
(feat "tests" true)
(feat "udev" isLinux)
(feat "yajl" true)
(driver "ch" isLinux)
(driver "esx" true)
(driver "interface" isLinux)
(driver "libvirtd" true)
(driver "libxl" enableXen)
(driver "lxc" isLinux)
(driver "network" true)
(driver "openvz" isLinux)
(driver "qemu" true)
(driver "remote" true)
(driver "secrets" true)
(driver "test" true)
(driver "vbox" true)
(driver "vmware" true)
(storage "dir" true)
(storage "disk" isLinux)
(storage "fs" isLinux)
(storage "gluster" enableGlusterfs)
(storage "iscsi" enableIscsi)
(storage "iscsi_direct" enableIscsi)
(storage "lvm" isLinux)
(storage "mpath" isLinux)
(storage "rbd" enableCeph)
(storage "scsi" true)
(storage "vstorage" isLinux)
(storage "zfs" enableZfs)
2022-03-11 23:24:01 +00:00
];
2022-03-14 07:33:21 +00:00
doCheck = true;
postInstall = ''
substituteInPlace $out/bin/virt-xml-validate \
--replace xmllint ${libxml2}/bin/xmllint
substituteInPlace $out/libexec/libvirt-guests.sh \
--replace 'ON_BOOT="start"' 'ON_BOOT=''${ON_BOOT:-start}' \
--replace 'ON_SHUTDOWN="suspend"' 'ON_SHUTDOWN=''${ON_SHUTDOWN:-suspend}' \
--replace "$out/bin" '${gettext}/bin' \
--replace 'lock/subsys' 'lock' \
--replace 'gettext.sh' 'gettext.sh
# Added in nixpkgs:
gettext() { "${gettext}/bin/gettext" "$@"; }
'
'' + optionalString isLinux ''
substituteInPlace $out/lib/systemd/system/libvirtd.service --replace /bin/kill ${coreutils}/bin/kill
rm $out/lib/systemd/system/{virtlockd,virtlogd}.*
wrapProgram $out/sbin/libvirtd \
--prefix PATH : /run/libvirt/nix-emulators:${binPath}
'';
2017-03-23 20:26:37 +00:00
meta = {
2020-09-29 07:45:13 +00:00
homepage = "https://libvirt.org/";
repositories.git = "git://libvirt.org/libvirt.git";
description = ''
A toolkit to interact with the virtualization capabilities of recent
versions of Linux (and other OSes)
'';
license = licenses.lgpl2Plus;
platforms = platforms.unix;
2022-03-14 07:33:21 +00:00
maintainers = with maintainers; [ fpletz globin lovesegfault ];
};
}