add uefi package and iso builder

thanks to https://github.com/martiert/x13s-bios
This commit is contained in:
Adam Stephens 2024-05-01 10:08:29 -04:00
parent 3fa14acfdd
commit 0650514998
No known key found for this signature in database
3 changed files with 88 additions and 0 deletions

View file

@ -1,5 +1,14 @@
{ lib, withSystem, ... }: { lib, withSystem, ... }:
{ {
perSystem =
{ pkgs, ... }:
{
packages = rec {
uefi = pkgs.callPackage ./uefi.nix { };
uefi-usbiso = pkgs.callPackage ./uefi-usbiso.nix { inherit uefi; };
};
};
flake.packages.aarch64-linux = withSystem "aarch64-linux" ( flake.packages.aarch64-linux = withSystem "aarch64-linux" (
{ pkgs, ... }: import ./default.nix { inherit lib pkgs; } { pkgs, ... }: import ./default.nix { inherit lib pkgs; }
); );

50
packages/uefi-usbiso.nix Normal file
View file

@ -0,0 +1,50 @@
{
stdenv,
parted,
util-linux,
dosfstools,
mtools,
uefi,
}:
stdenv.mkDerivation rec {
name = "usbdisk";
version = uefi.version;
src = ./.;
nativeBuildInputs = [
parted
util-linux
dosfstools
mtools
];
doUnpack = false;
buildPhase = ''
img=${name}-${version}.iso
gap=8
blocks=$(du -B 512 --summarize --apparent-size ${uefi} | awk '{ print $1 }')
blocks=$(( 2 * blocks ))
size=$(( 512 * blocks + gap * 1024 * 1024 + 34*512))
truncate -s $size $img
sfdisk $img <<EOF
label: gpt
start=''${gap}M, size=$blocks, type=uefi
EOF
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
truncate -s $(( SECTORS * 512 )) part.img
mkfs.vfat part.img
mcopy -spvm -i ./part.img ${uefi}/EFI "::/EFI"
mcopy -spvm -i ./part.img ${uefi}/Flash "::/Flash"
dd conv=notrunc if=part.img of=$img seek=$START count=$SECTORS
rm -fr part.img
'';
installPhase = ''
mkdir $out
mv ${name}-${version}.iso $out/
'';
}

29
packages/uefi.nix Normal file
View file

@ -0,0 +1,29 @@
{
stdenv,
fetchurl,
innoextract,
}:
stdenv.mkDerivation {
name = "uefi";
version = "1.60";
src = fetchurl {
url = "https://download.lenovo.com/pccbbs/mobiles/n3huj19w.exe";
hash = "sha256-ZSjkvbMb0e9CoL2OYo3Aioyz3or1YkOX/BdOOeAuL7I=";
};
nativeBuildInputs = [ innoextract ];
unpackPhase = ''
innoextract $src
'';
doBuild = false;
installPhase = ''
mkdir --parent $out/{EFI/Boot,Flash}
cp code\$GetExtractPath\$/Rfs/Usb/Bootaa64.efi $out/EFI/Boot/
cp -r code\$GetExtractPath\$/Rfs/Fw/* $out/Flash/
'';
}