Nothing wrong really, you just need to run nix-channel --update to download the channel.
Alternatively, you could import ${modulesPath}/installer/cd-dvd/channel.nix, which will copy the channel into the image, so you don’t need to download it later.
/nix/store/9daif9c2pmwa7hwnzrazkxi6nykrl0v3-extlinux-conf-builder.sh: line 138: cd: /nix/var/nix/profiles: No such file or directory
Preparing store paths for image...
Creating an EXT4 image of 1744146432 bytes (numInodes=107152, numDataBlocks=211513)
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 425817 4k blocks and 106496 inodes
Filesystem UUID: 44444444-4444-4444-8888-888888888888
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Copying files into the device: ext2fs_symlink: Could not allocate inode in ext2 filesystem while creating symlink "coreutils"
__populate_fs: Could not allocate inode in ext2 filesystem while writing symlink"coreutils"
mkfs.ext4: Could not allocate inode in ext2 filesystem while populating file system
However running nix-channel --update works, but it takes a while. Then I’am able to run the nix-shell -p hello command, but it builds a lot of things from scratch because there are a lot of gcc processes shown when I run top in a second tty.
So I’m now asking me a few things:
how can I fix the channel error from above by importing it directly into the image to speed up things?
how can I include some packages like hello or python already when I build the image so that they don’t need to be compiled on the rpi itself?
If I include things like users, service configurations, … in the sd-image build flake, is that included later in the sd-image, and where do I find the nix configuration file defining that in the sd image? (I couldn’t find anything like that in /etc/nix or /etc/nixos). And is that even necessary when I’m not planning on rebuilding the system on the device directly?
Sorry if those questions sound easy, I am currently trying to get my first nixos system running. And again, thank you really much for your great help, really appreciate it.
I’m not sure: it may be that this module is slightly incompatible with the sd image builder. It’s normally used for the installer image.
but it builds a lot of things from scratch because there are a lot of gcc processes
That’s unfortunately expected: there is no binary cache at all for armv6, so any package not included in the image will have to be built.
how can I fix the channel error from above by importing it directly into the image to speed up things?
No idea, sorry.
how can I include some packages like hello or python already when I build the image so that they don’t need to be compiled on the rpi itself?
Just add them to environment.systemPackages, like you normally would for NixOS.
If I include things like users, service configurations, … in the sd-image build flake, is that included later in the sd-image
Yes, you’re essentially building a normal system (in the /run/current-system directory sense), but the result and all its dependencies are collected into a compressed archive (the image).
and where do I find the nix configuration file defining that in the sd image? (I couldn’t find anything like that in /etc/nix or /etc/nixos). And is that even necessary when I’m not planning on rebuilding the system on the device directly?
No, it’s not necessary if you don’t plan on editing the configuration later (and running nixos-rebuild).
What I do is: I write a typical configuration.nix file, import the image builder module, build the image, flash unto the SD card and plug it in the raspberry pi. On the first boot the image will even auto-expand to fill the whole card, so it will look like a normal install.
Thank you very much for your help and being patient with me. Installing packages like python through environment.systemPackages already works now. I also think I understood a bit further how the sd image and the configuration.nix works.
I’m now trying to get i2c working, so first I added the i2c-tools package, build and bootet, but the command i2c-detect -y 1 now shows me this error (also tested with sudo):
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory"
So I thought that maybe i2c is not enabled.
First I tried adding this device tree overlay to my flake, but I still get the same error:
Thank you very much for your help and being patient with me. Installing packages like python through environment.systemPackages already works now. I also think I understood a bit further how the sd image and the configuration.nix works.
No problem, I’m glad to be of help.
Do you got i2c working on your model B or have any idea what I could try next?
I have never really tried i2c. I used SPI to flash chips but that was some time back, so I don’t remember whether I was using NixOS or alarm.
IIRC the dtparam options won’t work because they are a feature of the raspberry pi bootloader, but we are using uboot. So, the right approach is to use a device tree overlay, as in your first attempt.
I gave a quick look at the dtb (if you build linuxPackages_rpi1.kernel, you can inspect the tree with nix run -f '<nixpkgs>' dtc result/dtbs/bcm2835-rpi-zero-w.dtb) and I think something like this should work:
Thanks for your help. Trying your provided device tree doesn’t work. Reading the pin assignments from the bcm2835 datasheet it seems like i2c1 should be right one, because the pins 2,3 (these are what I’m using, already tested with raspberry pi os) are named SDA1 and SCL1. GPIO0 and 1 have the SDA0 and SCL0 label. But either way, shouldn’t there be a /dev/i2c* file or directory which I never saw with nixos.
What syntax is that dts actually? It looks really weird to me. And where do you have that &i2c1 thing from? Why is that outside of the compatible scope? I can’t find something like that on the internet.
I now played a bit further with the dts by actually extracting the dtb files from the second partition and converting them to dts files using nix run -f '<nixpkgs>' dtc m/boot/nixos/<some-hash>-device-tree-overlays/bcm2835-rpi-zero-w.dtb > current.dts and found out that:
if I use your provided device tree overlay there is no diff in the dts file to just using nothing.
if I use the device tree overlay (I now found the source again, I just used the one from the rpi4 on the nixpgs and adjusted the chip) from my first post about it (post #16), I get the following diff compared to just adding nothing. But this still not works:
I then tried to manually modify the dtb file in the image by mounting the image, converting it to a dts file, applying the following patch and compiling it back with the following command. Then I moved it into the image, unmounted and tried to boot it. I then also verified that uboot showed the loading of the correct .dtb file on boot.
What syntax is that dts actually? It looks really weird to me.
It seems to be a syntactic sugar12 that has been available for a while, but few people have picked it up. Anyway, this is what the kernel docs tell you to write, now.
And where do you have that &i2c1 thing from?
I took the label from the base device tree: you can dump it as I said before.
Why is that outside of the compatible scope? I can’t find something like that on the internet.
I suppose it’s to avoid repeating it for every property being changes. I can
assure you it’s correct: i have several overlays written like this (enabling
audio, gpu, etc.)
I don’t remember where I first learned about overlays, probably from someone in #nixos-on-arm:nixos.org. You should try asking there, because I think this is as far as I can go.
But also that way, there is no /dev/i2c* so the i2cdetect command fails. Do you have any idea how I can get that to work?
I don’t know, AFAIK hardware.i2c.enable = true is all you should need to get the i2c devices set up.
Hello. Thank you for this great topic.
So I decided to try build my own image for rpi zero w.
I basically used provided flake and try to compile on aws aarch64 machine.
However, without luck.
System is 23.11 and this issue (unable to unpack archive) seems to be weird.
What I missed? NixOS on aws is just some random selected comunity ami so maybe should I start to dig here?
error: builder for '/nix/store/vy12b7lmf3y548whsjfv3m81vlm8g2zz-libpng-apng-armv6l-unknown-linux-gnueabihf-1.6.40.drv' failed with exit code 1;
last 3 log lines:
> unpacking sources
> unpacking source archive /nix/store/jpqz1p52xw3jlhc8w143v92k0iaar2i4-libpng-1.6.40.tar.xz
> do not know how to unpack source archive /nix/store/jpqz1p52xw3jlhc8w143v92k0iaar2i4-libpng-1.6.40.tar.xz
For full logs, run 'nix log /nix/store/vy12b7lmf3y548whsjfv3m81vlm8g2zz-libpng-apng-armv6l-unknown-linux-gnueabihf-1.6.40.drv'.
error: 1 dependencies of derivation '/nix/store/2q5j823rwvrr8431y8dyg9i2w3cdrbsr-freetype-armv6l-unknown-linux-gnueabihf-2.13.2.drv' failed to build
error: 1 dependencies of derivation '/nix/store/9v3h4811dqsqc65yrvwq4y7mbyz7s8k0-fontconfig-armv6l-unknown-linux-gnueabihf-2.14.2.drv' failed to build
error: 1 dependencies of derivation '/nix/store/kdw5vbdbnp6djlqggmcw02lniqkay0zd-fontconfig-conf.drv' failed to build
error: 1 dependencies of derivation '/nix/store/li54ky7kl6yhjq204rkba2aig66x2hqk-system-path.drv' failed to build
error (ignored): error: cannot unlink '/run/user/0/nix-build-binutils-armv6l-unknown-linux-gnueabihf-2.40.drv-0/binutils-2.40/ld/.deps': Directory not empty
error (ignored): error: cannot unlink '/run/user/0/nix-build-libtasn1-armv6l-unknown-linux-gnueabihf-4.19.0.drv-0': Directory not empty
error: 1 dependencies of derivation '/nix/store/ban8rmijp7l85kvhgy5jg3qsrynahgm1-nixos-system-nixos-23.11.20240115.b8dd8be.drv' failed to build
error: 1 dependencies of derivation '/nix/store/sg2x74hlkf721z4355s8sy3zs9sqwm1y-ext4-fs.img.zst-armv6l-unknown-linux-gnueabihf.drv' failed to build
error: 1 dependencies of derivation '/nix/store/34ywqprscl80bmpwcpc2ihggnrk021wa-nixos-sd-image-23.11.20240115.b8dd8be-armv6l-linux.img-armv6l-unknown-linux-gnueabihf.drv' failed to build
[root@ip-172-31-16-53:~/flake]# nix --extra-experimental-features nix-command log /nix/store/vy12b7lmf3y548whsjfv3m81vlm8g2zz-libpng-apng-armv6l-unknown-linux-gnueabihf-1.6.40.drv
warning: The interpretation of store paths arguments ending in `.drv` recently changed. If this command is now failing try again with '/nix/store/vy12b7lmf3y548whsjfv3m81vlm8g2zz-libpng-apng-armv6l-unknown-linux-gnueabihf-1.6.40.drv^*'
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/jpqz1p52xw3jlhc8w143v92k0iaar2i4-libpng-1.6.40.tar.xz
do not know how to unpack source archive /nix/store/jpqz1p52xw3jlhc8w143v92k0iaar2i4-libpng-1.6.40.tar.xz
Not sure about that error, I think I also saw this onetime, but don’t know anymore how I got it and also what I did to solve it. Could you maybe provide more logs (nix log /nix/store/vy12b7lmf3y548whsjfv3m81vlm8g2zz-libpng-apng-armv6l-unknown-linux-gnueabihf-1.6.40.drv) and the exact flake (of course redact secrets) you’re using?
Thank you very much for that tip. That did the trick in combination with my initial device tree overlay. I2C now works.
I then tried to analyze if I can get the &i2c1 version to work. Reading about your two links I now understand that these &[node] things are semantic sugar to extend other nodes. I then tried to use that in combination with the hardware.i2c.enable = true but I still had no success as I already predicted since this doesn’t change the dtb file (I already analyzed this in my last post). I then tried to remove the -i2c suffix and still had the hardware.i2c.enable = true set which works now. So
Output of nix log is provided in previous comment.
Just:
do not know how to unpack source archive /nix/store/jpqz1p52xw3jlhc8w143v92k0iaar2i4-libpng-1.6.40.tar.xz