From d20022018e0b0c0e1770c62f25c29b339e59d252 Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Fri, 23 Aug 2019 17:47:09 +0200 Subject: [PATCH] libvirtd: add onBoot option This adds a new ``onBoot`` option that allows specifying the action taken on guests when the host boots. Specifying "start" ensures all guests that were running prior to shutdown are started, regardless of their autostart settings. Specifying "ignore" will make libvirtd ignore such guests. Any guest marked as autostart will still be automatically started by libvirtd. --- nixos/modules/virtualisation/libvirtd.nix | 13 +++++++++++++ pkgs/development/libraries/libvirt/default.nix | 1 + 2 files changed, 14 insertions(+) diff --git a/nixos/modules/virtualisation/libvirtd.nix b/nixos/modules/virtualisation/libvirtd.nix index 394b4ce56563..16b79d869193 100644 --- a/nixos/modules/virtualisation/libvirtd.nix +++ b/nixos/modules/virtualisation/libvirtd.nix @@ -104,6 +104,18 @@ in { ''; }; + onBoot = mkOption { + type = types.enum ["start" "ignore" ]; + default = "start"; + description = '' + Specifies the action to be done to / on the guests when the host boots. + The "start" option starts all guests that were running prior to shutdown + regardless of their autostart settings. The "ignore" option will not + start the formally running guest on boot. However, any guest marked as + autostart will still be automatically started by libvirtd. + ''; + }; + onShutdown = mkOption { type = types.enum ["shutdown" "suspend" ]; default = "suspend"; @@ -221,6 +233,7 @@ in { path = with pkgs; [ coreutils libvirt gawk ]; restartIfChanged = false; + environment.ON_BOOT = "${cfg.onBoot}"; environment.ON_SHUTDOWN = "${cfg.onShutdown}"; }; diff --git a/pkgs/development/libraries/libvirt/default.nix b/pkgs/development/libraries/libvirt/default.nix index d8446351945d..125259a6bee9 100644 --- a/pkgs/development/libraries/libvirt/default.nix +++ b/pkgs/development/libraries/libvirt/default.nix @@ -129,6 +129,7 @@ in stdenv.mkDerivation rec { binPath = [ iptables iproute pmutils numad numactl bridge-utils dmidecode dnsmasq ebtables ] ++ optionals enableIscsi [ openiscsi ]; in '' 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' \