How to install nix package manager on Raspbian?


#1

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 https://nixos.org/nix/, but was told there was no binary distribution for my platform. I can see the RPi is supported in some form from https://nixos.wiki/wiki/NixOS_on_ARM/Raspberry_Pi.

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

Thanks!


#2

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.


#3

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


#4

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?


#5

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:


#6

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?


#8

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

#9

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

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!


#10

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
➜