How to build a standalone NixOS QEMU VM?

Hi @eonpatapon, how would I do this interactively (to put it in @gesturbjarkason’s script) ?
Right now I have

nix-build '<nixpkgs/nixos>' - <<'EOF'
(import <nixpkgs/nixos/lib/make-disk-image.nix> {
    inherit lib config;
    pkgs = import <nixpkgs> { inherit (pkgs) system; };
    diskSize = 10240;
    format = "qcow2";
}).system.build.qcow2
EOF

but get

error: undefined variable ‘lib’ at (string):1:50