70 , enableGlusterfs ? false
75 , enableXen ? stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86_64
77 , enableZfs ? stdenv.hostPlatform.isLinux
82 inherit (stdenv.hostPlatform) isDarwin isLinux isx86_64;
83 binPath = lib.makeBinPath ([
85 ] ++ lib.optionals isLinux [
98 ] ++ lib.optionals enableIscsi [
101 ] ++ lib.optionals enableZfs [
106 assert enableXen -> isLinux && isx86_64;
107 assert enableCeph -> isLinux;
108 assert enableGlusterfs -> isLinux;
109 assert enableZfs -> isLinux;
111 # if you update, also bump <nixpkgs/pkgs/development/python-modules/libvirt/default.nix> and SysVirt in <nixpkgs/pkgs/top-level/perl-packages.nix>
112 stdenv.mkDerivation rec {
114 # NOTE: You must also bump:
115 # <nixpkgs/pkgs/development/python-modules/libvirt/default.nix>
116 # SysVirt in <nixpkgs/pkgs/top-level/perl-packages.nix>
119 src = fetchFromGitLab {
123 hash = "sha256-LYQYA5UIKYs+8rSNZDymmrxuTWsgmukP5Y17lGB5UQs=";
124 fetchSubmodules = true;
128 ./0001-meson-patch-in-an-install-prefix-for-building-on-nix.patch
129 ] ++ lib.optionals enableZfs [
131 src = ./0002-substitute-zfs-and-zpool-commands.patch;
132 zfs = "${zfs}/bin/zfs";
133 zpool = "${zfs}/bin/zpool";
137 # remove some broken tests
139 sed -i '/commandtest/d' tests/meson.build
140 sed -i '/virnetsockettest/d' tests/meson.build
141 # delete only the first occurrence of this
142 sed -i '0,/qemuxmlconftest/{/qemuxmlconftest/d;}' tests/meson.build
144 '' + lib.optionalString isLinux ''
145 for binary in mount umount mkfs; do
146 substituteInPlace meson.build \
147 --replace "find_program('$binary'" "find_program('${lib.getBin util-linux}/bin/$binary'"
151 substituteInPlace meson.build \
152 --replace "'dbus-daemon'," "'${lib.getBin dbus}/bin/dbus-daemon',"
153 '' + lib.optionalString isLinux ''
154 sed -i 's,define PARTED "parted",define PARTED "${parted}/bin/parted",' \
155 src/storage/storage_backend_disk.c \
156 src/storage/storage_util.c
157 '' + lib.optionalString isDarwin ''
158 # Darwin doesn’t support -fsemantic-interposition, but the problem doesn’t seem to affect Mach-O.
159 # See https://gitlab.com/libvirt/libvirt/-/merge_requests/235
160 sed -i "s/not supported_cc_flags.contains('-fsemantic-interposition')/false/" meson.build
161 sed -i '/qemufirmwaretest/d' tests/meson.build
162 sed -i '/qemuhotplugtest/d' tests/meson.build
163 sed -i '/qemuvhostusertest/d' tests/meson.build
164 sed -i '/qemuxml2xmltest/d' tests/meson.build
165 sed -i '/domaincapstest/d' tests/meson.build
166 # virshtest frequently times out on Darwin
167 substituteInPlace tests/meson.build \
168 --replace-fail "data.get('timeout', 30)" "data.get('timeout', 120)"
169 '' + lib.optionalString enableXen ''
170 # Has various hardcoded paths that don't exist outside of a Xen dom0.
171 sed -i '/libxlxml2domconfigtest/d' tests/meson.build
172 substituteInPlace src/libxl/libxl_capabilities.h \
173 --replace-fail /usr/lib/xen ${xen}/libexec/xen
178 nativeBuildInputs = [
181 libxml2 # for xmllint
182 libxslt # for xsltproc
188 perlPackages.XMLXPath
190 ++ lib.optional (!isDarwin) rpcsvc-proto
191 # NOTE: needed for rpcgen
192 ++ lib.optional isDarwin darwin.developer_cmds;
209 ] ++ lib.optionals isLinux [
225 ] ++ lib.optionals isDarwin [
231 ++ lib.optionals enableCeph [ ceph ]
232 ++ lib.optionals enableGlusterfs [ glusterfs ]
233 ++ lib.optionals enableIscsi [ libiscsi openiscsi ]
234 ++ lib.optionals enableXen [ xen ]
235 ++ lib.optionals enableZfs [ zfs ];
240 QEMU_BRIDGE_HELPER = "/run/wrappers/bin/qemu-bridge-helper";
241 QEMU_PR_HELPER = "/run/libvirt/nix-helpers/qemu-pr-helper";
244 patchBuilder = var: value: ''
245 sed -i meson.build -e "s|conf.set_quoted('${var}',.*|conf.set_quoted('${var}','${value}')|"
249 PATH="${binPath}:$PATH"
250 # the path to qemu-kvm will be stored in VM's .xml and .save files
251 # do not use "''${qemu_kvm}/bin/qemu-kvm" to avoid bound VMs to particular qemu derivations
252 substituteInPlace src/lxc/lxc_conf.c \
253 --replace 'lxc_path,' '"/run/libvirt/nix-emulators/libvirt_lxc",'
255 substituteInPlace build-aux/meson.build \
256 --replace "gsed" "sed" \
257 --replace "gmake" "make" \
258 --replace "ggrep" "grep"
260 substituteInPlace src/util/virpolkit.h \
261 --replace '"/usr/bin/pkttyagent"' '"${if isLinux then polkit.bin else "/usr"}/bin/pkttyagent"'
263 substituteInPlace src/util/virpci.c \
264 --replace '/lib/modules' '${if isLinux then "/run/booted-system/kernel-modules" else ""}/lib/modules'
268 + (lib.concatStringsSep "\n" (lib.mapAttrsToList patchBuilder overrides));
270 mesonAutoFeatures = "disabled";
274 cfg = option: val: "-D${option}=${val}";
275 feat = option: enable: cfg option (if enable then "enabled" else "disabled");
276 driver = name: feat "driver_${name}";
277 storage = name: feat "storage_${name}";
280 "--sysconfdir=/var/lib"
281 (cfg "install_prefix" (placeholder "out"))
282 (cfg "localstatedir" "/var")
283 (cfg "runstatedir" (if isDarwin then "/var/run" else "/run"))
284 (cfg "sshconfdir" "/etc/ssh/ssh_config.d")
286 (cfg "init_script" (if isDarwin then "none" else "systemd"))
287 (cfg "qemu_datadir" (lib.optionalString isDarwin "${qemu}/share/qemu"))
289 (feat "apparmor" isLinux)
290 (feat "attr" isLinux)
291 (feat "audit" isLinux)
292 (feat "bash_completion" true)
293 (feat "blkid" isLinux)
294 (feat "capng" isLinux)
297 (feat "expensive_tests" true)
298 (feat "firewalld" isLinux)
299 (feat "firewalld_zone" isLinux)
300 (feat "fuse" isLinux)
301 (feat "glusterfs" enableGlusterfs)
302 (feat "host_validate" true)
303 (feat "libiscsi" enableIscsi)
304 (feat "libnl" isLinux)
305 (feat "libpcap" true)
306 (feat "libssh2" true)
307 (feat "login_shell" isLinux)
308 (feat "nss" (isLinux && !stdenv.hostPlatform.isMusl))
309 (feat "numactl" isLinux)
310 (feat "numad" isLinux)
311 (feat "pciaccess" isLinux)
312 (feat "polkit" isLinux)
313 (feat "readline" true)
314 (feat "secdriver_apparmor" isLinux)
315 (feat "ssh_proxy" isLinux)
317 (feat "udev" isLinux)
320 (driver "ch" isLinux)
322 (driver "interface" isLinux)
323 (driver "libvirtd" true)
324 (driver "libxl" enableXen)
325 (driver "lxc" isLinux)
326 (driver "network" true)
327 (driver "openvz" isLinux)
329 (driver "remote" true)
330 (driver "secrets" true)
333 (driver "vmware" true)
336 (storage "disk" isLinux)
337 (storage "fs" isLinux)
338 (storage "gluster" enableGlusterfs)
339 (storage "iscsi" enableIscsi)
340 (storage "iscsi_direct" enableIscsi)
341 (storage "lvm" isLinux)
342 (storage "mpath" isLinux)
343 (storage "rbd" enableCeph)
344 (storage "scsi" true)
345 (storage "vstorage" isLinux)
346 (storage "zfs" enableZfs)
352 substituteInPlace $out/bin/virt-xml-validate \
353 --replace xmllint ${libxml2}/bin/xmllint
355 substituteInPlace $out/libexec/libvirt-guests.sh \
356 --replace 'ON_BOOT="start"' 'ON_BOOT=''${ON_BOOT:-start}' \
357 --replace 'ON_SHUTDOWN="suspend"' 'ON_SHUTDOWN=''${ON_SHUTDOWN:-suspend}' \
358 --replace 'PARALLEL_SHUTDOWN=0' 'PARALLEL_SHUTDOWN=''${PARALLEL_SHUTDOWN:-0}' \
359 --replace "$out/bin" '${gettext}/bin' \
360 --replace 'lock/subsys' 'lock' \
361 --replace 'gettext.sh' 'gettext.sh
363 gettext() { "${gettext}/bin/gettext" "$@"; }
365 '' + lib.optionalString isLinux ''
366 for f in $out/lib/systemd/system/*.service ; do
367 substituteInPlace $f --replace /bin/kill ${coreutils}/bin/kill
369 rm $out/lib/systemd/system/{virtlockd,virtlogd}.*
370 wrapProgram $out/sbin/libvirtd \
371 --prefix PATH : /run/libvirt/nix-emulators:${binPath}
374 passthru.updateScript = writeScript "update-libvirt" ''
375 #!/usr/bin/env nix-shell
376 #!nix-shell -i bash -p curl jq common-updater-scripts
380 libvirtVersion=$(curl https://gitlab.com/api/v4/projects/192693/repository/tags | jq -r '.[].name|select(. | contains("rc") | not)' | head -n1 | sed "s/v//g")
381 sysvirtVersion=$(curl https://gitlab.com/api/v4/projects/192677/repository/tags | jq -r '.[].name|select(. | contains("rc") | not)' | head -n1 | sed "s/v//g")
382 update-source-version ${pname} "$libvirtVersion"
383 update-source-version python3Packages.${pname} "$libvirtVersion"
384 update-source-version perlPackages.SysVirt "$sysvirtVersion" --file="pkgs/top-level/perl-packages.nix"
387 passthru.tests.libvirtd = nixosTests.libvirtd;
390 description = "Toolkit to interact with the virtualization capabilities of recent versions of Linux and other OSes";
391 homepage = "https://libvirt.org/";
392 changelog = "https://gitlab.com/libvirt/libvirt/-/raw/v${version}/NEWS.rst";
393 license = licenses.lgpl2Plus;
394 platforms = platforms.unix;
395 maintainers = with maintainers; [ fpletz globin lovesegfault ];