nix-community / nixos-generators

Collection of image builders [maintainer=@Lassulus]
MIT License
1.83k stars 145 forks source link

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

Open DavHau opened 4 years ago

DavHau commented 4 years ago

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.

Lassulus commented 4 years ago

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

DavHau commented 4 years ago

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

Lassulus commented 4 years ago

what error do you get?

Lassulus commented 3 years ago

@DavHau is this fixed?

DavHau commented 3 years ago

I'll check it again on the weekend.

DavHau commented 3 years ago

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.

Lassulus commented 3 years ago

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;
  });
DavHau commented 3 years ago

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

elsbrock commented 2 years ago

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?

Lassulus commented 2 years ago

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

elsbrock commented 2 years ago

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 🙁

Lassulus commented 2 years ago

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.

elsbrock commented 2 years ago

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

Lassulus commented 2 years ago

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

elsbrock commented 2 years ago

Indeed that did the trick. Thank you.