about summary refs log tree commit diff
path: root/nixos/lib/make-disk-image.nix
AgeCommit message (Collapse)AuthorFilesLines
2024-03-01nixos/lib/make-disk-image.nix: fix systemd-boot-builder clobbering ↵Arian van Putten1-0/+7
/homeless-shelter systemd-boot-builder.py calls nix-env --list-generations which creates $HOME/.nix-defexpr/channels/nixos if it doesn't exist. This would cause a folder /homeless-shelter to show up in the final image which in turn breaks nix builds in the target image if sandboxing is turned off (as /homeless-shelter is never allowed to exist).
2024-02-26nixos/lib/make-disk-image: Add ability to setup an XBOOTLDR partitionSiddhartha1-16/+39
2024-02-15OVMF: Add test with secure boot enabledShea Levy1-0/+3
Co-authored-by: Arthur Gautier <arthur.gautier@arista.com>
2023-12-26nixos/lib/make-disk-image: Create build products metadataMartin Weinelt1-2/+7
For hydra to expose built images for direct download, listing the relevant files in nix-support/hydra-build-products is required.
2023-07-19nixos/lib/make-disk-image: fix installBootLoader for disabled grubPogobanane1-1/+1
This commit is a fixup for a regression introduced by 0bdba6c99bc6db6fd8ea15de3fa10a3c0563ef9f. Before the regression, it was possible to build images without grub or a kernel (e.g. to boot other kernels with qemu -kernel. After the regression, such images fail to build. Since config.boog.loader.grub.enable is false in that scenario, grub.device is emptystring. While this happens not to be an issue of `ln`, `dirname` fails on emptystring. With this change, we guard both commands to only be run when grub is actually enabled. Images with and without grub succesfully build with this change.
2023-06-16nixos/qemu-vm: use persistent block device namesnikstur1-0/+1
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-04-28nixos/lib/make-disk-image: do not compile a full arch QEMU to convert imagesRaito Bezarius1-1/+1
2023-04-16nixos/make-disk-image: fix contents dir pathsLeon Barrett1-3/+8
`make-disk-image` is a tool for creating VM images. It takes an argument `contents` that allows one to specify files and directories that should be copied into the VM image. However, directories end up not at the specified target, but instead at a subdirectory of the target, with a nix-store-like path, e.g. `/target/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-source`. See issue https://github.com/NixOS/nixpkgs/issues/226203 . This change adds a test for make-disk-image's contents directory handling and adds a fix (appending `/` to rsync input directory names). This closes issue https://github.com/NixOS/nixpkgs/issues/226203 .
2023-02-26nixos/lib/make-disk-image: expose memSize parameterNick Bathum1-1/+4
Generating large disk images can fail from out-of-memory in vm-run.
2022-12-24nixos/lib/make-disk-image: docs, UEFI vars recording, more determinismRaito Bezarius1-13/+180
- Extensive documentation in NixOS manual - Deterministic mode that fixes various identifiers relative to disk partitions and filesystems in ext4 case - UEFI variable recording
2022-04-05make-disk-image: add systemdMinimal to PATHlassulus1-0/+1
this is needed to setup /tmp inside the chroot. which is needed by systemd-boot to sucessfully install
2021-11-29make-disk-image: Make additionalPaths work with Nix 2.4talyz1-1/+1
The `nix` command is marked as experimental since 2.4, so an extra flag is required to unlock it.
2021-10-28make-disk-image: Add an argument to only build a Nix store imagetalyz1-17/+32
Add the `onlyNixStore` argument which enables building images containing the contents of the Nix store at the root, instead of a full system.
2021-10-28make-disk-image: Add additionalPaths argumenttalyz1-1/+13
Add an argument which makes it possible to add additional paths to the image's nix store.
2021-10-28make-disk-image: Add copyChannel argumenttalyz1-2/+12
Add a copyChannel argument which controls whether the current source tree will be made available as a nix channel in the image or not. Previously, it always was. Making it available is useful for interactive use of nix utils, but changes the hash of the image when the sources are updated.
2021-10-28make-disk-image: Reintroduce the installBootLoader argumenttalyz1-4/+9
installBootLoader was removed in f1708a9d7d79e2bf2961fc648625578b23b3460f; probably by mistake, since only the logic was removed, not the argument.
2021-06-21make-disk-image: Reduce forkingCasey Ransom1-1/+1
The disk image calculator was using find + exec forking du for every file in the disk image, making it very slow. Change du to accept files, nul delimeted on stdin to speed it back up. Before change: nix-build nixos/tests/image-contents.nix 9.71s user 1.06s system 8% cpu 2:13.11 total After change: nix-build nixos/tests/image-contents.nix 9.93s user 1.23s system 21% cpu 51.601 total
2021-04-26Merge pull request #120489 from samueldr/fix/make-disk-image-auto-sizeLassulus1-6/+69
Fix make disk image automatic size
2021-04-26make-disk-image: fix broken EFI image buildsMartin Schwaighofer1-0/+3
Work around missing /dev files inside runInLinuxVM by creating a symlink before calling nixos-enter. This fixes https://github.com/NixOS/nixpkgs/issues/93381. I ran into this issue when trying to create a VMware image that boots from EFI. Thanks @colemickens for reporting this and @danielfullmer for fixing the same thing in in qemu-vm.nix (37676e77cb5adab936606838d6465faafda54f61) and explaining what the issue was.
2021-04-25make-disk-image: Round image size to the next mebibyteSamuel Dionne-Riel1-2/+12
This ensures the following gptfdisk warning won't happen: ``` Warning: File size is not a multiple of 512 bytes! Misbehavior is likely! ``` Additionally, helps towards aligning the partition to be more optimal for the underlying storage. It is actually impossible to align for the actual underlying storage optimally because we don't know what the block device will be! But aligning on 1MiB should help.
2021-04-24make-disk-image: Account for reserved disk spaceSamuel Dionne-Riel1-2/+19
This is a bit of a thorny issue. See, the actual `diskSize` variable is for the *total* disk size, not for the filesystem! The automatic numbers are meant to compute the *filesystem* required space. So we have to add any other reserved space! We have different requirements for reserved space. E.g. there could be none (when it's actually a filesystem image). There could also be 1MiB for alignment for an MBR image, legacy+gpt needs 2MiB, then GPT with an ESP ("bootSize") needs to take the boot partition and GPT size into account too! Though luckily(?) for this latter situation we can cheat! As noted in the change, `bootSize` is NOT the boot partition size. It is actually the offset where the target filesystem starts.
2021-04-24make-disk-image: Account for the ext4 reserved spaceSamuel Dionne-Riel1-6/+20
Reserved space includes: - inodes space in use (2 blocks per) - about 5.2% of the space The 5.2% reserved space was computed empirically when working on a previous EXT4 image builder. It seems to stabilize around 5% even for much larger filesystems.
2021-04-24make-disk-image: Get proper size for automatic sizeSamuel Dionne-Riel1-6/+28
On some filesystems, `du` without `--apparent-size` will not give the actual size for a file. Using `--apparent-size` will give us the actual file size. Though, this is not actually correct still. 1000 × 1 bytes is not 1000 bytes. It is 1000 × ceil(filesize/blockSize)*blockSize. So instead of adding up the actual file sizes. We are adding up the block sizes. Note that this also changes the builder to work with *bytes*, rather than with any other units. Doing maths on bytes is less likely to go awry than doing it on other units.
2021-01-29Merge pull request #67493 from clefru/make-disk-imageJörg Thalheim1-1/+2
2021-01-22Update nixos/lib/make-disk-image.nixclefru1-1/+1
Co-authored-by: Alyssa Ross <hi@alyssa.is>
2020-12-20nixos/lib/make-disk-image.nix: support content mode and ownershipFrancesco Gazzetta1-5/+43
2020-11-24utillinux: rename to util-linuxGraham Christensen1-2/+2
2020-10-30make-disk-image: support legacy+gptGraham Christensen1-1/+15
2020-07-31nixos/lib/make-disk-image.nix: abritary format inputEmery Hemingway1-1/+1
Pass unrecognized format types as the output file extension to qemu-img. The motivation is support for "vdi" output.
2020-07-27make-disk-image: add hybrid and dynamic sized imageslassulus1-23/+56
2020-07-10nixos make-disk-image: fix permissions of /buildlassulus1-0/+1
This was broken in 460c0d6 (PR #90431); now the nixos-unstable channel should get unblocked. vcunat modified this commit to use env-var instead of hardcoding /build
2020-06-13nixos/lib/make-disk-image.nix: VDI supportEmery Hemingway1-1/+2
2019-10-07Revert "make-disk-image: replace nixos-install by nix-env calls"Eelco Dolstra1-11/+3
This reverts commit e9bf955fd6d5ffda218878ba561c93c6a28dfe8e. We use nixos-install to ensure that make-disk-image produces the same result as a regular installation (9802da517fe4da41d68516029b01c5c1f175b3e4) and to reduce code duplication. If there is something broken in nixos-install, it should be fixed there.
2019-09-29make-disk-image: replace nixos-install by nix-env callsChristian Kögler1-3/+11
nixos-install can only be called from a machine
2019-08-26make-disk-image.nix: Handle cptofs error explicitlyClemens Fruhwirth1-1/+2
Because the copy process inside the VM does not reliably give "No space" error message leaving the user wondering what went wrong: unable to create directory /mnt/0000fe01///nix/store/yknzxx7w2ck9p30k81gpi5yfjlrq41lr-libsecret-0.18.7/share/locale/ro: Success [ 5.462365] reboot: Restarting system error processing entry /build/root/nix/store/yknzxx7w2ck9p30k81gpi5yfjlrq41lr-libsecret-0.18.7/share/locale/ro, aborting error processing entry /build/root/nix/store/yknzxx7w2ck9p30k81gpi5yfjlrq41lr-libsecret-0.18.7/share/locale, aborting error processing entry /build/root/nix/store/yknzxx7w2ck9p30k81gpi5yfjlrq41lr-libsecret-0.18.7/share, aborting error processing entry /build/root/nix/store/yknzxx7w2ck9p30k81gpi5yfjlrq41lr-libsecret-0.18.7, aborting error processing entry /build/root/nix/store, aborting error processing entry /build/root/nix, aborting builder for '/nix/store/fsdvqxq92iai7f3w8wcsncgfwag7cj2l-libvirtd-ssh-image.drv' failed with exit code 228
2019-01-24Add options to build disk image function (#50239)Travis Athougies1-2/+5
* add options to build disk image function * Revert suffix changes
2019-01-07make-disk-image: use filterSource instead of cleanSourceMatthew Bauer1-1/+1
cleanSource does not appear to work correctly in this case. The path does not get coerced to a string, resulting in a dangling symlink produced in channel.nix. Not sure why, but this seems to fix it. Fixes #51025. /cc @elvishjericco
2018-07-20[bot] nixos/*: remove unused arguments in lambdasvolth1-3/+0
2018-02-27Fix installing the Nixpkgs channel on the installation mediaEelco Dolstra1-1/+2
And test that it got installed correctly.
2018-02-22Merge remote-tracking branch 'origin/master' into nix-2.0Eelco Dolstra1-2/+2
2018-02-18nixos: rename config.system.nixos* -> config.system.nixos.*Jan Malakhovski1-2/+2
2018-02-07make-disk-image.nix: Use nixos-install againEelco Dolstra1-22/+25
Since nixos-install doesn't require any special privileges anymore, this Just Works. No more need for fakeroot / nixos-prepare-root.
2018-01-22nixos/make-disk-image.nix: Support EFI imagesTuomas Tynkkynen1-18/+64
- Add a new parameter `imageType` that can specify either "efi" or "legacy" (the default which should see no change in behaviour by this patch). - EFI images get a GPT partition table (instead of msdos) with a mandatory ESP partition (so we add an assert that `partitioned` is true). - Use the partx tool from util-linux to determine exact start + size of the root partition. This is required because GPT stores a secondary partition table at the end of the disk, so we can't just have mkfs.ext4 create the filesystem until the end of the disk. - (Unrelated to any EFI changes) Since we're depending on the `-E offset=X` option to mkfs which is only supported by e2fsprogs, disallow any attempts of creating partitioned disk images where the root filesystem is not ext4.
2017-12-20make-disk-image.nix: Really fix write permissions in the storeTuomas Tynkkynen1-1/+1
I think the current one applies the -exec only to those that match '-type d'. Let's switch it to something that humans can understand...
2017-12-17make-disk-image.nix: Remove write permissions from /nix/storeTuomas Tynkkynen1-0/+3
Fakeroot seems to always give the owner write bit to any files touched inside it (presumably to easily simulate the fact that root can still modify such files). So do an explicit chmod to remove them. This should finally solve #32242 after the EC2 images are regenerated with this change. https://hydra.nixos.org/build/66143116
2017-12-12build-support/vm: Use devtmpfs, not static device nodesTuomas Tynkkynen1-2/+0
In 2017, there is no reason to create a static /dev.
2017-11-13make-disk-image: fix evalOrivej Desh1-1/+1
2017-11-12make-disk-image: embed compression switch into the format nameOrivej Desh1-6/+6
2017-11-12make-disk-image: add compressed option to compress qcow2 imagesOrivej Desh1-1/+6
2017-11-12make-disk-image: clean upOrivej Desh1-7/+6