Commit Graph

219 Commits

Author SHA1 Message Date
nikstur
f6b37ddaf2 nixos/qemu-vm: use cfg.host.pkgs 2023-06-24 00:45:15 +02:00
nikstur
0bdba6c99b nixos/qemu-vm: use persistent block device names
This change removes the bespoke logic around identifying block devices.
Instead of trying to find the right device by iterating over
`qemu.drives` and guessing the right partition number (e.g.
/dev/vda{1,2}), devices are now identified by persistent names provided
by udev in /dev/disk/by-*.

Before this change, the root device was formatted on demand in the
initrd. However, this makes it impossible to use filesystem identifiers
to identify devices. Now, the formatting step is performed before the VM
is started. Because some tests, however, rely on this behaviour, a
utility function to replace this behaviour in added in
/nixos/tests/common/auto-format-root-device.nix.

Devices that contain neither a partition table nor a filesystem are
identified by their hardware serial number which is injecetd via QEMU
(and is thus persistent and predictable). PCI paths are not a reliably
way to identify devices because their availability and numbering depends
on the QEMU machine type.

This change makes the module more robust against changes in QEMU and the
kernel (non-persistent device naming) and by decoupling abstractions
(i.e. rootDevice, bootPartition, and bootLoaderDevice) enables further
improvement down the line.
2023-06-16 19:36:03 +02:00
Raito Bezarius
610f60231f nixos/qemu-vm: introduce virtualisation.directBoot
As with many things, we have scenarios where we don't want to boot on a
disk / bootloader and also we don't want to boot directly.

Sometimes, we want to boot through an OptionROM of our NIC, e.g. netboot
scenarios or let the firmware decide something, e.g. UEFI PXE (or even
UEFI OptionROM!).

This is composed of:

- `directBoot.enable`: whether to direct boot or not
- `directBoot.initrd`: enable overriding the
  `config.system.build.initialRamdisk` defaults, useful for
  netbootRamdisk for example.

This makes it possible.
2023-06-09 14:51:18 +02:00
nikstur
003fec835c nixos/qemu-vm: remove grub references from useBootLoader description 2023-06-01 01:38:08 +02:00
nikstur
8ea8154a32 nixos/qemu-vm: (re-)move old/incorrect comments 2023-06-01 01:38:06 +02:00
Raito Bezarius
09d1022782 nixos/qemu-vm: fix 32-bits assert for memorySize
It should be an implication, rather than &&.
2023-05-27 17:20:08 +02:00
Ryan Lahfa
537c6ede55
Merge pull request #234266 from emilylange/qemu-vm-2047mb
nixos/qemu-vm: add `virtualisation.memorySize < 2048` assertion on 32bit
2023-05-27 15:31:00 +02:00
emilylange
5dbd4f3243
nixos/qemu-vm: add virtualisation.memorySize < 2048 assertion on 32bit 2023-05-26 19:43:58 +02:00
Graham Dennis
93502aa3b1 nixos/qemu-vm: add option for named network interfaces
Adds a new option to the virtualisation modules that enables specifying explicitly named network interfaces in QEMU VMs.
The existing `virtualisation.vlans` option is still supported for cases where the name of the network interface is irrelevant.
2023-05-24 08:54:20 +10:00
Vladimír Čunát
5674901601
Revert "nixos/qemu-vm: fix diskless VMs" 2023-05-06 21:41:14 +02:00
Ryan Lahfa
1ab4d7d0c3
Merge pull request #228047 from RaitoBezarius/diskless-vm
nixos/qemu-vm: fix diskless VMs
2023-05-05 15:37:11 +02:00
Peter Kling
996db6d059
virtualisation/qemu-vm: escape bash variable in shell script
Fixes #229729
2023-05-04 09:52:49 +02:00
Raito Bezarius
6e8248c8b2 nixos/qemu-vm: make it possible to use UEFI without bootloaders
`useEFIBoot` is somewhat misleading, but we should make it possible to
enable UEFI environment / firmware without buying into a bootloader.

This makes it possible.
2023-05-02 23:20:03 +02:00
Raito Bezarius
be4e7ef905 nixos/qemu-vm: fix diskless VMs
Previously, it was possible to run with a tmpfs / with
`virtualisation.diskImage = null;`, this was likely broken by my changes
in 4b4e4c3ef9.

It is reintroduced by disabling properly the bootloader for now, as it
is complicated to make it work with.
2023-04-25 02:12:26 +02:00
Raito Bezarius
0df5257b82 nixos/qemu-vm: introduce virtualisation.mountHostNixStore option
Now that `useBootLoader` produces a full system image, moving disk
images can be slow because they have a full Nix store in them.

