Unix ignoramus here, but functional programming enthusiast.
I was made aware of NixOS a few months ago and really liked the idea of it.
If I ever get around to firing up a *nix computer, I think I would like to try this.
Has anyone ever installed on a Raspberry Pi 4?
Personally, I only installed Nix on my RPi4 with Raspbian. One thing I had to do to make it work was to switch Raspbian to a 64-bit kernel image. There’s some (theoretically experimental, yet it worked flawlessly for me) flag for this; if I found the right one, I believe you need to put arm_64bit=1 in the RPi4’s /boot/config.txt, then reboot.
Please note, that if you’ve never used Unix/Linux at all before, starting from NixOS might be a rather deep dive. Say, akin to learning car driving by buying a battered used 4x4 and having it delivered into your backyard. It’s definitely doable, and if you like experimenting you’ll definitely have tons of fun and learn a lot, though don’t be surprised if many people might say it’s not the easiest nor most typical way to do that. Depending on what is your vision of fun, you might want to consider going with Ubuntu/Raspbian first, if you prefer smaller and safer steps (i.e. learning in a Chevvy at a driving school) - or, it might be exactly the path to pick if you do like crazy hacker adventure :D (Personally, somewhat recently I did a for-fun project of assembling Android .apk files by hand from scratch, byte by byte, so I can totally relate if you’d like to choose the crazy way ;P)
Increase sdImage.firmwareSize from 128 to something like 1024 if your SD card has the space. If you don’t know what you’re doing you’ll probably want to nixos-rebuild switch a few times which can consume more than the default.
Prefer to use the AWS ARM instance support via packer if possible - it’s a lot faster than using QEMU. My (very rough) cost estimate is somewhere between 20-40 cents (Euro).
if you’re using a Pi 4 then make sure you read the instructions thoroughly for Pi 4 specifics. Mainly setting DISABLE_ZFS_IN_INSTALLER=y for build speed and NIXPKGS_BRANCH=master so it works and you don’t just get a very smol Christmas tree with blinking lights.
If you’re using packer you can directly add access_key and secret_key to the amazon-ebs source, like so:
I bought the 8gig model in september, it wouldn’t boot at all. Bought a 4gig model, booted same sd card I created and it worked fine, popped carg back in the 8 and then that booted. You should be ok now as the firmware is more up to date and you can always install a newer firmware but the 8g pi 4 is a bit weird. And not just with nixos i’ve seen lots of reports of similar from other people on the pi forums.
Other than that caveat it works fine, one thing i have to try out is the usb boot from the latest firmware and ditch sd cards entirely for these little pi’s.
I used NixOS for about a week, until I wanted to set up a python virtualenv to quickly hack on some project. Venvs fundamentally break the NixOS philosophy, and required some ungodly amount of hacks/arcane nix package stuff to get kinda working. I gave up. In hindsight I could have setmup a VM, but ffs that seems overkill.
NixOS doesn’t do anything to prevent you from using venvs. I often use a venv in a nix shell that has the necessary C dependencies for my Python. There is even a venvDir helper for mkShell derivations that automagically makes a venv for your nix shell.
It may not do anything to prevent you from using them, but I feel like every time I want to use a new language and its packages, (because I am still not the best at Nix) I have to read a bunch of documents and find a third party application that automates things, like mach-nix.
I love NixOS, but it is really annoying when I want to do something that on other OSes is really easy, like installing some software from npm, and it takes me multiple hours of document reading and tool testing. And then some more complex packages still don’t run well, like rpy2 for me.
Hopefully this would all be easier when the documentation gets better and I get better at Nix.
I understand where you’re coming from, it’s a kind of red herring: There is a lot of effort to programmatically convert all package management into idiomatic nix store stuff. I think this is a laudable effort but it’s not a requirement for everyone to use! This part is not obvious.
The first thing any developer does is search “how do I use X language in nix?” and of course we’ll find a lot of efforts to convert that language’s ecosystem into the nix ecosystem. I want to categorically say: It’s okay to ignore these. It’s okay to ignore pip2nix, it’s okay to ignore node2nix, etc.
One of the best parts of nix is it’s still very usable in an incremental way. It’s okay to use as much or as little of it as is helpful, and we can always migrate to more nix-ification as the need arises. :)
This might be a silly question. If I am on NixOS is there a way to “cheat” and install a python package the “normal” pip way (without combing through a bunch of Nix documentation)? If I were on Debian+Nix I would be able to, but on NixOS I could not find a way to “cheat” and do things the traditional way.
Perhaps I should go back to a “normal” Linux distro and use Nix incrementally until I am more proficient and then come back to NixOS.
Ah, I think I know what problem you’re having! Were you using a venv?
In Python, it’s generally discouraged to install things globally (sudo pip install foo). It’s still possible in most distros, but NixOS will prevent you because that part of the filesystem is marked as read-only.
The idiomatic way to use Python, regardless of distro: python -m venv to create a virtualenv (basically a “container” for this project’s dependencies), then activate it source ./venv/bin/activate – you can specify a different directory, too. Try python -m venv --help for more.
This is particularly important since pip is not able to handle multiple versions of the same dependency well, so it’s best to maintain one venv per project.
With that approach, it shouldn’t matter whether you’re using NixOS or Debian or whatever.
Oh, I did not know that venvs would work well in NixOS. Tbh I forget what I tried before moving to MachNix, but it is great to know that a simple venv would have solved my issue. I really appreciate the reply!
Unix ignoramus here, but functional programming enthusiast. I was made aware of NixOS a few months ago and really liked the idea of it. If I ever get around to firing up a *nix computer, I think I would like to try this. Has anyone ever installed on a Raspberry Pi 4?
I seem to have something about NixOS on RPi4 in my bookmarks: https://lobste.rs/s/pdkwcq/nixos_on_raspberry_pi_creating_custom_sd - though I haven’t tried that myself.
Personally, I only installed Nix on my RPi4 with Raspbian. One thing I had to do to make it work was to switch Raspbian to a 64-bit kernel image. There’s some (theoretically experimental, yet it worked flawlessly for me) flag for this; if I found the right one, I believe you need to put
arm_64bit=1
in the RPi4’s/boot/config.txt
, then reboot.Please note, that if you’ve never used Unix/Linux at all before, starting from NixOS might be a rather deep dive. Say, akin to learning car driving by buying a battered used 4x4 and having it delivered into your backyard. It’s definitely doable, and if you like experimenting you’ll definitely have tons of fun and learn a lot, though don’t be surprised if many people might say it’s not the easiest nor most typical way to do that. Depending on what is your vision of fun, you might want to consider going with Ubuntu/Raspbian first, if you prefer smaller and safer steps (i.e. learning in a Chevvy at a driving school) - or, it might be exactly the path to pick if you do like crazy hacker adventure :D (Personally, somewhat recently I did a for-fun project of assembling Android .apk files by hand from scratch, byte by byte, so I can totally relate if you’d like to choose the crazy way ;P)
I build SSH-enabled SD images for screen/keyboard-less installation via: https://github.com/Robertof/nixos-docker-sd-image-builder
Someone helpfully provided step-by-step instructions for the builder here: https://gist.github.com/chrisanthropic/2e6d3645f20da8fd4c1f122113f89c06
Things I tripped over initially:
sdImage.firmwareSize
from128
to something like1024
if your SD card has the space. If you don’t know what you’re doing you’ll probably want to nixos-rebuild switch a few times which can consume more than the default.DISABLE_ZFS_IN_INSTALLER=y
for build speed andNIXPKGS_BRANCH=master
so it works and you don’t just get a very smol Christmas tree with blinking lights.access_key
andsecret_key
to theamazon-ebs
source, like so:A word of warning on the new 4b with https://github.com/Robertof/nixos-docker-sd-image-builder
I bought the 8gig model in september, it wouldn’t boot at all. Bought a 4gig model, booted same sd card I created and it worked fine, popped carg back in the 8 and then that booted. You should be ok now as the firmware is more up to date and you can always install a newer firmware but the 8g pi 4 is a bit weird. And not just with nixos i’ve seen lots of reports of similar from other people on the pi forums.
Other than that caveat it works fine, one thing i have to try out is the usb boot from the latest firmware and ditch sd cards entirely for these little pi’s.
I’ve used it for two different 8GB Pi 4s in the past month - apart from forgetting to set
NIXPKGS_BRANCH=master
I’ve had no other problems.I used NixOS for about a week, until I wanted to set up a python virtualenv to quickly hack on some project. Venvs fundamentally break the NixOS philosophy, and required some ungodly amount of hacks/arcane nix package stuff to get kinda working. I gave up. In hindsight I could have setmup a VM, but ffs that seems overkill.
Guix has ‘profiles’, which sound like they might provide a non-hackish way to do that: https://guix.gnu.org/cookbook/en/html_node/Guix-Profiles-in-Practice.html
NixOS doesn’t do anything to prevent you from using venvs. I often use a venv in a nix shell that has the necessary C dependencies for my Python. There is even a
venvDir
helper formkShell
derivations that automagically makes a venv for your nix shell.More on this here: https://nixos.org/manual/nixpkgs/stable/#python
Ok. That looks like a vast improvement over what I recall when I last looked at it.
It may not do anything to prevent you from using them, but I feel like every time I want to use a new language and its packages, (because I am still not the best at Nix) I have to read a bunch of documents and find a third party application that automates things, like mach-nix.
I love NixOS, but it is really annoying when I want to do something that on other OSes is really easy, like installing some software from npm, and it takes me multiple hours of document reading and tool testing. And then some more complex packages still don’t run well, like rpy2 for me.
Hopefully this would all be easier when the documentation gets better and I get better at Nix.
I understand where you’re coming from, it’s a kind of red herring: There is a lot of effort to programmatically convert all package management into idiomatic nix store stuff. I think this is a laudable effort but it’s not a requirement for everyone to use! This part is not obvious.
The first thing any developer does is search “how do I use X language in nix?” and of course we’ll find a lot of efforts to convert that language’s ecosystem into the nix ecosystem. I want to categorically say: It’s okay to ignore these. It’s okay to ignore pip2nix, it’s okay to ignore node2nix, etc.
One of the best parts of nix is it’s still very usable in an incremental way. It’s okay to use as much or as little of it as is helpful, and we can always migrate to more nix-ification as the need arises. :)
This might be a silly question. If I am on NixOS is there a way to “cheat” and install a python package the “normal” pip way (without combing through a bunch of Nix documentation)? If I were on Debian+Nix I would be able to, but on NixOS I could not find a way to “cheat” and do things the traditional way.
Perhaps I should go back to a “normal” Linux distro and use Nix incrementally until I am more proficient and then come back to NixOS.
Ah, I think I know what problem you’re having! Were you using a venv?
In Python, it’s generally discouraged to install things globally (
sudo pip install foo
). It’s still possible in most distros, but NixOS will prevent you because that part of the filesystem is marked as read-only.The idiomatic way to use Python, regardless of distro:
python -m venv
to create a virtualenv (basically a “container” for this project’s dependencies), then activate itsource ./venv/bin/activate
– you can specify a different directory, too. Trypython -m venv --help
for more.This is particularly important since pip is not able to handle multiple versions of the same dependency well, so it’s best to maintain one venv per project.
With that approach, it shouldn’t matter whether you’re using NixOS or Debian or whatever.
Oh, I did not know that venvs would work well in NixOS. Tbh I forget what I tried before moving to MachNix, but it is great to know that a simple venv would have solved my issue. I really appreciate the reply!
You’re very welcome. :) Hit me up if you run into more problems.
I use venvs all the time for hacking on stuff outside of nix when i don’t care about being so pendantic.
pedantic**
Huh, this sounds very similar to what I use for Emacs with use-package.