Skip to content

Commit 23c038f

Browse files
kajusnaubrianmcgillion
authored andcommitted
audio: rework modules, forward pipewire socket to gui-vm
- introduced 'server' and 'client' configs - audio-vm is now the 'server', in charge of all audio hw - all other systems are now 'clients' - 'clients' can optionally enable pw socket forwarding - removed all audio-related configs from gui-vm/cosmic - removed ghaf-audio namespace - removed ghaf audio control tool, replaced by pavucontrol - re-enabled all sound-related settings in cosmic DE Signed-off-by: Kajus Naujokaitis <[email protected]>
1 parent 51a3943 commit 23c038f

File tree

27 files changed

+516
-383
lines changed

27 files changed

+516
-383
lines changed

modules/common/services/audio.nix

Lines changed: 0 additions & 131 deletions
This file was deleted.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# SPDX-FileCopyrightText: 2026 TII (SSRC) and the Ghaf contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
{
4+
pkgs,
5+
config,
6+
lib,
7+
...
8+
}:
9+
let
10+
useGivc = config.ghaf.givc.enable;
11+
cfg = config.ghaf.services.audio;
12+
host = "audio-vm";
13+
port =
14+
if cfg.client.pipewireControl.enable then
15+
cfg.server.pulseaudioTcpControlPort
16+
else
17+
cfg.server.pulseaudioTcpPort;
18+
address = "tcp:${host}:${toString port}";
19+
20+
in
21+
{
22+
options.ghaf.services.audio = {
23+
client = {
24+
remotePulseServerAddress = lib.mkOption {
25+
type = lib.types.str;
26+
default = address;
27+
defaultText = address;
28+
description = ''
29+
Address of the remote PulseAudio server to connect to.
30+
31+
This should point to the main Ghaf audio server.
32+
'';
33+
};
34+
pipewireControl = {
35+
enable = lib.mkEnableOption ''
36+
PipeWire control forwarding to gui-vm client.
37+
38+
This allows gui-vm to control audio settings via PipeWire.
39+
Requires givc to be enabled on both client and server.
40+
41+
To use it, set the `PIPEWIRE_RUNTIME_DIR` environment variable to /tmp.
42+
`PIPEWIRE_RUNTIME_DIR` can be set for the entire session but is not recommended,
43+
as it may interfere with local PipeWire instances.
44+
'';
45+
socket = lib.mkOption {
46+
type = lib.types.str;
47+
readOnly = true;
48+
default = "/tmp/pipewire-0";
49+
description = ''
50+
Path where the PipeWire socket is available for control operations.
51+
'';
52+
};
53+
};
54+
};
55+
};
56+
config = lib.mkIf (cfg.enable && (cfg.role == "client")) (
57+
lib.mkMerge [
58+
{
59+
environment = {
60+
systemPackages = [ pkgs.pulseaudio ];
61+
sessionVariables = {
62+
PULSE_SERVER = "${cfg.client.remotePulseServerAddress}";
63+
};
64+
variables = {
65+
PULSE_SERVER = "${cfg.client.remotePulseServerAddress}";
66+
};
67+
};
68+
}
69+
# givc socket proxy is declared in modules/givc/guivm.nix
70+
(lib.mkIf (cfg.client.pipewireControl.enable && useGivc) {
71+
assertions = [
72+
{
73+
assertion = config.system.name == "gui-vm";
74+
message = "PipeWire control forwarding can only be enabled on gui-vm.";
75+
}
76+
{
77+
assertion = useGivc;
78+
message = "GIVC must be enabled on audio clients when enabling Ghaf audio server control forwarding.";
79+
}
80+
];
81+
82+
environment = {
83+
systemPackages = with pkgs; [
84+
pipewire
85+
# `pwwvucontrol` is a good Rust-based alternative for pure PipeWire
86+
# but it lacks some features and polish compared to `pavucontrol`
87+
pavucontrol
88+
];
89+
};
90+
})
91+
]
92+
);
93+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: 2022-2026 TII (SSRC) and the Ghaf contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
{
4+
lib,
5+
...
6+
}:
7+
{
8+
imports = [
9+
./server.nix
10+
./client.nix
11+
];
12+
13+
options.ghaf.services.audio = {
14+
enable = lib.mkEnableOption "Enable Ghaf audio services";
15+
role = lib.mkOption {
16+
type = lib.types.enum [
17+
"server"
18+
"client"
19+
];
20+
default = "client";
21+
description = ''
22+
The role of this VM in the Ghaf audio topology.
23+
- "server" controls audio hardware and runs the main audio server
24+
- "client" connects to the audio server to play/record (and optionally control) audio
25+
'';
26+
};
27+
};
28+
}

0 commit comments

Comments
 (0)