nixos-generators
nixos-generators copied to clipboard
Override disk image size and squashfs compression
I'm building a fairly large image for testing in VM and run into some issues:
The qcow and raw formats fail with the error below, probably because the disk size is hard-coded
copying path '/nix/store/c7zffvkqmyapgj9m9skdhhci2qjw0v9j-nixos-system-nixos-20.09pre226148.0f5ce2fac0c' to 'local'...
copying channel...
preallocating file of 470627 bytes: No space left on device
error: path '/nix/store/ygkxj7psmiril30n0a9qawydkk05gy61-nixos-20.09pre226148.0f5ce2fac0c' does not exist and cannot be created
builder for '/nix/store/wjgcnaj420djrpcl5sb51ralqa9g6iiy-nixos-disk-image.drv' failed with exit code 1
note: build failure may have been caused by lack of free disk space
error: build of '/nix/store/wjgcnaj420djrpcl5sb51ralqa9g6iiy-nixos-disk-image.drv' failed
The iso image works, but the squashfs command takes very long.
Using --format-path
is a way to do this.
Not sure I follow you. Could you post a config to reproduce the issue?
also, yes the diskSize is currently hardcoded, making it dynamic requires upstream work. I'm trying to work on a modification to make-disk-image.nix to create the diskSize based on the files copied to it, with an optional parameter of addtionalDiskSpace
Any sufficiently large built image should reproduce this, below is a slightly silly example.
{ config, pkgs, ... }: {
environment.systemPackages = with pkgs; [
firefox thunderbird
awesome redshift xlockmore scrot
zsh
ripgrep
neomutt offlineimap elinks
git mercurial subversion
kitty
neovim
evince mupdf
chromium
pulseaudio
youtube-dl
opam
z3
mpv cmus
ffmpeg
wireguard wireguard-tools
gimp
pandoc
qemu
docker
wireshark-qt
qutebrowser
libreoffice
];
services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome3.enable = true;
}
I implemented a PR for nixpkgs which could solve some of the issues: https://github.com/NixOS/nixpkgs/pull/89331
@Lassulus Thanks! What do you think about improving squashfs speed by letting the user specify a faster compression method? -f iso
already supports large images, but takes very long to build the image.
better late than never: It would be nice to have squashfs optionally, since compressing everything takes forever when debugging something. Sadly I don't know how to do this and I didn't find any easy exposed options in nixpkgs to allow for this
Also run into this today because the build was timing out with 600 max-silent-time.
well making squashfs optional is also something which needs to be done upstream. so not much I can do in nixos-generators I guess (but didn't really take a deep look)
👍 to being able to lower the compression on the squashfs step— for quick iteration and one-off use-cases, it's often desirable to favor time over storage.
Actually, it turns out it's pretty easy as of https://github.com/NixOS/nixpkgs/pull/94660, just pass isoImage.squashfsCompression
:
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, nixos-generators, ... }: {
packages.x86_64-linux = {
iso = nixos-generators.nixosGenerate {
system = "x86_64-linux";
modules = [
# you can include your own nixos configuration here, i.e.
# ./configuration.nix
];
customFormats = {
install-iso-minimal = {
imports = [
"${toString nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
];
systemd.services.sshd.wantedBy = nixpkgs.lib.mkForce ["multi-user.target"];
isoImage.squashfsCompression = "zstd -Xcompression-level 3";
formatAttr = "isoImage";
filename = "*.iso";
};
};
format = "install-iso-minimal";
};
};
};
}
The iso part of that build is only 2m for me (and the final result is as expected a little bigger).
Seems to be fixed then.