Commit Graph

233 Commits

Author SHA1 Message Date
WilliButz
0139970416
nixos/qemu-vm: convert tmpfiles rules to settings
This change replaces the previously hard-coded `/boot` path with a
reference to `efiSysMountPoint` and more importantly this change makes
it possible to override these rules in scenarios in which they are not
desired.

One such scenario would be when `systemd-gpt-auto-generator(8)` is used
to automount the ESP. Consider this section from the mentioned manpage:

> The ESP is mounted to /boot/ if that directory exists and is not used
> for XBOOTLDR, and otherwise to /efi/. Same as for /boot/, an automount
> unit is used. The mount point will be created if necessary.

Prior to this change, the ESP would be automounted under `/efi` on first
boot, then the previous tmpfiles rules caused `/boot` to be created.
Following the quote above, this meant that the ESP is mounted under
`/boot` for each subsequent boot.
2024-02-07 16:25:30 +01:00
nikstur
c9569af3e0
Merge pull request #271326 from philiptaron/shutdown.target
treewide: depend on `shutdown.target` if `DefaultDependencies=no` in almost every case
2023-12-27 08:33:26 +01:00
Philip Taron
0a226a0639
nixos/qemu: ensure correct ordering w.r.t. shutdown.target 2023-11-30 15:44:36 -08:00
h7x4
79d3d59f58
treewide: replace mkPackageOptionMD with mkPackageOption 2023-11-30 19:03:14 +01:00
Alyssa Ross
8ab2f09522 nixos/qemu-vm: fix infinite recursion
The virtualisation.directBoot.initrd option was added for netboot
images, but the assertion to check directBoot enabled if it was used
caused an infinite recursion if it was.  Minimal reproduction:

	import nixos/tests/make-test-python.nix ({ pkgs, ... }: {
	  name = "";

	  nodes = {
	    machine = { config, ...}: {
	      imports = [ nixos/modules/installer/netboot/netboot-minimal.nix ];

	      virtualisation.directBoot = {
	        enable = true;
	        initrd = "${config.system.build.netbootRamdisk}/${config.system.boot.loader.initrdFile}";
	      };
	    };
	  };
	  testScript = "";
	}) {}

The fix is to swap the two conditions, so that cfg.directBoot.enable
is checked first, and the initrd comparision will be short circuited.

This wasn't noticed during review because in earlier versions of the
virtualisation.directBoot patch, the assertion was accidentally in the
conditional above, so wasn't evaluated unless port forwarding was in
use.
2023-11-06 13:49:31 +01:00
Robert Hensing
5dfc78a8ad
Merge pull request #262021 from Enzime/linux-builder-cross
linux-builder: support `x86_64-linux` on `aarch64`
2023-10-24 14:34:29 +02:00
Michael Hoang
ab1f45f3d3 linux-builder: support x86_64-linux on aarch64 2023-10-24 13:35:37 +02:00
Ryan Lahfa
b9337215cd
Merge pull request #229035 from NixOS/qemu-vm/tpm
qemu-vm: support TPM usecases
2023-10-23 10:10:27 +01:00
Arthur Gautier
08f4fe2087 qemu-vm: stop the swtpm once qemu stops
The idea is to run an async process waiting for swtpm
and we have to ensure that `FD_CLOEXEC` is cleared on this process'
stdin file descriptor, we use `fdflags` for this, a loadable builtin in
Bash ≥ 5.

The async process when exited will terminate `swtpm`, we bind the
termination of the async process to the termination of QEMU by virtue of
having `qemu` exec in that Bash script.

Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
Co-authored-by: Raito Bezarius <masterancpp@gmail.com>
2023-10-23 01:02:24 +02:00
Raito Bezarius
25872524f0 nixos/qemu-vm: add virtualisation.tpm for running TPM in QEMU infrastructure 2023-10-22 16:01:37 +02:00
Robert Hensing
7096340f9e nixos/qemu-vm: Rename nixos-disk-image -> nix-store-image
For the image that's actually a store image only.
Helps with visibility. The name "nixos-disk-image" has no special
significance, by grepping nixpkgs.
2023-10-21 19:13:58 +02:00
nikstur
62e95d095d nixos/qemu-vm: optionally disable overriding fileSystems
Allow the user to disable overriding the fileSystems option with
virtualisation.fileSystems by setting
`virtualisation.fileSystems = lib.mkForce { };`.

With this change you can use the qemu-vm module to boot from an external
image that was not produced by the qemu-vm module itself. The user can
now re-use the modularly set fileSystems option instead of having to
reproduce it in virtualisation.fileSystems.
2023-10-02 11:13:26 +02:00
Valentin Gagarin
295a5e1e2b
fix capitalization (#254542) 2023-09-15 09:59:11 +02:00
Michael Hoang
98d970bc37 nixos/qemu-vm: use CA certificates from host 2023-07-06 21:32:08 +10:00
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