It does not make sense to keep the 9p mountpoint to shadow the
/nix/store of the VM.

We disable it if we have `useBootLoader` and introduce an option for
easy overrides.
2023-04-23 23:58:46 +02:00
Florian Klink
6b27ed3229
Merge pull request #169116 from ElvishJerricco/systemd-stage-1-networkd
Systemd stage 1 networkd
2023-04-21 18:40:59 +02:00
Raito Bezarius
614b83a328 nixos/virtualisation/qemu-vm: remove persistBootDevice option
This option has been introduced in 678eed323f without realizing there was this
PR inflight, unfortunately, it collide with what this PR does and make
it irrelevant.

Therefore, I remove it here.
2023-04-21 13:00:19 +02:00
Raito Bezarius
76c7b656bf nixos/qemu-vm: refactor bootDisk generation using make-disk-image 2023-04-21 13:00:18 +02:00
Artturi
b83db86a9e
Merge pull request #222080 from Stunkymonkey/nixos-optionalString 2023-04-20 16:07:30 +03:00
Will Fancher
fef26d88e2 systemd-initrd: Support secrets when boot loader doesn't
initrd-secrets: Fix service config with systemd-stage-1
2023-04-11 15:20:47 -04:00
Felix Buehler
327b0cff7a treewide: use more lib.optionalString 2023-04-07 13:38:33 +02:00
Sandro Jäckel
a5d95ac5fc
nixos/tmp: move /tmp options under boot.tmp 2023-03-19 18:49:37 +01:00
Martin Weinelt
d03d74aa67
Merge remote-tracking branch 'origin/master' into staging-next
Conflicts:
- pkgs/development/python-modules/aiopulse/default.nix
- pkgs/development/python-modules/identify/default.nix
- pkgs/development/python-modules/spur/default.nix
2023-03-12 23:28:23 +01:00
Guillaume Girol
db901673ea
Merge pull request #209156 from pwaller/issue-114594
nixos/grub: Name initrd-secrets by system, not by initrd
2023-03-12 18:50:33 +00:00
github-actions[bot]
98d00577f6
Merge master into staging-next 2023-03-09 06:01:01 +00:00
Will Fancher
46089f7efe
Merge pull request #217886 from lilyinstarlight/fix/qemu-vm-initrd-mkdir-0755
nixos/qemu-vm: fix minor typo
2023-03-08 19:17:28 -05:00
Frederik Rietdijk
8cf8d77121 Merge master into staging-next 2023-03-04 09:38:25 +01:00
Lily Foster
e78dc938d8
nixos/qemu-vm: fix minor typo
The typo creates an empty directory 0755 in initrd rootfs rather than
create the Nix store directories with mode 0755.

I guess setting the mode is not strictly necessary if it worked before
this change, but I'll leave the `-m 0755` in just in case.
2023-02-23 13:01:53 -05:00
Will Fancher
a0ba973e13 qemu-vm: Simplfiy systemd-initrd /nix/store mount units 2023-02-07 22:22:39 -05:00
Will Fancher
1b39491326 systemd-stage-1: Use x-initrd.mount for better unit dependencies 2023-02-07 22:22:39 -05:00
Vladimír Čunát
23ce77d76e Revert #178290: nixos/virtualisation: add option
...for explicitly named network interfaces

This reverts commit 6ae3e7695e.
(and evaluation fixups 08d26bbb72 7aed90a969)
Some of the tests fail or time out after the merge.
2023-01-30 07:55:50 -08:00
Linus Heckemann
09f76e171e Merge remote-tracking branch 'upstream/nixos-unstable' into stateless-vms 2023-01-28 11:27:21 +01:00
Ryan Lahfa
8803f1da66
Merge pull request #178290 from andrew-hoff/ahh/qemu-interfaces
nixos/virtualisation: add option for explicitly named network interfaces
2023-01-25 17:32:53 +01:00
Andrew Hoff
6ae3e7695e nixos/virtualisation: add option for explicitly named network interfaces
Adds a new option to the virtualisation modules that enables specifying
explicitly named network interfaces in QEMU VMs. The existing
`virtualisation.vlans` is still supported for cases where the name of
the network interface is irrelevant.
2023-01-22 12:20:40 -05:00
Peter Waller
678eed323f nixos/grub: Name initrd-secrets by system, not by initrd
Previously, secrets were named according to the initrd they were
associated with. This created a problem: If secrets were changed whilst
the initrd remained the same, there were two versions of the secrets
with one initrd. The result was that only one version of the secrets would
by recorded into the /boot partition and get used. AFAICT this would
only be the oldest version of the secrets for the given initrd version.

