main
 1{
 2  flake.modules.nixos.desktop = {pkgs, ...}: {
 3    environment.systemPackages = with pkgs; [
 4      pulseaudio # provides `pactl`, which is required by some apps(e.g. sonic-pi)
 5    ];
 6
 7    # PipeWire is a new low-level multimedia framework.
 8    # It aims to offer capture and playback for both audio and video with minimal latency.
 9    # It support for PulseAudio-, JACK-, ALSA- and GStreamer-based applications.
10    # PipeWire has a great bluetooth support, it can be a good alternative to PulseAudio.
11    #     https://nixos.wiki/wiki/PipeWire
12    services.pipewire = {
13      enable = true;
14      # package = pkgs.pipewire;
15      alsa.enable = true;
16      alsa.support32Bit = true;
17      pulse.enable = true;
18      # If you want to use JACK applications, uncomment this
19      jack.enable = true;
20      wireplumber.enable = true;
21    };
22    # rtkit is optional but recommended
23    security.rtkit.enable = true;
24    # Disable pulseaudio, it conflicts with pipewire too.
25    services.pulseaudio.enable = false;
26
27    services.pipewire.extraConfig.pipewire."99-fix-lagging" = {
28      "context.properties" = {
29        "default.clock.rate" = 48000;
30        "default.clock.quantum" = 512;
31        "default.clock.min-quantum" = 512;
32        "default.clock.max-quantum" = 512;
33      };
34    };
35  };
36}