Skip to content

Commit

Permalink
Add common Ghaf audio configuration for app-vms
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Sahlberg <[email protected]>
  • Loading branch information
josa41 authored and brianmcgillion committed Sep 27, 2024
1 parent 3f3766d commit 1733e08
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion modules/common/services/audio.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ in
# Enable TCP socket for VMs pulseaudio clients
"server.address" = [
{
address = "tcp:${toString cfg.pulseaudioTcpPort}";
address = "tcp:0.0.0.0:${toString cfg.pulseaudioTcpPort}";
"client.access" = "unrestricted";
}
];
Expand Down
7 changes: 7 additions & 0 deletions modules/microvm/virtualization/microvm/appvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let
internalIP = index + 100;
})

./common/ghaf-audio.nix
./common/storagevm.nix

# To push logs to central location
Expand Down Expand Up @@ -73,6 +74,11 @@ let
withHardenedConfigs = true;
};

ghaf-audio = {
inherit (vm.ghafAudio) enable;
name = "${vm.name}";
};

storagevm = {
enable = true;
name = "${vm.name}";
Expand Down Expand Up @@ -253,6 +259,7 @@ in
type = types.nullOr types.str;
default = null;
};
ghafAudio.enable = lib.mkEnableOption "Ghaf application audio support";
vtpm.enable = lib.mkEnableOption "vTPM support in the virtual machine";
};
}
Expand Down
44 changes: 44 additions & 0 deletions modules/microvm/virtualization/microvm/common/ghaf-audio.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
config,
lib,
pkgs,
...
}:
let
cfg = config.ghaf.ghaf-audio;
audiovmHost = "audio-vm";
audiovmPort = config.ghaf.services.audio.pulseaudioTcpPort;
address = "tcp:${audiovmHost}:${toString audiovmPort}";
reconnectMs = 1000;
in
{
options.ghaf.ghaf-audio = with lib; {
enable = mkEnableOption "Ghaf audio support for application virtual machine.";

name = mkOption {
description = ''
Basename of corresponding virtual machine audio channel.
'';
type = types.str;
};
};

config = lib.mkIf cfg.enable {
security.rtkit.enable = true;
users.extraUsers.ghaf.extraGroups = [
"audio"
"video"
];

hardware.pulseaudio = {
enable = true;
extraConfig = ''
load-module module-tunnel-sink-new sink_name=${cfg.name}.speaker server=${address} reconnect_interval_ms=${toString reconnectMs}
load-module module-tunnel-source-new source_name=${cfg.name}.mic server=${address} reconnect_interval_ms=${toString reconnectMs}
'';
package = pkgs.pulseaudio-ghaf;
};
};
}
18 changes: 1 addition & 17 deletions modules/reference/appvms/business.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ in
in
[
pkgs.chromium
pkgs.pulseaudio
pkgs.xdg-utils
xdgPdfItem
xdgOpenPdf
Expand All @@ -47,22 +46,6 @@ in
extraModules = [
{
imports = [ ../programs/chromium.nix ];
# Enable pulseaudio for Chromium VM
security.rtkit.enable = true;
users.extraUsers.ghaf.extraGroups = [
"audio"
"video"
];

hardware.pulseaudio = {
enable = true;
extraConfig = ''
load-module module-tunnel-sink-new sink_name=business-speaker server=audio-vm:4713 reconnect_interval_ms=1000
load-module module-tunnel-source-new source_name=business-mic server=audio-vm:4713 reconnect_interval_ms=1000
'';
package = pkgs.pulseaudio-ghaf;
};

time.timeZone = config.time.timeZone;

microvm = {
Expand Down Expand Up @@ -284,5 +267,6 @@ in
}
];
borderColor = "#00FF00";
ghafAudio.enable = true;
vtpm.enable = true;
}
16 changes: 1 addition & 15 deletions modules/reference/appvms/chromium.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,6 @@ in
extraModules = [
{
imports = [ ../programs/chromium.nix ];
# Enable pulseaudio for Chromium VM
security.rtkit.enable = true;
users.extraUsers.ghaf.extraGroups = [
"audio"
"video"
];

hardware.pulseaudio = {
enable = true;
extraConfig = ''
load-module module-tunnel-sink-new sink_name=chromium-speaker server=audio-vm:4713 reconnect_interval_ms=1000
load-module module-tunnel-source-new source_name=chromium-mic server=audio-vm:4713 reconnect_interval_ms=1000
'';
package = pkgs.pulseaudio-ghaf;
};

time.timeZone = config.time.timeZone;

Expand All @@ -84,5 +69,6 @@ in
}
];
borderColor = "#630505";
ghafAudio.enable = true;
vtpm.enable = true;
}
18 changes: 1 addition & 17 deletions modules/reference/appvms/comms.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,12 @@ in
pkgs.element-gps
pkgs.gpsd
pkgs.tcpdump
pkgs.pulseaudio
] ++ pkgs.lib.optionals isDendritePineconeEnabled [ dendrite-pinecone ];
macAddress = "02:00:00:03:09:01";
ramMb = 4096;
cores = 4;
extraModules = [
{
# Enable pulseaudio for user ghaf to access mic
security.rtkit.enable = true;
users.extraUsers.ghaf.extraGroups = [
"audio"
"video"
];

hardware.pulseaudio = {
enable = true;
extraConfig = ''
load-module module-tunnel-sink-new sink_name=comms-speaker server=audio-vm:4713 reconnect_interval_ms=1000
load-module module-tunnel-source-new source_name=comms-mic server=audio-vm:4713 reconnect_interval_ms=1000
'';
package = pkgs.pulseaudio-ghaf;
};

systemd = {
services = {
element-gps = {
Expand Down Expand Up @@ -110,4 +93,5 @@ in
}
];
borderColor = "#337aff";
ghafAudio.enable = true;
}

0 comments on commit 1733e08

Please sign in to comment.