diff --git a/README.md b/README.md index 2c36cdf0..779f0927 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ on the generated NixOS build. - hyperv - proxmox - qcow +- qcow-efi - raw-efi - raw - vm @@ -119,10 +120,10 @@ on the generated NixOS build. Example (20GB disk): ```bash -nixos-generate -c -f --disk-size 20480 +nixos-generate -c -f --boot-size 512 --disk-size 20480 ``` -To set the disk size in `flake.nix`, set `diskSize` in the `specialArgs` argument of the `nixosGenerate` function. +To set the disk size in `flake.nix`, set `diskSize` in the `specialArgs` argument of the `nixosGenerate` function. Similarly, you can also set `bootSize` in the `specialArgs` argument in the same manner, as well as use the `--boot-size` argument to specify the size in megabytes for the `/boot` partition. ```nix { @@ -158,7 +159,8 @@ To set the disk size in `flake.nix`, set `diskSize` in the `specialArgs` argumen system = system; specialArgs = { pkgs = pkgs; - diskSize = 20 * 1024; + bootSize = 512; # 500 MB for /boot + diskSize = 20 * 1024; # 20 GB for / }; modules = [ # Pin nixpkgs to the flake input, so that the packages installed @@ -317,14 +319,14 @@ multiple custom formats. `nixosGenerate` will then match against these custom f # ./configuration.nix ]; format = "vmware"; - + # optional arguments: # explicit nixpkgs and lib: # pkgs = nixpkgs.legacyPackages.x86_64-linux; # lib = nixpkgs.legacyPackages.x86_64-linux.lib; # additional arguments to pass to modules: # specialArgs = { myExtraArg = "foobar"; }; - + # you can also define your own custom formats # customFormats = { "myFormat" = ; ... }; # format = "myFormat"; diff --git a/formats/proxmox.nix b/formats/proxmox.nix index 47a62ffe..9709f7ce 100644 --- a/formats/proxmox.nix +++ b/formats/proxmox.nix @@ -1,4 +1,5 @@ { + lib, modulesPath, specialArgs, ... @@ -7,7 +8,11 @@ "${toString modulesPath}/virtualisation/proxmox-image.nix" ]; - proxmox.qemuConf.diskSize = specialArgs.diskSize or "auto"; + proxmox.qemuConf = { + diskSize = specialArgs.diskSize or "auto"; + } // (lib.optionalAttrs ((builtins.hasAttr "bootSize" specialArgs) && specialArgs.bootSize != null) { + bootSize = "${builtins.toString specialArgs.bootSize}M"; + }); formatAttr = "VMA"; fileExtension = ".vma.zst"; diff --git a/formats/qcow-efi.nix b/formats/qcow-efi.nix index 74e67da9..fe44cdc4 100644 --- a/formats/qcow-efi.nix +++ b/formats/qcow-efi.nix @@ -1,57 +1,48 @@ -{ config, lib, pkgs, modulesPath, ... }: { + config, + lib, + pkgs, + modulesPath, + specialArgs, + ... +}: let + consoles = [ "ttyS0" ] ++ + (lib.optional (pkgs.stdenv.hostPlatform.isAarch) "ttyAMA0,115200") ++ + (lib.optional (pkgs.stdenv.hostPlatform.isRiscV64) "ttySIF0,115200"); +in { # for virtio kernel drivers imports = [ "${toString modulesPath}/profiles/qemu-guest.nix" ]; - options = { - boot = { - consoles = lib.mkOption { - default = [ "ttyS0" ] ++ - (lib.optional (pkgs.stdenv.hostPlatform.isAarch) "ttyAMA0,115200") ++ - (lib.optional (pkgs.stdenv.hostPlatform.isRiscV64) "ttySIF0,115200"); - description = "Kernel console boot flags to pass to boot.kernelParams"; - example = [ "ttyS2,115200" ]; - }; - - diskSize = lib.mkOption { - default = "auto"; - description = "The disk size in megabytes of the system disk image."; - type = with lib.types; oneOf [ ints.positive (enum [ "auto" ])]; - }; - }; + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + autoResize = true; + fsType = "ext4"; }; - config = { - fileSystems."/" = { - device = "/dev/disk/by-label/nixos"; - autoResize = true; - fsType = "ext4"; - }; - - fileSystems."/boot" = { - device = "/dev/disk/by-label/ESP"; - fsType = "vfat"; - }; - - boot.growPartition = true; - boot.kernelParams = map (c: "console=${c}") config.boot.consoles; - boot.loader.grub.device = "nodev"; - - boot.loader.grub.efiSupport = true; - boot.loader.grub.efiInstallAsRemovable = true; - boot.loader.timeout = 0; - - system.build.qcow-efi = import "${toString modulesPath}/../lib/make-disk-image.nix" { - inherit lib config pkgs; - diskSize = config.boot.diskSize; - format = "qcow2"; - partitionTableType = "efi"; - }; - - formatAttr = "qcow-efi"; - fileExtension = ".qcow2"; + fileSystems."/boot" = { + device = "/dev/disk/by-label/ESP"; + fsType = "vfat"; }; -} + boot.growPartition = true; + boot.kernelParams = map (c: "console=${c}") consoles; + boot.loader.grub.device = "nodev"; + + boot.loader.grub.efiSupport = true; + boot.loader.grub.efiInstallAsRemovable = true; + boot.loader.timeout = 0; + + system.build.qcow-efi = import "${toString modulesPath}/../lib/make-disk-image.nix" ({ + inherit lib config pkgs; + diskSize = specialArgs.diskSize or "auto"; + format = "qcow2"; + partitionTableType = "efi"; + } // (lib.optionalAttrs ((builtins.hasAttr "bootSize" specialArgs) && specialArgs.bootSize != null) { + bootSize = "${builtins.toString specialArgs.bootSize}M"; + })); + + formatAttr = "qcow-efi"; + fileExtension = ".qcow2"; +} diff --git a/formats/qcow.nix b/formats/qcow.nix index 0d0aa80a..6962a634 100644 --- a/formats/qcow.nix +++ b/formats/qcow.nix @@ -28,12 +28,14 @@ boot.loader.grub.efiInstallAsRemovable = lib.mkIf (pkgs.stdenv.system != "x86_64-linux") (lib.mkDefault true); boot.loader.timeout = 0; - system.build.qcow = import "${toString modulesPath}/../lib/make-disk-image.nix" { + system.build.qcow = import "${toString modulesPath}/../lib/make-disk-image.nix" ({ inherit lib config pkgs; diskSize = specialArgs.diskSize or "auto"; format = "qcow2"; partitionTableType = "hybrid"; - }; + } // (lib.optionalAttrs ((builtins.hasAttr "bootSize" specialArgs) && specialArgs.bootSize != null) { + bootSize = "${builtins.toString specialArgs.bootSize}M"; + })); formatAttr = "qcow"; fileExtension = ".qcow2"; diff --git a/formats/raw-efi.nix b/formats/raw-efi.nix index b6108725..b451c01b 100644 --- a/formats/raw-efi.nix +++ b/formats/raw-efi.nix @@ -27,5 +27,7 @@ in { partitionTableType = "efi"; diskSize = specialArgs.diskSize or "auto"; format = "raw"; - }); + } // (lib.optionalAttrs ((builtins.hasAttr "bootSize" specialArgs) && specialArgs.bootSize != null) { + bootSize = "${builtins.toString specialArgs.bootSize}M"; + })); } diff --git a/nixos-generate b/nixos-generate index 6beddcb9..2f768921 100755 --- a/nixos-generate +++ b/nixos-generate @@ -80,6 +80,10 @@ while [[ $# -gt 0 ]]; do cores=$2 shift ;; + --boot-size) + nix_build_args+=("--argstr" "bootSize" "$2") + shift + ;; --disk-size) nix_build_args+=("--argstr" "diskSize" "$2") shift diff --git a/nixos-generate.nix b/nixos-generate.nix index 2cdc8999..33c6cf8e 100644 --- a/nixos-generate.nix +++ b/nixos-generate.nix @@ -2,6 +2,7 @@ nixpkgs ? , configuration ? , system ? builtins.currentSystem, + bootSize ? null, diskSize ? "auto", formatConfig, flakeUri ? null, @@ -22,6 +23,7 @@ in import "${toString nixpkgs}/nixos/lib/eval-config.nix" { inherit system; specialArgs = { + bootSize = bootSize; diskSize = diskSize; }; modules = [