{ config, lib, pkgs, ... }:
{
  config = lib.mkIf config.services.icecast.enable {
    services.liquidsoap.streams = {
      nixscrap = pkgs.writeText "nixscrap" ''
        settings.log.stdout.set(true)
        settings.init.allow_root.set(true)
        settings.scheduler.fast_queues.set(2)
        
        stream = mksafe(playlist(mode='randomize', reload=1, reload_mode="rounds", "/storage/Music/Scrap"))
        stream_fallback = fallback([stream, stream])
        
        output.icecast(
          %ffmpeg(format="ogg", %audio(codec="libvorbis", samplerate=48000, b="256k", channels=2)),
          host="127.0.0.1",
          port=${toString config.services.icecast.listen.port},
          password="${config.secrets.cast.sourcePass}",
          encoding = "UTF-8",

          name="NixBops Scrap",
          genre="Scrapped",
          description="Music canned from the main radio.",
          mount="nixscrap.opus",
          icy_metadata=["artist", "title"],
          public=true,

          stream_fallback
        )
      '';
    };

    # Avoid the most stupid error imaginable
    systemd.services.nixscrap = {
      after = [ "network-online.target" ];
      wants = [ "network-online.target" ];
    };
  };
}
