Snapcast: Difference between revisions

imported>Mweinelt
m Add audio category
Minor changes after reworking my configuration
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:


https://github.com/badaix/snapcast
https://github.com/badaix/snapcast
Note that MPD can directly act as a Snapcast audio source (see https://mpd.readthedocs.io/en/stable/plugins.html#snapcast). However, it does not provide all features of a Snapcast server such as the web interface.


== Pipewire Sink ==
== Pipewire Sink ==
Line 12: Line 14:
First create a local snapserver instance that creates the FIFO queue to stream into.
First create a local snapserver instance that creates the FIFO queue to stream into.


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
   services.snapserver = {
   services.snapserver = {
     enable = true;
     enable = true;
     codec = "flac";
     settings = {
    streams = {
       stream.source = "pipe:///run/snapserver/pipe?name=NAME";
       pipewire  = {
        type = "pipe";
        location = "/run/snapserver/pipewire";
      };
     };
     };
    openFirewall = true;
   };
   };
</syntaxHighlight>
</syntaxhighlight>


Then create a systemd user unit to attach the pipe-sink after pipewire has started.
Tell Pipewire about the sink used by Snapcast.


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
   systemd.user.services.snapcast-sink = {
   services.pipewire.extraConfig.pipewire-pulse."40-snapcast-sink" = {
     wantedBy = [
     "pulse.cmd" = [
      "pipewire.service"
       {
    ];
        cmd = "load-module";
    after = [
        args = "module-pipe-sink file=/run/snapserver/pipe sink_name=Snapcast format=s16le rate=48000";
       "pipewire.service"
       }
    ];
    bindsTo = [
      "pipewire.service"
    ];
    path = with pkgs; [
      gawk
       pulseaudio
     ];
     ];
    script = ''
      pactl load-module module-pipe-sink file=/run/snapserver/pipewire sink_name=Snapcast format=s16le rate=48000
    '';
   };
   };
</syntaxHighlight>


</syntaxhighlight>


There is a new direct connection of Pipewire with Snapcast in the making. However, as of March 16, 2026, the version of Pipewire in Nixpkgs (1.4.X) does not support this new feature yet (available starting with Pipewire version 1.6.0).
== Playback ==
== Playback ==


To have local audio synced up with remote clients it needs to be routed through a local snapclient instance.
To have local audio synced up with remote clients it needs to be routed through a local snapclient instance.


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
   systemd.user.services.snapclient-local = {
   systemd.user.services.snapclient-local = {
     wantedBy = [
     wantedBy = [
Line 62: Line 52:
     ];
     ];
     serviceConfig = {
     serviceConfig = {
       ExecStart = "${pkgs.snapcast}/bin/snapclient -h ::1";
       ExecStart = "${pkgs.snapcast}/bin/snapclient --player pipewire tcp://localhost:1704";
     };
     };
   };
   };
</syntaxHighlight>
</syntaxhighlight>


[[Category:Audio]]
[[Category:Audio]]