New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
qemu-vm: fix script syntax and VM args #34409
Conversation
Is this the same code used in |
@Mic92 Yes |
I tried the following: { lib, config, pkgs, fetchgit, ... }:
{
users.users.root.initialPassword = "root";
systemd.services."serial-getty@ttyS0".enable = true;
networking.firewall.enable = false;
} $ nixos-rebuild -I nixos-config=./test-vm.nix build-vm-with-bootloader
building Nix...
building the system configuration...
these derivations will be built:
/nix/store/6z05y9a1bqi5n51rxc2pmcz2bqr584w2-nixos-boot-disk.drv
/nix/store/h70k8wn3b5rn3r066lwdaq4fpkdyhq7a-run-nixos-vm.drv
/nix/store/b6sg27fqhw32ll7fb7rp2al0xy27jjya-nixos-vm.drv
building '/nix/store/6z05y9a1bqi5n51rxc2pmcz2bqr584w2-nixos-boot-disk.drv'...
Formatting '/nix/store/z0l74v7na2027xbfdq6anci097vjp33s-nixos-boot-disk/disk.img', fmt=qcow2 size=41943040 cluster_size=65536 lazy_refcounts=off refcount_bits=16
QEMU 2.11.0 monitor - type 'help' for more information
(qemu) qemu-system-x86_64: -serial pty: char device redirected to /dev/pts/0 (label serial0)
builder for '/nix/store/6z05y9a1bqi5n51rxc2pmcz2bqr584w2-nixos-boot-disk.drv' failed with exit code 1
cannot build derivation '/nix/store/h70k8wn3b5rn3r066lwdaq4fpkdyhq7a-run-nixos-vm.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/b6sg27fqhw32ll7fb7rp2al0xy27jjya-nixos-vm.drv': 1 dependencies couldn't be built
error: build of '/nix/store/b6sg27fqhw32ll7fb7rp2al0xy27jjya-nixos-vm.drv' failed The same error happens on current master. |
I hadn't noticed that before pushing. I actually ran my tests against an outdated branch and only cherry-picked the commit. I was able to reproduce the issue on master and might be able to push a fix on the weekend. |
I have outlined the changes required for 18.03 which make it work for me here: steveej-forks/nixpkgs-channels#1 I'm building this with the following script: #!/usr/bin/env bash
set -x
rm $(hostname).qcow2
set -e
nix-build -K --show-trace ${HOME}/src/github/NixOS/nixpkgs-channels/nixos \
-I nixos-config=${HOME}/src/steveej/nix-expressions/nixos-configuration/steveej-laptop/configuration.nix \
-A vmWithBootLoader
./result/bin/run-*-vm I will try to reproduce this on master too and update this PR |
5c35ed0
to
f777d2b
Compare
@aszlig Any pointers on how to design a nixos/test which executes the script produced by the vmWithBootLoader derivation and makes use of the test-driver? |
@Mic92 the easiest way to test this would be to do the following while you're in the working tree with this branch: |
Thanks! |
@xeji do we want this on release-18.09? |
@@ -196,9 +197,17 @@ rec { | |||
${qemuBinary qemu} \ | |||
-nographic -no-reboot \ | |||
-device virtio-rng-pci \ | |||
${if "$diskInterface" == "scsi" then '' \ | |||
\ # FIXME: /dev/sda is not created within the VM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using virtio-scsi-pci?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, should be more efficent than lsi53c895a.
@Mic92 let me run some tests, I will backport unless there are issues. |
backported to 18.09: 174e19d |
This seems to break nix-build "<nixpkgs/nixos>" \
-A config.system.build.virtualBoxOVA \
-I nixos-config=vm.nix vm.nix { config, pkgs, lib, ... }:
{
imports =
[
<nixpkgs/nixos/modules/virtualisation/virtualbox-image.nix>
];
virtualbox = {
baseImageSize = 64 * 1024;
memorySize = 2048;
};
nixpkgs = {
config = {
allowUnfree = true;
};
};
}
|
Yep same error on Hydra for nixos.ova |
''${if isSCSI then | ||
"-device lsi53c895a -device ${diskInterface}-hd,${commonInterfaceArgs}" | ||
else | ||
"-device virtio-blk-pci,scsi=off,${commonInterfaceArgs}"} '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the ''
here? (if isSCSI then ... else ...)
should be enough.
${if cfg.useBootLoader then '' | ||
${mkDiskIfaceDriveFlag "0" "file=$NIX_DISK_IMAGE,cache=writeback,werror=report"} \ | ||
${mkDiskIfaceDriveFlag "1" "file=$TMPDIR/disk.img,media=disk"} \ | ||
-boot menu=on \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this? If the user wants to have a boot menu, they can still provide additional arguments via command line or within the configuration.
''} | ||
'' else '' | ||
${mkDiskIfaceDriveFlag "0" "file=$NIX_DISK_IMAGE,cache=writeback,werror=report"} \ | ||
\''} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it pretty much unreadable, why not ${optionalString cfg.useEFIBoot "-pflash $TMPDIR/bios.bin"} \
?
-device lsi53c895a \ | ||
-device scsi-hd,drive=hd,id=scsi1,bootindex=1 \ | ||
''${diskImage:+-drive file=$diskImage,media=disk,if=none,id=hd,cache=unsafe,werror=report} \ | ||
'' else '' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that when you leave out the \
, the first newline is stripped, so this just adds another superfluous \
to the table for which I don't see any reason here.
'' else '' \ | ||
-drive file=$diskImage,media=disk,if=none,id=hd \ | ||
-device virtio-blk-pci,scsi=off,drive=hd,id=virtio0,bootindex=1 \ | ||
\''} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add the backslash after the }
?
requiredSystemFeatures = [ "kvm" ]; | ||
builder = "${bash}/bin/sh"; | ||
args = ["-e" (vmRunCommand qemuCommandLinux)]; | ||
origArgs = args; | ||
origBuilder = builder; | ||
diskInterface = "${moreArgs.diskInterface}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is not only called by just the qemu-vm
module, so you really need to take care of falling back to a default value.
Thanks for the contribution, however: IMHO this makes the module less readable overall, because it adds another way to handle the backslashes. Ideally we might want to get rid of all that nested antiquotation and either use an attribute set or list to build those arguments. Apart from that, the commit message provides no detail whatsoever about why you did certain things. Unfortunately it already got merged, so I'd suggest to provide more details for commits containing substantial changes in the future :-) Ideally there should be one commit for each logical step. |
I have reverted this on 18.09 in 294060d |
@xeji Ah, I just reverted it on master, you got to release-18.09 before me. I think we should fix the evaluation error before continuing on both branches. |
@srhb: The eval error would be gone by adding In practice however more fixing needs to be done, for example if you look at https://github.com/steveeJ/nixpkgs/blob/f777d2b719be0db4cb7819d5b6dbdd121db29a37/pkgs/build-support/vm/default.nix#L200, the code is essentially a no-op which always falls back to the |
@aszlig I didn't mean (or want) to try and make quickfixes to the existing commit just in order to get eval going again. The revert is fine until we can get it sorted out properly, imo. :) |
Motivation for this change
-netdev
Please let me know if you need me to split into separate commits.
Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)