Switching from pulseaudio to pipewire on nixos

I was having a hard time enabling pipewire (and turning off pulseaudio).

In my /etc/nixos/configuration.nixfile I disabled pulseaudio with hardware.pulseadio.enable = false; But, when I then run nixos-rebuild build I still see pulseaudio in the process list.

I was following this guide and have the pipewire config added: https://nixos.wiki/wiki/PipeWire

# rtkit is optional but recommended
security.rtkit.enable = true;
services.pipewire = {
  enable = true;
  alsa.enable = true;
  alsa.support32Bit = true;
  pulse.enable = true;
  # If you want to use JACK applications, uncomment this
  jack.enable = true;

  # use the example session manager (no others are packaged yet so this is enabled by default,
  # no need to redefine it in your config for now)
  #media-session.enable = true;
};
services.pipewire  = {
  media-session.config.bluez-monitor.rules = [
    {
      # Matches all cards
      matches = [ { "device.name" = "~bluez_card.*"; } ];
      actions = {
        "update-props" = {
          "bluez5.reconnect-profiles" = [ "hfp_hf" "hsp_hs" "a2dp_sink" ];
          # mSBC is not expected to work on all headset + adapter combinations.
          "bluez5.msbc-support" = true;
          # SBC-XQ is not expected to work on all headset + adapter combinations.
          "bluez5.sbc-xq-support" = true;
        };
      };
    }
    {
      matches = [
        # Matches all sources
        { "node.name" = "~bluez_input.*"; }
        # Matches all outputs
        { "node.name" = "~bluez_output.*"; }
      ];
      actions = {
        "node.pause-on-idle" = false;
      };
    }
  ];
};

I then ran nixos-rebuild switch.

I see this error: creating symlink from ‘/nix/var/nix/profiles/system-3-link.tmp-14561-720987748’ to ‘/nix/store/wazaxcb3b78cwwqjx2p2wxp9nj4l7fgq-nixos-system-nixos-21.05.4132.24528474d2b’: Permission denied

sudo nixos-rebuild switch seemed to fix that. Running with sudo fixed that error, but still no pipewire in the process list.

I still was seeing pulseaudio in there:

123chrisda+    1542  0.0  0.0 1501000 14136 ?       S<sl 17:18   0:01 /nix/store/4kwkchzb9bf6y9wh2rji03sza8mr57ij-pulseaudio-14.2/bin/pulseaudio --daemonize=no --log-target=journal
chrisda+    1622  0.0  0.0 240420  8388 ?        Sl   17:18   0:00 /nix/store/4kwkchzb9bf6y9wh2rji03sza8mr57ij-pulseaudio-14.2/libexec/pulse/gsettings-helper
chrisda+   15699  0.0  0.0 223452  2324 pts/3    S+   18:03   0:00 grep pulseaudio

Then, I rebooted. And it all worked!