mbrimage.nix (1501B)
1 { 2 config, 3 pkgs, 4 lib, 5 ... 6 }: 7 let 8 inherit (lib) mkOption types; 9 o = config.system.outputs; 10 phram_address = lib.toHexString (config.hardware.ram.startAddress + 256 * 1024 * 1024); 11 in 12 { 13 options.system.outputs = { 14 mbrimage = mkOption { 15 type = types.package; 16 description = '' 17 mbrimage 18 ********* 19 20 This creates a disk image file with a partition table containing 21 the contents of ``outputs.rootfs`` as its only partition. 22 ''; 23 }; 24 vmdisk = mkOption { type = types.package; }; 25 }; 26 27 config = { 28 system.outputs = { 29 mbrimage = 30 let 31 o = config.system.outputs; 32 in 33 pkgs.runCommand "mbrimage" 34 { 35 depsBuildBuild = [ pkgs.pkgsBuildBuild.util-linux ]; 36 } 37 '' 38 # leave 4 sectors at start for partition table 39 # and alignment to 2048 bytes (does that help?) 40 dd if=${o.rootfs} of=$out bs=512 seek=4 conv=sync 41 echo '4,-,L,*' | sfdisk $out 42 ''; 43 vmdisk = pkgs.runCommand "vmdisk" { } '' 44 mkdir $out 45 cd $out 46 ln -s ${o.mbrimage} ./mbrimage 47 cat > run.sh <<EOF 48 #!${pkgs.runtimeShell} 49 ${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 50 EOF 51 chmod +x run.sh 52 ''; 53 }; 54 }; 55 }