This manifests as #114594, which I found frustrating while trying to use
initrd secrets for the first time. While developing the secrets I found
I could not get new versions of the secrets to take effect.
Additionally, it's a nasty issue to run into if you had cause to change
the initrd secrets for credential rotation, etc, if you change them and
discover you cannot, or alternatively that you can't roll back as you
would expect.

Additional changes in this patch.

* Add a regression test that switching to another grub configuration
  with the alternate secrets works. This test relies on the fact that it
  is not changing the initrd. I have checked that the test fails if I
  undo my change.

* Persist the useBootLoader disk state, similarly to other boot state.
  * I had to do this, otherwise I could not find a route to testing the
    alternate boot configuration. I did attempt a few different ways of
    testing this, including directly running install-grub.pl, but what
    I've settled on is most like what a user would do and avoids
    depending on lots of internal details.
  * Making tests that test the boot are a bit tricky (see hibernate.nix
    and installer.nix for inspiration), I found that in addition to
    having to copy quite a bit of code I still couldn't get things to
    work as desired since the bootloader state was being clobbered.

My change to persist the useBootLoader state could break things,
conceptually. I need some help here discovering if that is the case,
possibly by letting this run through a staging CI if there is one.

Fix #114594.

cc potential reviewers:

@lopsided98 (original implementer) @joachifm (original reviewer),
@wkennington (numerous fixes to grub-install.pl), @lheckemann (wrote
original secrets test).
2023-01-21 17:19:26 +00:00
Thomas Watson
8736edfd95 nixos/qemu-vm: fix useBootLoader builds on aarch64-linux
The aarch64-linux kernel and initrd recently eclipsed 60M, causing the
boot disk image build to run out of space and fail. Double the size of
the image to 120M to fix the issue.

The disk image is stored in expandable qcow2 format, so only the space
actually used by files in the image is consumed. Therefore, other
architectures are not unfairly penalized, and the output size does not
suddenly double.

This also fixes NixOS tests which use this option, like systemd-boot's.
2023-01-19 23:28:01 -06:00
Robert Hensing
e973da60cd
Merge pull request #200225 from pacien/nixos-qemu-vm-restrictnetwork
nixos/qemu-vm: add option "restrictNetwork"
2023-01-13 21:47:21 +01:00
K900
2d3cf010fe
Revert "treewide: use nativeBuildInputs with runCommand instead of inlining" 2022-12-26 21:05:35 +03:00
Linus Heckemann
246d09fea2 qemu-vm: use nixos module patterns for filesystems 2022-12-20 20:35:40 +01:00
Linus Heckemann
bf41254a8a nixos/qemu-vm: allow use without a disk image 2022-12-19 12:04:13 +01:00
Sandro Jäckel
26f704b545
treewide: use nativeBuildInputs with runCommand instead of inlining 2022-12-18 23:36:40 +01:00
Naïm Favier
0ff3b35356 nixos/doc: fix some options 2022-12-08 17:52:52 +01:00
Naïm Favier
e8927c46b8
nixos/doc: document mkOrder and friends
Add a section on ordering option definitions.

Also mention `mkDefault` in the section on `mkOverride`.

Clarify the code a bit by renaming `defaultPriority` to
`defaultOverridePriority` and introducing `defaultOrderPriority`.
2022-12-02 14:15:24 +01:00
Ryan Lahfa
a8a68c3427
Merge pull request #189935 from baloo/baloo/qemu-vm/fixup-efi-partitions
qemu-vm: ensure we do not overwrite the partition table when EFI is in use
2022-12-01 15:16:23 +01:00
pacien
e039cb9d97 nixos/qemu-vm: add option "restrictNetwork"
This adds an option to the qemu virtualisation module to isolate the
guest's from the host's and outside networks.

This is particularly useful for development sandboxes for example.

The option is disabled by default to preserve the current behaviour.
2022-11-08 17:54:31 +01:00
pennae
d98322834b nixos/*: fix docbook deprecation notices
mostly no rendering changes except in buildkite, which used markdown
where docbook was expected without marking up its markdown.
2022-09-10 18:23:13 +02:00
Arthur Gautier
7f026cc6d0 qemu-vm: ensure we do not overwrite the partition table when EFI is in use 2022-09-05 17:18:06 -07:00
pennae
3bddcf5f90
Merge branch 'master' into option-docs-md 2022-09-01 16:10:09 +02:00
pennae
722b99bc0e nixos/*: convert options with admonitions to MD
rendering changes only slightly, most changes are in spacing.
2022-08-31 16:36:16 +02:00
pennae
9547123258 nixos/*: convert internal option descriptions to MD
we'll have to do it eventually, may as well be now.
2022-08-31 16:32:54 +02:00