From 597f83b324721f06dc57cd916db30ee6df3e1084 Mon Sep 17 00:00:00 2001 From: Bailey Stevens Date: Wed, 19 Apr 2023 20:28:26 -0400 Subject: [PATCH] Switches to full nixos config. WHY was I rewriting this from scratch?? --- config.txt | 16 ---------- flake.nix | 31 +++++++++++++------ rootfs.nix | 12 -------- sd-card.nix | 87 ----------------------------------------------------- 4 files changed, 21 insertions(+), 125 deletions(-) delete mode 100644 config.txt delete mode 100644 rootfs.nix delete mode 100644 sd-card.nix diff --git a/config.txt b/config.txt deleted file mode 100644 index 5da13cd..0000000 --- a/config.txt +++ /dev/null @@ -1,16 +0,0 @@ -[pi02] -kernel=u-boot-rpi3.bin -core_freq=250 - -[all] -# Boot in 64-bit mode. -arm_64bit=1 - -# U-Boot needs this to work, regardless of whether UART is actually used or not. -# Look in arch/arm/mach-bcm283x/Kconfig in the U-Boot tree to see if this is still -# a requirement in the future. -enable_uart=1 - -# 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 diff --git a/flake.nix b/flake.nix index e516a88..42fe61c 100644 --- a/flake.nix +++ b/flake.nix @@ -17,17 +17,14 @@ { apps.default = { type = "app"; - program = "${self.outputs.packages.${system}.vmscript}/bin/vmscript"; + program = self.outputs.packages.${system}.vmscript + "/bin/vmscript"; }; - packages = { - default = import ./sd-card.nix { inherit pkgs crossPkgs; }; - uncompressed = import ./sd-card.nix { inherit pkgs crossPkgs; compress = false; }; - - vmscript = pkgs.writeScriptBin "vmscript" '' + packages.vmscript = pkgs.writeScriptBin "vmscript" '' #!${pkgs.runtimeShell} -e img=./sd-card.img - cp -b ${self.outputs.packages.${system}.uncompressed}/sd-card.img $img + cp -b ${self.outputs.image}/sd-image/orange.img $img chmod 640 $img + truncate -s %2G $img ${pkgs.qemu}/bin/qemu-system-aarch64 \ -machine raspi3b \ -kernel "${crossPkgs.ubootRaspberryPi3_64bit}/u-boot.bin" \ @@ -39,8 +36,22 @@ -serial null \ -serial mon:stdio ''; - + }) // { + nixosConfigurations.orange = nixpkgs.lib.nixosSystem { + modules = [ + "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" + { + boot.kernelParams = [ "console=ttyS1,115200n8" ]; + networking.hostName = "orange"; + system.stateVersion = "23.05"; + nixpkgs.hostPlatform.system = "aarch64-linux"; + sdImage = { + imageName = "orange.img"; + compressImage = false; + }; + } + ]; + }; + image = self.outputs.nixosConfigurations.orange.config.system.build.sdImage; }; - - }); } diff --git a/rootfs.nix b/rootfs.nix deleted file mode 100644 index 7f51672..0000000 --- a/rootfs.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ pkgs }: - -pkgs.stdenv.mkDerivation { - name = "orange-rootfs.img.zstd"; - - nativeBuildInputs = with pkgs; [ zstd ]; - - buildCommand = '' - truncate -s 512M ./rootfs.img - zstd -T$NIX_BUILD_CORES ./rootfs.img -o $out - ''; -} diff --git a/sd-card.nix b/sd-card.nix deleted file mode 100644 index c4039b2..0000000 --- a/sd-card.nix +++ /dev/null @@ -1,87 +0,0 @@ -{ pkgs, crossPkgs, compress ? true}: - -let - fwPart = { - offset = 8; - id = "0xfeed3425"; - name = "FIRMWARE"; - size = 512; - }; - rootfsImage = import ./rootfs.nix { inherit pkgs; }; - - configTxt = pkgs.writeText "config.txt" (builtins.readFile ./config.txt); - populateFirmwareCommands = '' - # Add config.txt - cp ${configTxt} firmware/config.txt - - # Copy the firmware files - cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/bootcode.bin firmware/ - cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/fixup*.dat firmware/ - cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/start*.elf firmware/ - - # Add pi3 specific files - cp ${crossPkgs.ubootRaspberryPi3_64bit}/u-boot.bin firmware/u-boot-rpi3.bin - ''; -in - pkgs.stdenv.mkDerivation { - name = "orange"; - - nativeBuildInputs = with pkgs; [ dosfstools e2fsprogs libfaketime mtools util-linux zstd ]; - - buildCommand = '' - mkdir $out - img=$out/sd-card.img - root_fs=./rootfs.img - zstd -d --no-progress "${rootfsImage}" -o $root_fs - - # Create the image file sized to fit /boot/firmware and /, plus slack for the gap. - rootSizeBlocks=$(du -B 512 --apparent-size $root_fs | awk '{ print $1 }') - firmwareSizeBlocks=$((${toString fwPart.size} * 1024 * 1024 / 512)) - imageSize=$((rootSizeBlocks * 512 + firmwareSizeBlocks * 512)) - truncate -s $imageSize $img - - # type=b is 'W95 FAT32', type=83 is 'Linux'. - # The "bootable" partition is where u-boot will look file for the bootloader - # information (dtbs, extlinux.conf file). - sfdisk $img <