From 50c59caae1d5818584b85b9a3bfd4cab01148fe6 Mon Sep 17 00:00:00 2001 From: Craige McWhirter Date: Fri, 26 Jun 2020 08:51:29 +1000 Subject: [PATCH] First pass at armv7l images --- clusters/pi2B_rack.nix | 34 +++++++++++++ hardware/raspberry_pi_2_model_B.nix | 75 +++++++++++++++++++++++++++++ images/sd-image_paidh-aon.nix | 19 ++++++++ images/sd-image_paidh-armv7.nix | 40 +++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 clusters/pi2B_rack.nix create mode 100644 hardware/raspberry_pi_2_model_B.nix create mode 100644 images/sd-image_paidh-aon.nix create mode 100644 images/sd-image_paidh-armv7.nix diff --git a/clusters/pi2B_rack.nix b/clusters/pi2B_rack.nix new file mode 100644 index 0000000..94d090f --- /dev/null +++ b/clusters/pi2B_rack.nix @@ -0,0 +1,34 @@ +# NixOps configuration for the Raspberry Pi 2B Rack + +{ + + imports = + [ + + ../hardware/raspberry_pi_2_model_B.nix + ../roles/host_common.nix + ../roles/pi_common.nix + ../roles/server_common.nix + ]; + + # Ensure the right package architecture is used + nixpkgs.localSystem = { + system = "armv7l-linux"; + config = "armv7l-unknown-linux-gnu"; + allowUnfree = true; + }; + + networking.wireless.enable = false; # Toggles wireless support via wpa_supplicant. + + documentation = { + nixos.enable = false; # Save some space by disabling the manual + }; + + users.users.root = { + openssh.authorizedKeys.keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDtjE0YstRzlh+Zhlj03th9DYOkMqJ5xHUcderBq151K craige@mcwhirter.io" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFq6/C6ZSM8nS091fqw/om9LRszHDmS82ZTL7+GaSBnz craige@paidh-tri" + ]; + }; + +} diff --git a/hardware/raspberry_pi_2_model_B.nix b/hardware/raspberry_pi_2_model_B.nix new file mode 100644 index 0000000..d436b90 --- /dev/null +++ b/hardware/raspberry_pi_2_model_B.nix @@ -0,0 +1,75 @@ +# Configuration common to all Raspberry Pi 3 Model B devices + +{ config, pkgs, lib, ... }: + +{ + + boot = { + initrd = { + availableKernelModules = [ + "bcm2835_dma" # Allows early (earlier) mode setting + "i2c_bcm2835" # Allows early (earlier) mode setting + "usbhid" + "usb_storage" + "vc4" # Allows early (earlier) mode setting + ]; + }; + kernelPackages = pkgs.linuxPackages_latest; # For a Raspberry Pi 2 or 3) + kernelParams = [ + "console=ttyS0,115200n8" # Enable the serial console + "console=ttyAMA0,115200n8" + "console=tty0" + ]; + loader = { + generic-extlinux-compatible = { + enable = true; # Enables the generation of /boot/extlinux/extlinux.conf + }; + grub = { + enable = false; # NixOS wants to enable GRUB by default. + }; + raspberryPi = { + enable = true; + version = 3; + firmwareConfig = '' + hdmi_force_hotplug=1 # Enable headless booting + ''; + }; + }; + }; + + # File systems configuration for using the installer's partition layout + fileSystems = { + "/" = { + device = "/dev/disk/by-label/NIXOS_SD"; + fsType = "ext4"; + }; + "/boot/firmware" = { + device = "/dev/disk/by-label/FIRMWARE"; + fsType = "vfat"; + # Alternatively, this could be removed from the configuration. + # The filesystem is not needed at runtime, it could be treated + # as an opaque blob instead of a discrete FAT32 filesystem. + options = [ "nofail" "noauto" ]; + }; + "/var" = { + device = "/dev/disk/by-label/var"; + fsType = "ext4"; + }; + }; + + # !!! Adding a swap file is optional, but strongly recommended! + swapDevices = [ { device = "/swapfile"; size = 1024; } ]; + + hardware = { + enableRedistributableFirmware = true; # Enable support for Pi firmware blobs + }; + + networking = { + enableB43Firmware = false; # If true, enable Pi wireless firmware + }; + + environment.systemPackages = with pkgs; [ + raspberrypi-tools # Userland tools for the Raspberry Pi board + ]; + +} diff --git a/images/sd-image_paidh-aon.nix b/images/sd-image_paidh-aon.nix new file mode 100644 index 0000000..62945c6 --- /dev/null +++ b/images/sd-image_paidh-aon.nix @@ -0,0 +1,19 @@ +# SD image for paidh-aon +# +# To build this image, run: +# +# nix-build '' -A config.system.build.sdImage -I \ +# nixos-config=./images/sd-image_paidh-aon.nix +# +# An example of how to write the image to SD card: +# +# bzcat ./result/sd-image/nixos-sd-image-20.03.1577.74a80c5a9ab-aarch64-linux.img.bz2 | sudo dd of=/dev/sdb + +{ ... }: { + + imports = [ + ./sd-image_paidh-armv7.nix + ../hosts/paidh-aon.nix + ]; + +} diff --git a/images/sd-image_paidh-armv7.nix b/images/sd-image_paidh-armv7.nix new file mode 100644 index 0000000..c295215 --- /dev/null +++ b/images/sd-image_paidh-armv7.nix @@ -0,0 +1,40 @@ +# Base image for building SD images for my Pi 2's +# +# To build, use: +# imports = [ ./sd-image_paidh-armv7.nix ] + +{ config, lib, pkgs, ... }: + +let + extlinux-conf-builder = + import { + pkgs = pkgs.buildPackages; + }; +in +{ + imports = [ + + + ]; + + boot.consoleLogLevel = lib.mkDefault 7; + + sdImage = { + populateFirmwareCommands = let + configTxt = pkgs.writeText "config.txt" '' + # Prevent the firmware from smashing the framebuffer setup done by the mainline kernel + # when attempting to show low-voltage or overtemperature warnings. + avoid_warnings=1 + ''; + in '' + (cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf $NIX_BUILD_TOP/firmware/) + cp ${pkgs.ubootRaspberryPi2}/u-boot.bin firmware/u-boot-rpi2.bin + cp ${configTxt} firmware/config.txt + ''; + populateRootCommands = '' + mkdir -p ./files/boot + ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./files/boot + ''; + }; + +}