Skip to content

Qemu restoration#127933

Merged
nrdxp merged 11 commits intoNixOS:masterfrom
rnhmjoj:qemu-restoration
Sep 29, 2021
Merged

Qemu restoration#127933
nrdxp merged 11 commits intoNixOS:masterfrom
rnhmjoj:qemu-restoration

Conversation

@rnhmjoj
Copy link
Contributor

@rnhmjoj rnhmjoj commented Jun 23, 2021

Motivation for this change

The NixOS QEMU module has always been in pretty degraded
state: most of the options are not type-checked or
documented (I think the reason is that the module is not
in the manual, can we fix this too?). Manipulating the
qemu.options is painful and qemu.networkingOptions
makes a very good footgun. Lots of options are hard-coded
and it's not clear how to override them1.

So, here I try to clean up things a bit and adding some
higher-level options for

  • Forwarding ports
  • Sharing directories via 9pfs
  • Changing screen resolution

The change is quite big but I tried to break into smaller commits.

Things done
  • Tested virtualisation.resolution
  • Tested host port forwarding
  • Tested guest port forwarding
  • Tested directory sharing (/nix/store itself is done using the new option)
  • Tested nixos-rebuild build-vm
  • Tested nixos-build-vms
  • Tested several nixosTests
  • 21.11 Release Notes
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Jun 23, 2021
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jun 23, 2021
@rnhmjoj rnhmjoj force-pushed the qemu-restoration branch from c4e69df to 55c2d09 Compare June 23, 2021 17:18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see many changes of the kind that would also be suggested by the tool shellcheck - did you run that tool on the result and got the inspiration for the tool from there?

Maybe we could have shellcheck run over the output automatically?
(In that case it might also help if the script would be less concatenated from nix snippets)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I run shellcheck on the result/bin/run-machine-vm script and applied the changes to the Nix code.
I guess It could be added as a checkPhase to the writer functions (writeShellScript, etc.), but I'm not sure what the performance penality would be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shellcheck is usually pretty fast but the problem I with adding that is that we probably need to disable some checks and also add a lot more ignore comments at false positives.

@rnhmjoj rnhmjoj force-pushed the qemu-restoration branch from 55c2d09 to 21f3338 Compare June 24, 2021 15:07
@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jun 24, 2021

Fixed guest fowarding and added assertions for common mistakes.

@rnhmjoj rnhmjoj force-pushed the qemu-restoration branch from 21f3338 to 9723b04 Compare June 30, 2021 19:49
@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jun 30, 2021

I fixed another bug introduced with the qemu-common renaming.
I also tested nixos-rebuild build-vm and run a bunch of nixosTests: at this point I'm fairly certain it should break too many things.

@rnhmjoj rnhmjoj force-pushed the qemu-restoration branch from 9723b04 to 1eabb67 Compare July 19, 2021 20:19
@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jul 19, 2021

Fixed a typo.

Copy link
Member

@piegamesde piegamesde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it out and it indeed fixes #134318. Also the changes of the default values are deeply appreciated. I only reviewed the first commits in detail though.

@piegamesde piegamesde requested a review from andir September 10, 2021 12:53
@andir
Copy link
Member

andir commented Sep 10, 2021

@ofborg test simple

@github-actions github-actions bot added 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation labels Sep 15, 2021
@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Sep 15, 2021

Rebased and added a release note. Also, I enabled the documentation of these options in the manual, by default.

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Sep 18, 2021

Rebased againd a fixed a couple of conflict.
I think this PR is pretty much ready to go, can you finish your review @andir?

Copy link

@nrdxp nrdxp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks like a very nice and welcome clean up, especially the type additions. None of my remarks are hard blockers I'd say. Good work!

Comment on lines +130 to +144
${qemu}/bin/qemu-img create -f qcow2 -F qcow2 -b ${bootDisk}/disk.img "$TMPDIR/disk.img" || exit 1

NIX_EFI_VARS=$(readlink -f ''${NIX_EFI_VARS:-${cfg.efiVars}})
NIX_EFI_VARS=$(readlink -f "''${NIX_EFI_VARS:-${cfg.efiVars}}")

${if cfg.useEFIBoot then ''
${lib.optionalString cfg.useEFIBoot
''
# VM needs writable EFI vars
if ! test -e "$NIX_EFI_VARS"; then
cp ${bootDisk}/efi-vars.fd "$NIX_EFI_VARS" || exit 1
chmod 0644 "$NIX_EFI_VARS" || exit 1
fi
'' else ""}
'' else ""}
''}
''}

cd $TMPDIR
idx=0
cd "$TMPDIR" || exit 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be better to use a simple set -e on the script rather than all these explicit exits?


<warning><para>
If the NixOS firewall on the virtual machine is enabled, you also
have to open the guest ports to enable the traffic between host and
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we not open the same firewall ports ourselves using a gatekeeping option that some modules have, i.e. openPorts?

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Sep 29, 2021 via email

@dasJ
Copy link
Member

dasJ commented Sep 29, 2021

Did you break unstable-small again?

From our Hydra (don't mind the weird name of nixpkgs):

in job ‘nixos.tests.boot.biosCdrom’:
error: getting status of '/nix/store/nd3fl6bqmw44adz0grd18v6i9jq21zr6-nixpkgs-patched/nixos/lib/qemu-flags.nix': No such file or directory

Probably because of this file:

nixos/tests/boot.nix:with import ../lib/qemu-flags.nix { inherit pkgs; };

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Sep 29, 2021

It seems nixosTests.boot was changed to import qemu-flags.nix after I tested the commit that renamed qemu-flags.

noteed added a commit to hypered/curiosity that referenced this pull request Jul 30, 2022
The way `networkingOptions` works seems to have change following
NixOS/nixpkgs#127933.
@rnhmjoj rnhmjoj deleted the qemu-restoration branch July 10, 2023 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants