liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

mbrimage.nix (1473B)


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