‹ blog.suddaby.net

Tags / nixos


For a long time I was running piCorePlayer on my RaspberryPi 4 Model B with a HiFiBerry DAC+ Light without any problems. The little Pi 4, however, is capable of much more, so I decided to try to put NixOS on it. It wasn’t entirely straightforward.

The guide on the NixOS Wiki is pretty good for the first parts of the installation–flashing a MicroSD card with a recent image (I used 25.05), generating a config, and updating the firmware. Where it got trickier was trying to get the HiFiBerry DAC+ Light to be recognised.

First I had to add the nixos-hardware channel with the following commands:

$ sudo nix-channel --add https://github.com/NixOS/nixos-hardware/archive/master.tar.gz nixos-hardware
$ sudo nix-channel --update

Then add the following a line to the top of /etc/nixos/configuration.nix

  imports =
    [ # Include the results of the hardware scan.
  # The line just below adds the hardware repository so we can add the Hifiberry board
      <nixos-hardware/raspberry-pi/4>
      ./hardware-configuration.nix
    ];

The next step was the hard bit to figure out. A post on the NixOS hardware github was key (thank you, Ramblurr), though I had to change which DTS overlay I copied from as I have a DAC+ Light not the standard DAC+. This is what works for me in my configuration.nix:

  # I'm adding this to enable the HifiBerry DAC+ Light board. Overlays, urgh!

  hardware = {
    raspberry-pi."4".apply-overlays-dtmerge.enable = true;
    deviceTree = {
      enable = true;
      filter = "bcm2711-rpi-4*.dtb";
      overlays = [
        {
          name = "hifiberry-dac";
          dtsText = ''
// Definitions for HiFiBerry DAC
/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2711";

	fragment@0 {
		target = <&i2s_clk_producer>;
		__overlay__ {
			status = "okay";
		};
	};

	fragment@1 {
		target-path = "/";
		__overlay__ {
			pcm5102a-codec {
				#sound-dai-cells = <0>;
				compatible = "ti,pcm5102a";
				status = "okay";
			};
		};
	};

	fragment@2 {
		target = <&sound>;
		__overlay__ {
			compatible = "hifiberry,hifiberry-dac";
			i2s-controller = <&i2s_clk_producer>;
			status = "okay";
		};
	};
};
'';
   }
 ];
    };
  };

Then I could add the magical NixOS service line for squeezelite in configuration.nix:

  # Squeezelite, and the output sent to the Hifiberry.
  services.squeezelite.enable = true;
  services.squeezelite.extraArguments = "-o sysdefault:CARD=sndrpihifiberry";

And do the magic rebuild:

sudo nixos-rebuild switch

Then restart, and it should all work perfectly.

« Older posts Newer posts »