Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qcow2 disk size not set to auto #288

Closed
a-h opened this issue Feb 3, 2024 · 3 comments
Closed

qcow2 disk size not set to auto #288

a-h opened this issue Feb 3, 2024 · 3 comments

Comments

@a-h
Copy link
Contributor

a-h commented Feb 3, 2024

The qcow2 disk image seems set to 8192 in https://github.com/nix-community/nixos-generators/blob/896f6589db5b25023b812bbb6c1f5d3a499b1132/formats/qcow.nix#L32C16-L32C20

When building a large disk image, it's likely you'll receive the following error:

ERROR: cptofs failed. diskSize might be too small for closure.

This comment suggests using a module to override the behaviour: #150 (comment)

However, applying the module within the flake.nix doesn't make any difference.

      packages.vm = forAllHostnames ({ system, pkgs, hostname }: nixos-generators.nixosGenerate {
        system = system;
        modules = [
          # Pin nixpkgs to the flake input, so that the packages installed
          # come from the flake inputs.nixpkgs.url.
          ({ ... }: { nix.registry.nixpkgs.flake = nixpkgs; })
          # Make the disk bigger to avoid "ERROR: cptofs failed. diskSize might be too small for closure."
          ({ lib, ... }: {
            system.build.qcow = lib.mkDefault {
              diskSize = lib.mkForce "auto";
              additionalSpace = "10G";
            };
          })
          # Install all tools.
          ./tools.nix
          # Apply the rest of the config.
          ./configuration.nix
        ];
        format = "qcow2";
      });

And neither does setting it in the configuration.nix:

{ pkgs, lib, hostname, github-url, ... }: {
  networking = {
    hostName = hostname;
  };
  # Enable the OpenSSH server.
  services.openssh = {
    enable = true;
  };
  # Lots of other stuff...
  system.build.qcow = lib.mkDefault {
    diskSize = lib.mkForce "auto";
    additionalSpace = "10G";
  };
  system.stateVersion = "23.11";
}

However, if I switch to the raw image format, everything works well. Presumably because raw images use the "auto" setting?

Is there a reason why diskSize isn't set to auto for qcow2 images?

@a-h
Copy link
Contributor Author

a-h commented Feb 3, 2024

The change to add auto resizing images was added in NixOS/nixpkgs#89331

Not sure if this is the same issue, but in a different format: #279

There's some people out there running out of /tmp space, but that's not me, I've got >100GB free (https://discourse.nixos.org/t/disk-size-too-small-when-generating-qcow2-image/35281)

@jalseth
Copy link
Contributor

jalseth commented Feb 10, 2024

I had a similar problem, except that I want to use a specific size rather than "auto", so I opened a PR: #292.

@a-h
Copy link
Contributor Author

a-h commented Feb 15, 2024

From reading @jalseth's PR, it looks like it resolves this issue. I've moved to using raw images as a result of the issue, so I haven't got a test to hand.

I'll close this.

@a-h a-h closed this as completed Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants