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

overriding system.build.raw doesn't have any effect

Open DavHau opened this issue 5 years ago • 15 comments

building with format raw while trying to override the image size:

system.build.raw.diskSize = mkForce 4096;

Doesn't have any effect on the disk size.

DavHau avatar Oct 20 '20 15:10 DavHau

yes, sadly all the different images use different code/options to specify their size. for the raw image itself there is no easy way to do it then to import make-disk-image.nix with the correct arguments:

  system.build.raw = lib.mkForce (import <nixpkgs/nixos/modules/lib/make-disk-image.nix> {
    inherit lib config pkgs;
    diskSize = 4096;
  });

This is also more of an upstream issue and I wanted to fix it at some point

Lassulus avatar Oct 22 '20 07:10 Lassulus

I'm quite sure that i tried this as well and it also didn't work

DavHau avatar Oct 22 '20 11:10 DavHau

what error do you get?

Lassulus avatar Oct 22 '20 13:10 Lassulus

@DavHau is this fixed?

Lassulus avatar Nov 09 '20 21:11 Lassulus

I'll check it again on the weekend.

DavHau avatar Nov 11 '20 19:11 DavHau

Still an issue. Building the following config

{ lib, ... }:
{
  system.build.raw.diskSize = lib.mkForce 4096;
}

via nixos-generate -c configuration.nix -f raw

produces an .img file with size of 2G.

DavHau avatar Nov 14 '20 15:11 DavHau

yes, thats expected, what about:

  system.build.raw = lib.mkForce (import <nixpkgs/nixos/modules/lib/make-disk-image.nix> {
    inherit lib config pkgs;
    diskSize = 4096;
  });

Lassulus avatar Nov 14 '20 15:11 Lassulus

Exactly the same result. Even the store hash is equivalent.

DavHau avatar Nov 14 '20 16:11 DavHau

I'm also trying to override some settings of make-disk-image.nix but am unable to get this to work (just does not seem to have an effect).

Is there a way it can be troubleshooted?

elsbrock avatar May 17 '22 20:05 elsbrock

I just tried this again. I have this davhau.nix:

{ config, lib, pkgs, modulesPath, ... }:
{
  system.build.raw = lib.mkForce (import "${toString modulesPath}/../lib/make-disk-image.nix" {
    inherit lib config pkgs;
    diskSize = "10000";
    format = "raw";
  });
}

running ./nixos-generate -f raw -c ./davhau.nix gives an image with 10G size

~/src/nixos-generators fdisk -l /nix/store/7mh1dxm4f0i1pq89n7jm3kcrinmrgklm-nixos-disk-image/nixos.img
Disk /nix/store/7mh1dxm4f0i1pq89n7jm3kcrinmrgklm-nixos-disk-image/nixos.img: 9.77 GiB, 10485760000 bytes, 20480000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3f75e85c

Device                                                                  Boot Start      End  Sectors  Size Id Type
/nix/store/7mh1dxm4f0i1pq89n7jm3kcrinmrgklm-nixos-disk-image/nixos.img1       2048 20477951 20475904  9.8G 83 Linux

So overriding with mkForce should work. Not sure if this was fixed in the last 2 years or @DavHau did something wrong in the beginning :)

Lassulus avatar May 18 '22 09:05 Lassulus

Thanks! What am I doing wrong then?

{
  boot = {
    loader = {
      #systemd-boot.enable = true;
      #efi.canTouchEfiVariables = true;
    };

    kernelParams = [ ];
  };

  system.build.qcow = lib.mkForce (import "${toString modulesPath}/../lib/make-disk-image.nix" {
    inherit lib config pkgs;
    diskSize = "65536";
    #partitionTableType = "efi";
  });

  # fileSystems = {
  #   "/boot" = {
  #     device = "/dev/vda1";
  #     fsType = "vfat";
  #   };

  #   "/" = {
  #     device = "/dev/disk/by-label/nixos";
  #     autoResize = true;
  #     fsType = "ext4";
  #   };
  # };
}

In the generated VM:

$ df -h
Filesystem                Size  Used Avail Use% Mounted on
devtmpfs                   24M     0   24M   0% /dev
tmpfs                     239M     0  239M   0% /dev/shm
tmpfs                     120M  3.6M  116M   3% /run
tmpfs                     239M  384K  239M   1% /run/wrappers
/dev/disk/by-label/nixos  7.8G  2.1G  5.3G  29% /
tmpfs                      48M     0   48M   0% /run/user/0
tmpfs                      48M     0   48M   0% /run/user/1000

(interestingly, adding the additional /boot does not seem to have an effect either – same issue?)

Apologies if it's obvious, still new to Nix 🙁

elsbrock avatar May 20 '22 21:05 elsbrock

what is the format you are using? maybe just show the complete nixos-generate line. you can also add

  formatAttr = lib.mkForce "qcow";
  filename = "*.qcow2";

to have the desired effect probably.

Lassulus avatar May 21 '22 06:05 Lassulus

I am using nixos-generate -f qcow -c configuration.nix (assuming that the instructions for raw should be the same for qcow).

elsbrock avatar May 21 '22 10:05 elsbrock

ah, in 21.11 it seems indeed not working, but on nixos-unstable its working as expected

Lassulus avatar May 21 '22 12:05 Lassulus

Indeed that did the trick. Thank you.

elsbrock avatar May 22 '22 14:05 elsbrock