git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/libvirtd: add package option

At the moment, it's not possible to override the libvirtd package used without supplying a nixpkgs overlay. Adding a package option makes libvirtd more consistent and allows enabling e.g. ceph and iSCSI support more easily.

commit1ce6b05ea18de429b2ddf06332b99264cdb49bb1 authorLuke Granger-Brown <git@lukegb.com> dateWed 10 Mar 2021, 00:31 (6 years ago) parent40be12c
1 file changed+17−8
nixos/modules/virtualisation/libvirtd.nix+17−8
nixos/modules/virtualisation/libvirtd.nix+17−8
@@ -46,6 +46,15 @@ in {
4646 '';
4747 };
4848
49+ package = mkOption {
50+ type = types.package;
51+ default = pkgs.libvirt;
52+ defaultText = "pkgs.libvirt";
53+ description = ''
54+ libvirt package to use.
55+ '';
56+ };
57+
4958 qemuPackage = mkOption {
5059 type = types.package;
5160 default = pkgs.qemu;
@@ -149,7 +158,7 @@ in {
149158 # this file is expected in /etc/qemu and not sysconfdir (/var/lib)
150159 etc."qemu/bridge.conf".text = lib.concatMapStringsSep "\n" (e:
151160 "allow ${e}") cfg.allowedBridges;
152− systemPackages = with pkgs; [ libvirt libressl.nc iptables cfg.qemuPackage ];
161+ systemPackages = with pkgs; [ libressl.nc iptables cfg.package cfg.qemuPackage ];
153162 etc.ethertypes.source = "${pkgs.iptables}/etc/ethertypes";
154163 };
155164
@@ -169,26 +178,26 @@ in {
169178 source = "/run/${dirName}/nix-helpers/qemu-bridge-helper";
170179 };
171180
172− systemd.packages = [ pkgs.libvirt ];
181+ systemd.packages = [ cfg.package ];
173182
174183 systemd.services.libvirtd-config = {
175184 description = "Libvirt Virtual Machine Management Daemon - configuration";
176185 script = ''
177186 # Copy default libvirt network config .xml files to /var/lib
178187 # Files modified by the user will not be overwritten
179− for i in $(cd ${pkgs.libvirt}/var/lib && echo \
188+ for i in $(cd ${cfg.package}/var/lib && echo \
180189 libvirt/qemu/networks/*.xml libvirt/qemu/networks/autostart/*.xml \
181190 libvirt/nwfilter/*.xml );
182191 do
183192 mkdir -p /var/lib/$(dirname $i) -m 755
184− cp -npd ${pkgs.libvirt}/var/lib/$i /var/lib/$i
193+ cp -npd ${cfg.package}/var/lib/$i /var/lib/$i
185194 done
186195
187196 # Copy generated qemu config to libvirt directory
188197 cp -f ${qemuConfigFile} /var/lib/${dirName}/qemu.conf
189198
190199 # stable (not GC'able as in /nix/store) paths for using in <emulator> section of xml configs
191− for emulator in ${pkgs.libvirt}/libexec/libvirt_lxc ${cfg.qemuPackage}/bin/qemu-kvm ${cfg.qemuPackage}/bin/qemu-system-*; do
200+ for emulator in ${cfg.package}/libexec/libvirt_lxc ${cfg.qemuPackage}/bin/qemu-kvm ${cfg.qemuPackage}/bin/qemu-system-*; do
192201 ln -s --force "$emulator" /run/${dirName}/nix-emulators/
193202 done
194203
@@ -234,7 +243,7 @@ in {
234243
235244 systemd.services.libvirt-guests = {
236245 wantedBy = [ "multi-user.target" ];
237− path = with pkgs; [ coreutils libvirt gawk ];
246+ path = with pkgs; [ coreutils gawk cfg.package ];
238247 restartIfChanged = false;
239248
240249 environment.ON_BOOT = "${cfg.onBoot}";
@@ -249,7 +258,7 @@ in {
249258
250259 systemd.services.virtlogd = {
251260 description = "Virtual machine log manager";
252− serviceConfig.ExecStart = "@${pkgs.libvirt}/sbin/virtlogd virtlogd";
261+ serviceConfig.ExecStart = "@${cfg.package}/sbin/virtlogd virtlogd";
253262 restartIfChanged = false;
254263 };
255264
@@ -261,7 +270,7 @@ in {
261270
262271 systemd.services.virtlockd = {
263272 description = "Virtual machine lock manager";
264− serviceConfig.ExecStart = "@${pkgs.libvirt}/sbin/virtlockd virtlockd";
273+ serviceConfig.ExecStart = "@${cfg.package}/sbin/virtlockd virtlockd";
265274 restartIfChanged = false;
266275 };
267276