nix-community / raspberry-pi-nix

NixOS modules to aid in configuring NixOS for raspberry pi products
MIT License
144 stars 34 forks source link

Error when building SD image due to large NixOS configuration #15

Closed bolt12 closed 3 months ago

bolt12 commented 3 months ago

I am encountering an error while attempting to build an SD image for my Raspberry Pi using a non-minimal NixOS configuration. The build fails with errors indicating a lack of space. When using a minimal configuration, the build completes successfully. I need guidance on how to build a larger image to accommodate my full configuration, which includes various services and system packages.

/nix/store/jg308gw60a4i4lg13vn1aj4flb7ymwfw-extlinux-conf-builder.sh: line 138: cd: /nix/var/nix/profiles: No such file or directory
Preparing store paths for image...
cp: error writing './rootImage/nix/store/s7js1pkrpw2xxk4v4mkilrrrnyx3jz04-freepats-20060219/Tone_000/019_Church_Organ.pat': No space left on device
cp: error writing './rootImage/nix/store/s7js1pkrpw2xxk4v4mkilrrrnyx3jz04-freepats-20060219/Tone_000/021_Accordion.pat': No space left on device
...
cp: error writing './rootImage/nix/store/s7js1pkrpw2xxk4v4mkilrrrnyx3jz04-freepats-20060219/Tone_000/056_Trumpet.pat': No space left on device
cp: error writing './rootImage/nix/store/s7js1pkrpw2xxk4v4mkilrrrnyx3jz04-freepats-20060219/Tone_000/057_Trombone.pat': No space left on device
cp: error writing './rootImage/nix/store/s7js1pkrpw2xxk4v4mkilrrrnyx3jz04-freepats-20060219/Tone_000/058_Tuba.pat': No space left on device

I am looking for advice on how to build a larger SD image that can handle my full NixOS configuration, perhaps by checking the storePaths size during the build process? I tried reading the code but most of it went way over my head.

Thank you!

bolt12 commented 3 months ago

It seems the image also has some issues with channels not being properly set up? I had to add to my config the following in order to be able to make it work:

nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];

if not previously I would get:

warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error:
… <borked>

at «none»:0: (source not available)

… while calling the 'import' builtin

at «string»:1:18:

1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (dig) ]; } ""
|                  ^

(stack trace truncated; use '--show-trace' to show the full trace)

error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

at «none»:0: (source not available)

when trying to nix-shell -p dig

tstat commented 3 months ago

It looks to me like you are failing here, so your hard drive doesn't have enough free space to support copying the store paths in preparation for creating the ext4 image.

It seems the image also has some issues with channels not being properly set up? I had to add to my config the following in order to be able to make it work:

That's right, this nixos module doesn't do anything to setup channels -- it doesn't do any configuration besides attempting to make the config work on rpi hardware. It isn't intended to be a base image, but is instead meant to be a module to add to your nixos configuration to make it work on rpi hardware.

The way you have set the nix path looks good to me.

bolt12 commented 3 months ago

Thank you for replying @tstat !

My hard drive does have enough space, I think, unless 200GiB isn't enough which I doubt it. If you are more familiar with that ext4 logic than me, could you perhaps point me to how can I make my ./rootImage partition larger?

tstat commented 3 months ago

That's strange, it looks to me like that code just copies some files into a directory (this is where it looks like you are crashing to me) then it calls mkfs.ext4 with the -d flag on the directory to create the filesystem.

Perhaps your nix build directory is on a smaller partition. Do you have a tmpfs mounted at /tmp?

bolt12 commented 3 months ago

This is how my partitions look like:

Filesystem     1G-blocks  Used Available Use% Mounted on
devtmpfs              1G    0G        1G   0% /dev
devpts                0G    0G        0G    - /dev/pts
tmpfs                 8G    1G        8G   5% /dev/shm
proc                  0G    0G        0G    - /proc
tmpfs                12G    1G       12G   1% /run
ramfs                 0G    0G        0G    - /run/keys
tmpfs                 8G    1G        8G   1% /run/wrappers
sysfs                 0G    0G        0G    - /sys
/dev/nvme0n1p5      709G  498G      175G  75% /
/dev/nvme0n1p5      709G  498G      175G  75% /nix/store
securityfs            0G    0G        0G    - /sys/kernel/security
cgroup2               0G    0G        0G    - /sys/fs/cgroup
pstore                0G    0G        0G    - /sys/fs/pstore
efivarfs              1G    1G        1G  31% /sys/firmware/efi/efivars
bpf                   0G    0G        0G    - /sys/fs/bpf
systemd-1              -     -         -    - /proc/sys/fs/binfmt_misc
mqueue                0G    0G        0G    - /dev/mqueue
debugfs               0G    0G        0G    - /sys/kernel/debug
hugetlbfs             0G    0G        0G    - /dev/hugepages
fusectl               0G    0G        0G    - /sys/fs/fuse/connections
configfs              0G    0G        0G    - /sys/kernel/config
tmpfs                 8G    1G        8G   3% /tmp
/dev/nvme0n1p1        1G    1G        1G  39% /boot
binfmt_misc           0G    0G        0G    - /proc/sys/fs/binfmt_misc
tracefs               0G    0G        0G    - /sys/kernel/debug/tracing
tmpfs                12G    1G       12G   1% /run/user/1000
gvfsd-fuse            0G    0G        0G    - /run/user/1000/gvfs
portal                0G    0G        0G    - /run/user/1000/doc
tstat commented 3 months ago

Ok, so your /tmp is on an 8 GiB partition, and the default nix build dir is /tmp.

You could stop mounting /tmp to a tmpfs (for this build at least), or you could change the nix daemon build directory. Note that this isn't an issue that is specific to raspberry-pi-nix, but instead an issue you will run into with any nix build that consumes more than 8 GiB.

bolt12 commented 3 months ago

I see! That makes sense! I will try doing that and report back! Thank you for your time and help!

tstat commented 3 months ago

No problem, happy to help.

bolt12 commented 3 months ago

Can confirm that

mkdir -p /path/to/tmp
sudo mount --bind /path/to/tmp /tmp

and then building the sd image works!