anchor.diff:  
     cfg = config.virtualisation;
   
  -  qemuGraphics = lib.optionalString (!cfg.graphics) "-nographic";
  -
     consoles = lib.concatMapStringsSep " " (c: "console=${c}") cfg.qemu.consoles;
   
  -  # XXX: This is very ugly and in the future we really should use attribute
  -  # sets to build ALL of the QEMU flags instead of this mixed mess of Nix
  -  # expressions and shell script stuff.
  -  mkDiskIfaceDriveFlag = idx: driveArgs: let
  -    inherit (cfg.qemu) diskInterface;
  -    # The drive identifier created by incrementing the index by one using the
  -    # shell.
  -    drvId = "drive$((${idx} + 1))";
  -    # NOTE: DO NOT shell escape, because this may contain shell variables.
  -    commonArgs = "index=${idx},id=${drvId},${driveArgs}";
  -    isSCSI = diskInterface == "scsi";
  -    devArgs = "${diskInterface}-hd,drive=${drvId}";
  -    args = "-drive ${commonArgs},if=none -device lsi53c895a -device ${devArgs}";
  -  in if isSCSI then args else "-drive ${commonArgs},if=${diskInterface}";
  +  driveOpts = { ... }: {
  +
  +    options = {
  +
  +      file = mkOption {
  +        type = types.str;
  +        description = "The file image used for this drive.";
  +      };
  +
  +      driveExtraOpts = mkOption {
  +        type = types.attrsOf types.str;
  +        default = {};
  +        description = "Extra options passed to drive flag.";
  +      };
  +
  +      deviceExtraOpts = mkOption {
  +        type = types.attrsOf types.str;
  +        default = {};
  +        description = "Extra options passed to device flag.";
  +      };
  +
  +    };
  +
  +  };
  +
  +  driveCmdline = idx: { file, driveExtraOpts, deviceExtraOpts, ... }:
  +    let
  +      drvId = "drive${toString idx}";
  +      mkKeyValue = generators.mkKeyValueDefault {} "=";
  +      mkOpts = opts: concatStringsSep "," (mapAttrsToList mkKeyValue opts);
  +      driveOpts = mkOpts (driveExtraOpts // {
  +        index = idx;
  +        id = drvId;
  +        "if" = "none";
  +        inherit file;
  +      });
  +      deviceOpts = mkOpts (deviceExtraOpts // {
  +        drive = drvId;
  +      });
  +      device =
  +        if cfg.qemu.diskInterface == "scsi" then
  +          "-device lsi53c895a -device scsi-hd,${deviceOpts}"
  +        else
  +          "-device virtio-blk-pci,${deviceOpts}";
  +    in
  +      "-drive ${driveOpts} ${device}";
  +
  +  drivesCmdLine = drives: concatStringsSep " " (imap1 driveCmdline drives);
   
     # Shell script to start the VM.
     startVM =
  
positive.code: 
      # FIXME: Consolidate this one day.
      virtualisation.qemu.options = mkMerge [
        (mkIf (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) [ "-vga std" "-usb" "-device usb-tablet,bus=usb-bus.0" ])
        (mkIf (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64) [ "-device virtio-gpu-pci" "-device usb-ehci,id=usb0" "-device usb-kbd" "-device usb-tablet" ])
      ];
  
      # Mount the host filesystem via 9P, and bind-mount the Nix store
  
negative.code:       ''}
  
        cd $TMPDIR
        idx=0
        ${flip concatMapStrings cfg.emptyDiskImages (size: ''
          if ! test -e "empty$idx.qcow2"; then
              ${qemu}/bin/qemu-img create -f qcow2 "empty$idx.qcow2" "${toString size}M"
          fi
          idx=$((idx + 1))
        '')}
  
  