Open DavHau opened 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
I'm quite sure that i tried this as well and it also didn't work
what error do you get?
@DavHau is this fixed?
I'll check it again on the weekend.
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.
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;
});
Exactly the same result. Even the store hash is equivalent.
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?
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 :)
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 🙁
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.
I am using nixos-generate -f qcow -c configuration.nix
(assuming that the instructions for raw
should be the same for qcow
).
ah, in 21.11 it seems indeed not working, but on nixos-unstable its working as expected
Indeed that did the trick. Thank you.
building with format
raw
while trying to override the image size:Doesn't have any effect on the disk size.