summary refs log tree commit diff
path: root/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix
diff options
context:
space:
mode:
authorTuomas Tynkkynen <tuomas.tynkkynen@iki.fi>2015-05-05 06:23:28 +0300
committerTuomas Tynkkynen <tuomas.tynkkynen@iki.fi>2015-07-26 00:31:20 +0300
commitdf86813d9727aa3a9e3dcc45347f97b71bd01599 (patch)
tree89f4a25074ab30d84d7251f298b4be18e4a35ae2 /nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix
parent8665b0d8b10dc612b9b3dd5174837278026739e4 (diff)
downloadnixpkgs-df86813d9727aa3a9e3dcc45347f97b71bd01599.tar
nixpkgs-df86813d9727aa3a9e3dcc45347f97b71bd01599.tar.gz
nixpkgs-df86813d9727aa3a9e3dcc45347f97b71bd01599.tar.bz2
nixpkgs-df86813d9727aa3a9e3dcc45347f97b71bd01599.tar.lz
nixpkgs-df86813d9727aa3a9e3dcc45347f97b71bd01599.tar.xz
nixpkgs-df86813d9727aa3a9e3dcc45347f97b71bd01599.tar.zst
nixpkgs-df86813d9727aa3a9e3dcc45347f97b71bd01599.zip
nixos: Add derivations for SD card installation images on ARM
The resulting image can be copied to a SD card with `dd` and is directly
bootable by a suitably configured U-Boot. Though depending on the board, some
extra steps are required for copying U-Boot itself to the SD card.

Inside the image is a partition table, with a FAT32 /boot and a normal
writable EXT4 rootfs. It's possible to directly reuse the SD image's
partition layout and "install" NixOS on the same SD card by replacing
the default configuration.nix and nixos-rebuild, and actually is the
preferred way to use these images. To assist in this installation
method, the boot scripts on the image automatically resize the rootfs
partition to fit the SD card on the first boot.

The SD images come in two flavors; one for the ARMv6 Raspberry Pi,
and one multiplatform image for all the boards supported by the
mainline kernel's multi_v7_defconfig config target. At the moment, these
have been tested on:
    - Raspberry Pi Model B (512MB model)
    - NVIDIA Jetson TK1
    - Linksprite pcDuino3 Nano

To build, run:

nix-build '<nixpkgs/nixos>' -A config.system.build.sdImage \
    -I nixos-config='<nixpkgs/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix>'
Diffstat (limited to 'nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix')
-rw-r--r--nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix46
1 files changed, 46 insertions, 0 deletions
diff --git a/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix b/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix
new file mode 100644
index 00000000000..199a252ad2b
--- /dev/null
+++ b/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix
@@ -0,0 +1,46 @@
+{ config, lib, pkgs, ... }:
+
+let
+  extlinux-conf-builder =
+    import ../../system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.nix {
+      inherit pkgs;
+    };
+in
+{
+  imports = [
+    ../../profiles/minimal.nix
+    ../../profiles/installation-device.nix
+    ./sd-image.nix
+  ];
+
+  assertions = lib.singleton {
+    assertion = pkgs.stdenv.system == "armv6l-linux";
+    message = "sd-image-raspberrypi.nix can be only built natively on ARMv6; " +
+      "it cannot be cross compiled";
+  };
+
+  # Needed by RPi firmware
+  nixpkgs.config.allowUnfree = true;
+
+  boot.loader.grub.enable = false;
+  boot.loader.generic-extlinux-compatible.enable = true;
+
+  boot.kernelPackages = pkgs.linuxPackages_rpi;
+
+  # FIXME: fix manual evaluation on ARM
+  services.nixosManual.enable = lib.mkOverride 0 false;
+
+  # FIXME: this probably should be in installation-device.nix
+  users.extraUsers.root.initialHashedPassword = "";
+
+  sdImage = {
+    populateBootCommands = ''
+      for f in bootcode.bin fixup.dat start.elf; do
+        cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/$f boot/
+      done
+      cp ${pkgs.ubootRaspberryPi}/u-boot.bin boot/u-boot-rpi.bin
+      echo 'kernel u-boot-rpi.bin' > boot/config.txt
+      ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot
+    '';
+  };
+}