diff --git a/modules/microvm/virtualization/microvm/appvm.nix b/modules/microvm/virtualization/microvm/appvm.nix index e04536f4e..393d60485 100644 --- a/modules/microvm/virtualization/microvm/appvm.nix +++ b/modules/microvm/virtualization/microvm/appvm.nix @@ -82,6 +82,7 @@ let ghaf-audio = { inherit (vm.ghafAudio) enable; + inherit (vm.ghafAudio) useTunneling; name = "${vm.name}"; }; @@ -270,7 +271,10 @@ in type = types.nullOr types.str; default = null; }; - ghafAudio.enable = lib.mkEnableOption "Ghaf application audio support"; + ghafAudio = { + enable = lib.mkEnableOption "Ghaf application audio support"; + useTunneling = lib.mkEnableOption "Use Pulseaudio tunneling"; + }; vtpm.enable = lib.mkEnableOption "vTPM support in the virtual machine"; }; } diff --git a/modules/microvm/virtualization/microvm/common/ghaf-audio.nix b/modules/microvm/virtualization/microvm/common/ghaf-audio.nix index 2d0116f3e..9be8fbe77 100644 --- a/modules/microvm/virtualization/microvm/common/ghaf-audio.nix +++ b/modules/microvm/virtualization/microvm/common/ghaf-audio.nix @@ -23,16 +23,18 @@ in ''; type = types.str; }; + + useTunneling = mkEnableOption "Enable local pulseaudio with tunneling"; }; config = lib.mkIf cfg.enable { - security.rtkit.enable = true; - users.extraUsers.ghaf.extraGroups = [ + security.rtkit.enable = cfg.useTunneling; + users.extraUsers.ghaf.extraGroups = lib.mkIf cfg.useTunneling [ "audio" "video" ]; - hardware.pulseaudio = { + hardware.pulseaudio = lib.mkIf cfg.useTunneling { enable = true; extraConfig = '' load-module module-tunnel-sink-new sink_name=${cfg.name}.speaker server=${address} reconnect_interval_ms=${toString reconnectMs} @@ -40,5 +42,12 @@ in ''; package = pkgs.pulseaudio-ghaf; }; + + environment = lib.mkIf (!cfg.useTunneling) { + systemPackages = [ pkgs.pulseaudio ]; + sessionVariables = rec { + PULSE_SERVER = "${address}"; + }; + }; }; }