How to install nix package manager on Raspbian?

Hi all,

I’d like to play with Nix on my Raspberry Pi, but have already installed and set up Raspbian. Because of this I would like to just install the the package manager.

For a long shot I just tried running the install instructions from Nix & NixOS | Reproducible builds and deployments, but was told there was no binary distribution for my platform. I can see the RPi is supported in some form from NixOS on ARM/Raspberry Pi - NixOS Wiki.

Is there a way to just get the package manager for ARM/RPi?

Thanks!

1 Like

If I remember correctly, for armv7l the only way to get Nix would be to compile it from the source, and compiling from source requires a patch for armv7l.

This used to work, not sure anymore:
https://nixos.wiki/wiki/Nix_on_ARM

Thanks for the answers!

@eadwu Is there a way to set up a cross-compile environment?

@tom I’m unsure how to use the code on that page, do you have any pointers?

There’s been some very recent work on getting cross-compilation working well for NixOS. I was able to use this configuration to cross-compile to a Raspberry Pi Zero W:

1 Like

Thanks you! It looks like that code will cross-compile all of NixOS? Do you have any pointers for just compiling the Nix package manager?

1 Like

I haven’t tried it but taking the crossSystem part might be enough:

let
  lib =
    (import <nixpkgs> { }).lib;
  crossPkgs =
    import <nixpkgs> {
      crossSystem =
        lib.systems.elaborate lib.systems.examples.raspberryPi;
    };
in
crossPkgs.nix

This is not easy to do right now. Someone had a PR to make this easier here:

https://github.com/NixOS/nixpkgs/pull/51626

But it hasn’t been reviewed, and I’m a little bit hesitant to merge it as is. If anyone can review that, it would make this process much easier! We could add it as a job for cross-trunk, and you would just download it from:

https://hydra.nixos.org/jobset/nixpkgs/cross-trunk#tabs-jobs

Unfortunately Nix is broken right now in cross-trunk:

https://hydra.nixos.org/job/nixpkgs/cross-trunk/rpi.nix.x86_64-linux

Any fixes for that would be greatly appreciated!

It seems that adding libatomic_ops as a dependency was all that was needed to cross-compile Nix (or at least finish the build)? Though I’m not sure how the conditional would look like since it seems native compilation works fine without it.

~ took 1m 36s
➜ nix build -f "<nixpkgs>" pkgsCross.raspberryPi.nix
[1 built, 2 copied (0.6 MiB), 0.1 MiB DL]

~ took 1m 49s
➜ nix build -f "<nixpkgs>" pkgsCross.aarch64-multiplatform.nix
[25 built, 22 copied (927.7 MiB), 180.5 MiB DL]

~ took 16m 9s
➜

1 Like

So any straightforward way for doing this now?

1 Like

After a weekend deep dive into the Nix arm world I finally managed to build a release tarball of nix which can be installed on Raspberry Pi OS / Raspbian or any other armv7l based linux.

I published the binary + instructions here: GitHub - DavHau/nix-on-armv7l: Nix without NixOS on arm32v7 / armv7l / Raspberry Pi OS / Raspbian

The build was done on a raspberry with Raspberry Pi OS running a docker container of debian testing.
→ see Dockerfile in the repo
This is only possible because there is now a nix package available in the debian-testing repo. This nix version is used inside docker to compile a proper nix binary tarball for armv7l.

It really was a long way to figuring that out. It would be much simpler if either an official armv7l release of nix or a working cross build recipe would exist. Both is not the case. But there are open PRs like for example this one.
If someone could push this forward it would be amazing.

3 Likes

I just found out that armv7l isn’t required anymore for modern Raspberry PI OS versions. One can just switch them to aarch64 with one single config option. See here: Pi4 64-bit raspbian kernel for testing - Focus on Pi4 - Raspberry Pi Forums

Afterwards just use the official aarch64 version of nix. If nix doesn’t detect the platform correctly. add a system = aarch64-linux to /etc/nix/nix.conf.

Aarch64 is officially supported by nix and has full availability via official binary cache. Therefore this is definitely the better option compared to messing around with armv7l.

Probably this should go into the wiki.

1 Like

@DavHau Thank you so much for posting this! Building Nix myself seemed like too much effort for too little reward, but now that I’ve switched to AArch64, I don’t have to :slight_smile:

For whatever it’s worth, I found this guide on switching to AArch64 to be easier to follow than that forum post.

1 Like