-
Notifications
You must be signed in to change notification settings - Fork 0
/
genTFTP.nix
69 lines (61 loc) · 2.44 KB
/
genTFTP.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{ config, pkgs, nixpkgs, systemname, systemserial, ... }:
let
pxeLinuxCfg = ''
DEFAULT menu.c32
PROMPT 0
TIMEOUT 100
ONTIMEOUT nixos
LABEL nixos
MENU LABEL NixOS: ${systemname}
LINUX ${systemname}/Image
INITRD ${systemname}/initrd
APPEND init=${config.system.build.toplevel}/init boot.shell_on_fail console=ttyS0,115200n8 console=ttyAMA0,115200n8 console=tty0 nohibernate loglevel=7
FDTDIR dtb
'';
in
{
imports = [
"${nixpkgs}/nixos/modules/installer/netboot/netboot-minimal.nix" # Netboot system - Kernel and ramdisk builds.
./rpiFirmware.nix # Raspberry Pi firmware - u-boot, config.txt, etc.
./rpiBoot.nix
];
system.build.rpiTFTP = pkgs.callPackage
({ stdenv, fetchurl, ... }: stdenv.mkDerivation {
name = "rpiTFTP";
src = fetchurl {
url = "https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz";
hash = "sha256-JQub2QlF02FZanpplD0L3F/AwJF6pWJgn40wWKLDazo=";
};
buildCommand = ''
# Create the directory structure
mkdir -p $out
mkdir -p $out/dtb
mkdir -p $out/${systemname}
mkdir -p $out/pxelinux.cfg
# Copy the boot firmware (config.txt, start.elf, etc)
# This is what is first read by the Raspberry Pi, contains u-boot.
cp -r ${config.system.build.rpiFirmware}/firmware/* $out/
# Copy the kernel (dtbs, Image, lib, System.map)
# This is the Linux kernel, which is loaded by u-boot.
cp -r ${config.system.build.kernel}/* $out/${systemname}/
# Make a second copy of the dtbs, because u-boot needs them in a different place
cp -r ${config.system.build.kernel}/dtbs/* $out/dtb/
# Copy the initrd from the boot directory.
cp ${config.system.build.rpiBoot}/nixos/*initrd* $out/${systemname}/initrd
mkdir -p $out/${systemname}/boot
cp -r ${config.system.build.rpiBoot}/nixos/* $out/${systemname}/boot
# Copy the netboot ramdisk.
# Copy syslinux.
tar -xzf $src
cp -r syslinux-6.03/bios/com32/chain/chain.c32 $out/
cp -r syslinux-6.03/bios/com32/mboot/mboot.c32 $out/
cp -r syslinux-6.03/bios/memdisk/memdisk $out/
cp -r syslinux-6.03/bios/com32/menu/menu.c32 $out/
cp -r syslinux-6.03/bios/core/pxelinux.0 $out/
# Copy the pxelinux config.
echo "${pxeLinuxCfg}" > $out/pxelinux.cfg/${systemserial}
'';
}
)
{ };
}