Skip to content

Instantly share code, notes, and snippets.

@amazingidiot
Created August 14, 2021 09:56
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amazingidiot/5cdd9fd08d9817154aafc15286719f62 to your computer and use it in GitHub Desktop.
Save amazingidiot/5cdd9fd08d9817154aafc15286719f62 to your computer and use it in GitHub Desktop.
Pipewire virtual devices as systemd user services

Create pipewire virtual devices as systemd user services

Add both files to ~/.config/systemd/user/ and enable them via systemctl --user enable --now pipewire-source-stereo@sourcename.service or systemctl --user enable --now pipewire-sink-stereo@sinkname.service. Change sourcename and sinkname in the command to your needs. You can add multiple devices with different names.

[Unit]
Description = Add a pipewire stereo sink named %i
After = pipewire.service
[Service]
Type = oneshot
StandardOutput = journal
ExecStart = /bin/sh -c 'pactl load-module module-null-sink media.class=Audio/Sink sink_name="%i" channel_map=stereo > %h/.cache/pipewire_sink_stereo_%i'
ExecStopPost = -/bin/sh -c 'pactl unload-module $(cat %h/.cache/pipewire_sink_stereo_%i)'
ExecStopPost = -/bin/rm %h/.cache/pipewire_sink_stereo_%i
RemainAfterExit = true
[Install]
WantedBy = default.target
[Unit]
Description = Add a pipewire stereo source named %i
After = pipewire.service
[Service]
Type = oneshot
StandardOutput = journal
ExecStart = /bin/sh -c 'pactl load-module module-null-sink object.linger=1 media.class=Audio/Source/Virtual sink_name="%i" channel_map=stereo > %h/.cache/pipewire_source_stereo_%i'
ExecStopPost = -/bin/sh -c 'pactl unload-module $(cat %h/.cache/pipewire_source_stereo_%i)'
ExecStopPost = -/bin/rm %h/.cache/pipewire_source_stereo_%i
RemainAfterExit = true
[Install]
WantedBy = default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment