-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial AudioVM implementation with pipewire and pulseaudio
Initial version of AudioVM with Pipewire backend and pulseaudio TCP remote communication layer for the guest VMs. Note that this is not really secure design (yet) basically all VMs can access the pulseaudio TCP service. Signed-off-by: Jon Sahlberg <jon.sahlberg@unikie.com>
- Loading branch information
Showing
12 changed files
with
353 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,6 @@ | |
productId = "46a6"; | ||
} | ||
]; | ||
|
||
audio.pciDevices = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ | ||
config, | ||
lib, | ||
... | ||
}: let | ||
configHost = config; | ||
vmName = "audio-vm"; | ||
macAddress = "02:00:00:03:03:03"; | ||
audiovmBaseConfiguration = { | ||
imports = [ | ||
(import ./common/vm-networking.nix {inherit vmName macAddress;}) | ||
({ | ||
lib, | ||
pkgs, | ||
... | ||
}: { | ||
ghaf = { | ||
users.accounts.enable = lib.mkDefault configHost.ghaf.users.accounts.enable; | ||
profiles.debug.enable = lib.mkDefault configHost.ghaf.profiles.debug.enable; | ||
|
||
development = { | ||
ssh.daemon.enable = lib.mkDefault configHost.ghaf.development.ssh.daemon.enable; | ||
debug.tools.enable = lib.mkDefault configHost.ghaf.development.debug.tools.enable; | ||
nix-setup.enable = lib.mkDefault configHost.ghaf.development.nix-setup.enable; | ||
}; | ||
systemd = { | ||
enable = true; | ||
withName = "audiovm-systemd"; | ||
withNss = true; | ||
withResolved = true; | ||
withTimesyncd = true; | ||
withDebug = configHost.ghaf.profiles.debug.enable; | ||
}; | ||
}; | ||
|
||
environment = { | ||
systemPackages = [ | ||
pkgs.pulseaudio | ||
pkgs.pamixer | ||
pkgs.pipewire | ||
]; | ||
}; | ||
|
||
system.stateVersion = lib.trivial.release; | ||
|
||
nixpkgs.buildPlatform.system = configHost.nixpkgs.buildPlatform.system; | ||
nixpkgs.hostPlatform.system = configHost.nixpkgs.hostPlatform.system; | ||
|
||
microvm = { | ||
optimize.enable = true; | ||
vcpu = 1; | ||
mem = 256; | ||
hypervisor = "qemu"; | ||
shares = [ | ||
{ | ||
tag = "ro-store"; | ||
source = "/nix/store"; | ||
mountPoint = "/nix/.ro-store"; | ||
} | ||
]; | ||
writableStoreOverlay = lib.mkIf config.ghaf.development.debug.tools.enable "/nix/.rw-store"; | ||
qemu = { | ||
machine = | ||
{ | ||
# Use the same machine type as the host | ||
x86_64-linux = "q35"; | ||
aarch64-linux = "virt"; | ||
} | ||
.${configHost.nixpkgs.hostPlatform.system}; | ||
}; | ||
}; | ||
|
||
imports = [ | ||
../../../common | ||
]; | ||
|
||
# Fixed IP-address for debugging subnet | ||
systemd.network.networks."10-ethint0".addresses = [ | ||
{ | ||
addressConfig.Address = "192.168.101.5/24"; | ||
} | ||
]; | ||
}) | ||
]; | ||
}; | ||
cfg = config.ghaf.virtualization.microvm.audiovm; | ||
in { | ||
options.ghaf.virtualization.microvm.audiovm = { | ||
enable = lib.mkEnableOption "AudioVM"; | ||
|
||
extraModules = lib.mkOption { | ||
description = '' | ||
List of additional modules to be imported and evaluated as part of | ||
AudioVM's NixOS configuration. | ||
''; | ||
default = []; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
microvm.vms."${vmName}" = { | ||
autostart = true; | ||
config = | ||
audiovmBaseConfiguration | ||
// { | ||
imports = | ||
audiovmBaseConfiguration.imports | ||
++ cfg.extraModules; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
{ | ||
lib, | ||
pkgs, | ||
microvm, | ||
configH, | ||
... | ||
}: let | ||
# TCP port used by Pipewire-pulseaudio service | ||
pulseaudioTcpPort = 4713; | ||
|
||
audiovmPCIPassthroughModule = { | ||
microvm.devices = lib.mkForce ( | ||
builtins.map (d: { | ||
bus = "pci"; | ||
inherit (d) path; | ||
}) | ||
configH.ghaf.hardware.definition.audio.pciDevices | ||
); | ||
}; | ||
|
||
audiovmExtraConfigurations = { | ||
time.timeZone = "Asia/Dubai"; | ||
|
||
# Enable pipewire service for audioVM with pulseaudio support | ||
security.rtkit.enable = true; | ||
sound.enable = true; | ||
hardware.firmware = [pkgs.sof-firmware]; | ||
services.pipewire = { | ||
enable = true; | ||
pulse.enable = true; | ||
systemWide = true; | ||
}; | ||
|
||
services.pipewire.configPackages = [ | ||
(pkgs.writeTextDir "share/pipewire/pipewire.conf.d/10-remote-simple.conf" '' | ||
context.modules = [ | ||
{ name = libpipewire-module-protocol-pulse | ||
args = { | ||
server.address = [ | ||
"tcp:4713" # IPv4 and IPv6 on all addresses | ||
]; | ||
pulse.min.req = 128/48000; # 2.7ms | ||
pulse.default.req = 960/48000; # 20 milliseconds | ||
pulse.min.frag = 128/48000; # 2.7ms | ||
pulse.default.frag = 512/48000; # ~10 ms | ||
pulse.default.tlength = 512/48000; # ~10 ms | ||
pulse.min.quantum = 128/48000; # 2.7ms | ||
} | ||
} | ||
]; | ||
'') | ||
]; | ||
|
||
hardware.pulseaudio.extraConfig = '' | ||
# Set sink and source default max volume to about 75% (0-65536) | ||
set-sink-volume @DEFAULT_SINK@ 48000 | ||
set-source-volume @DEFAULT_SOURCE@ 48000 | ||
''; | ||
|
||
# Allow ghaf user to access pulseaudio and pipewire | ||
users.extraUsers.ghaf.extraGroups = ["audio" "video" "pulse-access" "pipewire"]; | ||
|
||
# Dummy service to get pipewire and pulseaudio services started at boot | ||
# Normally Pipewire and pulseaudio are started when they are needed by user, | ||
# We don't have users in audiovm so we need to give PW/PA a slight kick.. | ||
# This calls pulseaudios pa-info binary to get information about pulseaudio current | ||
# state which starts pipewire-pulseaudio service in the process. | ||
systemd.services.pulseaudio-starter = { | ||
after = ["pipewire.service" "network-online.target"]; | ||
requires = ["pipewire.service" "network-online.target"]; | ||
wantedBy = ["default.target"]; | ||
path = [pkgs.coreutils]; | ||
enable = true; | ||
serviceConfig = { | ||
User = "ghaf"; | ||
Group = "ghaf"; | ||
}; | ||
script = ''${pkgs.pulseaudio}/bin/pa-info > /dev/null 2>&1''; | ||
}; | ||
|
||
# Open TCP port for the PDF XDG socket | ||
networking.firewall.allowedTCPPorts = [pulseaudioTcpPort]; | ||
|
||
microvm.qemu.extraArgs = [ | ||
]; | ||
microvm.kernelParams = [ | ||
"snd_intel_dspcfg.dsp_driver=3" | ||
"snd_sof_intel_hda_common.dmic_num=4" | ||
]; | ||
}; | ||
in [ | ||
audiovmPCIPassthroughModule | ||
audiovmExtraConfigurations | ||
] |
Oops, something went wrong.