anchor.diff:        fi
       done
   
  -    # TODO: Nix really likes to chown things it creates to its current user...
  -    fakeroot nixos-prepare-root $root ${channelSources} ${config.system.build.toplevel} closure
  -
  -    # fakeroot seems to always give the owner write permissions, which we do not want
  -    find $root/nix/store -mindepth 1 -maxdepth 1 -type f -o -type d | xargs chmod -R a-w
  +    export HOME=$TMPDIR
  +
  +    # Provide a Nix database so that nixos-install can copy closures.
  +    export NIX_STATE_DIR=$TMPDIR/state
  +    nix-store --load-db < ${closureInfo}/registration
  +
  +    echo "running nixos-install..."
  +    nixos-install --root $root --no-bootloader --no-root-passwd --closure ${config.system.build.toplevel} --substituters ""
   
       echo "copying staging root to image..."
       cptofs -p ${optionalString (partitionTableType != "none") "-P ${rootPartition}"} -t ${fsType} -i $diskImage $root/* /
  
positive.code:         cp ${configFile} /mnt/etc/nixos/configuration.nix
        ''}
  
        mount --rbind /dev  $mountPoint/dev
        mount --rbind /proc $mountPoint/proc
        mount --rbind /sys  $mountPoint/sys
  
        # Set up core system link, GRUB, etc.
        NIXOS_INSTALL_BOOTLOADER=1 chroot $mountPoint /nix/var/nix/profiles/system/bin/switch-to-configuration boot
  
        # TODO: figure out if I should activate, but for now I won't
        # chroot $mountPoint /nix/var/nix/profiles/system/activate
  
        # The above scripts will generate a random machine-id and we don't want to bake a single ID into all our images
        rm -f $mountPoint/etc/machine-id
  
negative.code:   pkgs.runCommand name
      { preVM = prepareImage;
        buildInputs = with pkgs; [ utillinux e2fsprogs dosfstools ];
        postVM = ''
          ${if format == "raw" then ''
            mv $diskImage $out/${filename}
  