From b244e8e845ff36763bfcf0130087dbbe83e57afd Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 23 Jun 2022 16:57:25 -0700 Subject: [PATCH] moby: properly flash firmware as part of the image build --- machines/moby/default.nix | 1 + machines/moby/firmware.nix | 8 ++++++++ modules/image.nix | 12 +++++------- pkgs/overlay.nix | 3 +++ pkgs/tow-boot-pinephone/default.nix | 30 +++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 machines/moby/firmware.nix create mode 100644 pkgs/tow-boot-pinephone/default.nix diff --git a/machines/moby/default.nix b/machines/moby/default.nix index f76db571..1996500b 100644 --- a/machines/moby/default.nix +++ b/machines/moby/default.nix @@ -4,6 +4,7 @@ (import "${mobile-nixos}/lib/configuration.nix" { device = "pine64-pinephone"; }) + ./firmware.nix ./fs.nix ]; # XXX colin: phosh doesn't work well with passwordless login diff --git a/machines/moby/firmware.nix b/machines/moby/firmware.nix new file mode 100644 index 00000000..29a30fca --- /dev/null +++ b/machines/moby/firmware.nix @@ -0,0 +1,8 @@ +{ config, pkgs, ... }: +{ + system.build.img = pkgs.runCommandNoCC "nixos_full-disk-image.img" {} '' + cp -v ${config.system.build.img-without-firmware}/nixos.img $out + chmod +w $out + dd if=${pkgs.tow-boot-pinephone}/Tow-Boot.noenv.bin of=$out bs=1024 seek=8 conv=notrunc + ''; +} diff --git a/modules/image.nix b/modules/image.nix index 9081dc78..b2ab430e 100644 --- a/modules/image.nix +++ b/modules/image.nix @@ -39,7 +39,11 @@ in system.build.img-without-firmware = with pkgs; imageBuilder.diskImage.makeGPT { name = "nixos"; diskID = vfatUuidFromFs bootFs; - # headerHole = imageBuilder.size.MiB 16; + # leave some space for firmware + # TODO: we'd prefer to turn this into a protected firmware partition, rather than reserving space in the GPT header itself + # Tow-Boot manages to do that; not sure how. + # TODO: does this method work on all systems (test on lappy) + headerHole = imageBuilder.size.MiB 16; partitions = [ (fsBuilderMapBoot."${bootFs.fsType}" { # fs properties @@ -83,10 +87,4 @@ in ]; }; system.build.img = lib.mkDefault config.system.build.img-without-firmware; - # TODO: pinephone build: - # system.build.img = pkgs.runCommandNoCC "nixos_full-disk-image.img" {} '' - # cp -v ${config.system.build.without-bootloader}/nixos.img $out - # chmod +w $out - # dd if=${pkgs.tow-boot-pinephone}/Tow-Boot.noenv.bin of=$out bs=1024 seek=8 conv=notrunc - # ''; } diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index 83932119..c999af13 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -1,6 +1,9 @@ (next: prev: { #### my own, non-upstreamable packages: sane-scripts = prev.callPackage ./sane-scripts { }; + tow-boot-pinephone = prev.callPackage ./pkgs/tow-boot-pinephone { }; + + #### customized packages # nixos-unstable pleroma is too far out-of-date for our db pleroma = prev.callPackage ./pleroma { }; diff --git a/pkgs/tow-boot-pinephone/default.nix b/pkgs/tow-boot-pinephone/default.nix new file mode 100644 index 00000000..6423856e --- /dev/null +++ b/pkgs/tow-boot-pinephone/default.nix @@ -0,0 +1,30 @@ +{ lib, stdenv, fetchurl }: + +stdenv.mkDerivation rec { + pname = "tow-boot-pinephone"; + version = "2021.10-004"; + + src = fetchurl { + url = "https://github.com/Tow-Boot/Tow-Boot/releases/download/release-2021.10-004/pine64-pinephoneA64-2021.10-004.tar.xz"; + sha256 = "sha256-UZSzzzTp8PQ/wuLUA3RJyTa/vbQ0HdhfagJ8574leoA="; + }; + + unpackPhase = '' + mkdir -p src + tar -xf ${src} -C src + ''; + + installPhase = '' + mkdir -p "$out" + cp -R src/pine64-pinephoneA64-2021.10-004/*.img "$out"/ + cp -R src/pine64-pinephoneA64-2021.10-004/binaries/* "$out"/ + ''; + + + meta = with lib; { + description = "An opinionated distribution of U-Boot"; + homepage = "https://tow-boot.org/"; + platforms = [ "aarch64-linux" ]; + }; +} +