anchor.diff:      environment.etc."alsa/conf.d/50-pipewire.conf" = mkIf cfg.alsa.enable {
         source = "${pkgs.pipewire}/share/alsa/alsa.conf.d/50-pipewire.conf";
       };
  -    environment.sessionVariables.LD_LIBRARY_PATH = [ "/run/current-system/sw/lib/pipewire" ];
  +    environment.sessionVariables.LD_LIBRARY_PATH =
  +      lib.optional (cfg.alsa.enable || cfg.jack.enable || cfg.pulse.enable) "/run/current-system/sw/lib/pipewire";
     };
   }
  
positive.code:       };
  
        alsa = {
          enable = mkOption {
            default = false;
            type = types.bool;
            description = ''
              Route audio to/from generic ALSA-using applications via the ALSA PIPEWIRE PCM plugin.
            '';
          };
  
          support32Bit = mkOption {
            default = false;
            type = types.bool;
            description = ''
              Whether to support sound for 32-bit ALSA applications on a 64-bit system.
            '';
          };
        };
  
        jack = {
          enable = mkOption {
            default = false;
            type = types.bool;
            description = ''
              Enable transparent JACK audio emulation using LD_LIBRARY_PATH.
            '';
          };
        };
  
        pulse = {
          enable = mkOption {
            default = false;
            type = types.bool;
            description = ''
              Enable transparent PulseAudio emulation using LD_LIBRARY_PATH.
            '';
          };
        };
      };
    };
  
negative.code: 
    ###### implementation
    config = mkIf cfg.enable {
      assertions = [
        {
          assertion = cfg.pulse.enable -> !config.hardware.pulseaudio.enable;
          message = "PipeWire based PulseAudio emulation doesn't use the PulseAudio service";
        }
        {
          assertion = cfg.jack.enable -> !config.services.jack.jackd.enable;
          message = "PIpeWire based JACK emulation doesn't use the JACK service";
        }
      ];
  
      environment.systemPackages = [ pkgs.pipewire ]
                                   ++ lib.optional cfg.jack.enable jack-libs
                                   ++ lib.optional cfg.pulse.enable pulse-libs;
  
      systemd.packages = [ pkgs.pipewire ];
  
      # PipeWire depends on DBUS but doesn't list it. Without this booting
      # into a terminal results in the service crashing with an error.
      systemd.user.sockets.pipewire.wantedBy = lib.mkIf cfg.socketActivation [ "sockets.target" ];
      systemd.user.services.pipewire.bindsTo = [ "dbus.service" ];
      services.udev.packages = [ pkgs.pipewire ];
  