2023-12-06 00:16:53 +01:00
|
|
|
{
|
|
|
|
config
|
|
|
|
, pkgs
|
|
|
|
, lib
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (lib) mkOption types concatStringsSep;
|
|
|
|
o = config.system.outputs;
|
|
|
|
phram_address = lib.toHexString (config.hardware.ram.startAddress + 256 * 1024 * 1024);
|
|
|
|
in {
|
|
|
|
options.system.outputs = {
|
2023-12-11 20:04:34 +01:00
|
|
|
mbrimage = mkOption {
|
2023-12-06 00:16:53 +01:00
|
|
|
type = types.package;
|
|
|
|
description = ''
|
2023-12-11 20:04:34 +01:00
|
|
|
mbrimage
|
2023-12-06 00:16:53 +01:00
|
|
|
*********
|
|
|
|
|
|
|
|
This creates a disk image file with a partition table containing
|
|
|
|
the contents of ``outputs.rootfs`` as its only partition.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
vmdisk = mkOption { type = types.package; };
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
system.outputs = {
|
2023-12-11 20:04:34 +01:00
|
|
|
mbrimage =
|
2023-12-06 00:16:53 +01:00
|
|
|
let
|
|
|
|
o = config.system.outputs;
|
2023-12-11 20:04:34 +01:00
|
|
|
in pkgs.runCommand "mbrimage" {
|
2023-12-06 00:16:53 +01:00
|
|
|
depsBuildBuild = [ pkgs.pkgsBuildBuild.util-linux ];
|
|
|
|
} ''
|
|
|
|
# leave 4 sectors at start for partition table
|
|
|
|
# and alignment to 2048 bytes (does that help?)
|
|
|
|
dd if=${o.rootfs} of=$out bs=512 seek=4 conv=sync
|
|
|
|
echo '4,-,L,*' | sfdisk $out
|
|
|
|
'';
|
|
|
|
vmdisk = pkgs.runCommand "vmdisk" {} ''
|
|
|
|
mkdir $out
|
|
|
|
cd $out
|
2023-12-11 20:04:34 +01:00
|
|
|
ln -s ${o.mbrimage} ./mbrimage
|
2023-12-06 00:16:53 +01:00
|
|
|
cat > run.sh <<EOF
|
|
|
|
#!${pkgs.runtimeShell}
|
2023-12-29 19:12:57 +01:00
|
|
|
${pkgs.pkgsBuildBuild.run-liminix-vm}/bin/run-liminix-vm --arch ${pkgs.stdenv.hostPlatform.qemuArch} --u-boot ${o.u-boot}/u-boot.bin --phram-address 0x${phram_address} --disk-image ${o.mbrimage} \$* /dev/null /dev/null
|
2023-12-06 00:16:53 +01:00
|
|
|
EOF
|
|
|
|
chmod +x run.sh
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|