nixos-generators icon indicating copy to clipboard operation
nixos-generators copied to clipboard

Override disk image size and squashfs compression

Open copy opened this issue 4 years ago • 8 comments

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.

copy avatar May 23 '20 20:05 copy

Using --format-path is a way to do this.

copy avatar May 23 '20 21:05 copy

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

Lassulus avatar May 26 '20 20:05 Lassulus

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;
}

copy avatar May 27 '20 00:05 copy

I implemented a PR for nixpkgs which could solve some of the issues: https://github.com/NixOS/nixpkgs/pull/89331

Lassulus avatar Jun 01 '20 22:06 Lassulus

@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.

copy avatar Jun 02 '20 01:06 copy

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

Lassulus avatar Apr 19 '22 17:04 Lassulus

Also run into this today because the build was timing out with 600 max-silent-time.

SuperSandro2000 avatar May 24 '22 16:05 SuperSandro2000

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)

Lassulus avatar May 24 '22 18:05 Lassulus

👍 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.

mikepurvis avatar Jun 15 '23 02:06 mikepurvis

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).

mikepurvis avatar Jun 15 '23 02:06 mikepurvis

Seems to be fixed then.

copy avatar Jun 26 '23 03:06 copy