cleanup files and add AIO image
This commit is contained in:
parent
c436983153
commit
022ceeb8aa
9 changed files with 90 additions and 114 deletions
|
@ -21,9 +21,10 @@
|
|||
description = "Compress the resulting image with zstd.";
|
||||
};
|
||||
|
||||
# TODO this is unnecessary. just make the partition big enough to fit the boot files automatically.
|
||||
bootPartitionSize = mkOption {
|
||||
type = types.int;
|
||||
default = 128;
|
||||
default = 64;
|
||||
description = "Size of the boot partition, in mebibytes (1024x1024 bytes).";
|
||||
};
|
||||
|
||||
|
@ -57,6 +58,9 @@
|
|||
};
|
||||
|
||||
config = let cfg = config.ps4; in lib.mkIf cfg.enable {
|
||||
# TODO write definitions for the other southbridges
|
||||
boot.kernelPackages = pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor (pkgs.callPackage ../kernel/kernel-aeolia-5.3.nix {}));
|
||||
|
||||
fileSystems = {
|
||||
"/boot" = {
|
||||
device = "/dev/disk/by-label/${cfg.usbImage.bootPartitionLabel}";
|
||||
|
@ -70,6 +74,7 @@
|
|||
};
|
||||
|
||||
boot.loader.grub.enable = lib.mkForce false;
|
||||
boot.loader.initScript.enable = lib.mkForce true;
|
||||
|
||||
# from https://github.com/NixOS/nixpkgs/blob/e405f30513169feedb64b5c25e7b00242010af58/nixos/modules/installer/sd-card/sd-image.nix#L267
|
||||
boot.postBootCommands = let
|
||||
|
@ -107,7 +112,7 @@
|
|||
fi
|
||||
'';
|
||||
|
||||
system.build.rootFileSystem = pkgs.callPackage (modulesPath + "/../lib/make-ext4-fs.nix") {
|
||||
system.build.rootfsImage = pkgs.callPackage (modulesPath + "/../lib/make-ext4-fs.nix") {
|
||||
storePaths = [ config.system.build.toplevel ];
|
||||
volumeLabel = cfg.usbImage.rootPartitionLabel;
|
||||
populateImageCommands = ''
|
||||
|
@ -115,5 +120,53 @@
|
|||
touch ./files/firstboot
|
||||
'';
|
||||
};
|
||||
|
||||
# slightly modified version of https://github.com/NixOS/nixpkgs/blob/e405f30513169feedb64b5c25e7b00242010af58/nixos/modules/installer/sd-card/sd-image.nix#L182
|
||||
system.build.usbImage = pkgs.stdenv.mkDerivation {
|
||||
name = cfg.usbImage.imageName;
|
||||
|
||||
nativeBuildInputs = with pkgs; [ dosfstools parted mtools e2fsprogs util-linux ]
|
||||
++ lib.optional cfg.usbImage.compressImage zstd;
|
||||
|
||||
inherit (cfg.usbImage) compressImage;
|
||||
|
||||
buildCommand = ''
|
||||
# mkdir -p $out/usb-image
|
||||
img=$out
|
||||
rootfs=${config.system.build.rootfsImage}
|
||||
|
||||
# Create the image to fit rootfs + bootfs + 1 MiB
|
||||
rootfsSizeBlocks=$(du -B 512 --apparent-size $rootfs | awk '{ print $1 }')
|
||||
bootfsSizeBlocks=$((${toString cfg.usbImage.bootPartitionSize} * 1024 * 1024 / 512))
|
||||
imageSize=$((rootfsSizeBlocks * 512 + bootfsSizeBlocks * 512 + 1 * 1024 * 1024))
|
||||
truncate -s $imageSize $img
|
||||
|
||||
# Partition the image
|
||||
parted -s $img -- mklabel msdos
|
||||
parted -s $img -- mkpart primary fat32 1M ${toString (cfg.usbImage.bootPartitionSize + 1)}M
|
||||
parted -s $img -- mkpart primary ext4 ${toString (cfg.usbImage.bootPartitionSize + 1)}M 100%
|
||||
|
||||
# Copy the rootfs to the image
|
||||
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
|
||||
dd conv=notrunc if=$rootfs of=$img seek=$START count=$SECTORS
|
||||
|
||||
# Create a temporary image for the boot partition
|
||||
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
|
||||
truncate -s $((SECTORS * 512)) boot.img
|
||||
mkfs.vfat -F 32 -n ${cfg.usbImage.bootPartitionLabel} boot.img
|
||||
|
||||
# Copy the files that the PS4 Linux Loader payload expects to the boot partition
|
||||
mcopy -i boot.img ${config.system.build.kernel}/bzImage ::/bzImage
|
||||
mcopy -i boot.img ${config.system.build.initialRamdisk}/initrd.gz ::/initramfs.cpio.gz
|
||||
|
||||
# Verify the boot partition before copying it
|
||||
fsck.vfat -vn boot.img
|
||||
dd conv=notrunc if=boot.img of=$img seek=$START count=$SECTORS
|
||||
|
||||
if test -n "$compressImage"; then
|
||||
zstd -T$NIX_BUILD_CORES --rm $img
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue