nixos: introduce boot.growPartition (#33521)

Move it from being a profile

zimbatm eddf30cc 51110e2a

+1
nixos/modules/module-list.nix
···
./system/activation/top-level.nix
./system/boot/coredump.nix
./system/boot/emergency-mode.nix
+
./system/boot/grow-partition.nix
./system/boot/initrd-network.nix
./system/boot/initrd-ssh.nix
./system/boot/kernel.nix
+3
nixos/modules/rename.nix
···
(mkRenamedOptionModule [ "config" "fonts" "fontconfig" "ultimate" "forceAutohint" ] [ "config" "fonts" "fontconfig" "forceAutohint" ])
(mkRenamedOptionModule [ "config" "fonts" "fontconfig" "ultimate" "renderMonoTTFAsBitmap" ] [ "config" "fonts" "fontconfig" "renderMonoTTFAsBitmap" ])
+
# Profile splitting
+
(mkRenamedOptionModule [ "virtualization" "growPartition" ] [ "boot" "growPartition" ])
+
# Options that are obsolete and have no replacement.
(mkRemovedOptionModule [ "boot" "initrd" "luks" "enable" ] "")
(mkRemovedOptionModule [ "programs" "bash" "enable" ] "")
+43
nixos/modules/system/boot/grow-partition.nix
···
+
# This module automatically grows the root partition.
+
# This allows an instance to be created with a bigger root filesystem
+
# than provided by the machine image.
+
+
{ config, lib, pkgs, ... }:
+
+
with lib;
+
+
{
+
+
options = {
+
boot.growPartition = mkEnableOption "grow the root partition on boot";
+
};
+
+
config = mkIf config.boot.growPartition {
+
+
boot.initrd.extraUtilsCommands = ''
+
copy_bin_and_libs ${pkgs.gawk}/bin/gawk
+
copy_bin_and_libs ${pkgs.gnused}/bin/sed
+
copy_bin_and_libs ${pkgs.utillinux}/sbin/sfdisk
+
copy_bin_and_libs ${pkgs.utillinux}/sbin/lsblk
+
+
substitute "${pkgs.cloud-utils}/bin/.growpart-wrapped" "$out/bin/growpart" \
+
--replace "${pkgs.bash}/bin/sh" "/bin/sh" \
+
--replace "awk" "gawk" \
+
--replace "sed" "gnused"
+
+
ln -s sed $out/bin/gnused
+
'';
+
+
boot.initrd.postDeviceCommands = ''
+
rootDevice="${config.fileSystems."/".device}"
+
if [ -e "$rootDevice" ]; then
+
rootDevice="$(readlink -f "$rootDevice")"
+
parentDevice="$(lsblk -npo PKNAME "$rootDevice")"
+
TMPDIR=/run sh $(type -P growpart) "$parentDevice" "''${rootDevice#$parentDevice}"
+
udevadm settle
+
fi
+
'';
+
+
};
+
+
}
+2 -2
nixos/modules/virtualisation/amazon-image.nix
···
let cfg = config.ec2; in
{
-
imports = [ ../profiles/headless.nix ./ec2-data.nix ./grow-partition.nix ./amazon-init.nix ];
+
imports = [ ../profiles/headless.nix ./ec2-data.nix ./amazon-init.nix ];
config = {
···
}
];
-
virtualisation.growPartition = cfg.hvm;
+
boot.growPartition = cfg.hvm;
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
+2 -1
nixos/modules/virtualisation/google-compute-image.nix
···
gce = pkgs.google-compute-engine;
in
{
-
imports = [ ../profiles/headless.nix ../profiles/qemu-guest.nix ./grow-partition.nix ];
+
imports = [ ../profiles/headless.nix ../profiles/qemu-guest.nix ];
system.build.googleComputeImage = import ../../lib/make-disk-image.nix {
name = "google-compute-image";
···
autoResize = true;
};
+
boot.growPartition = true;
boot.kernelParams = [ "console=ttyS0" "panic=1" "boot.panic_on_fail" ];
boot.initrd.kernelModules = [ "virtio_scsi" ];
boot.kernelModules = [ "virtio_pci" "virtio_net" ];
+3 -48
nixos/modules/virtualisation/grow-partition.nix
···
-
# This module automatically grows the root partition on virtual machines.
-
# This allows an instance to be created with a bigger root filesystem
-
# than provided by the machine image.
-
-
{ config, lib, pkgs, ... }:
-
-
with lib;
-
-
{
-
-
options = {
-
-
virtualisation.growPartition = mkOption {
-
type = types.bool;
-
default = true;
-
};
-
-
};
-
-
config = mkIf config.virtualisation.growPartition {
-
-
boot.initrd.extraUtilsCommands = ''
-
copy_bin_and_libs ${pkgs.gawk}/bin/gawk
-
copy_bin_and_libs ${pkgs.gnused}/bin/sed
-
copy_bin_and_libs ${pkgs.utillinux}/sbin/sfdisk
-
copy_bin_and_libs ${pkgs.utillinux}/sbin/lsblk
-
-
substitute "${pkgs.cloud-utils}/bin/.growpart-wrapped" "$out/bin/growpart" \
-
--replace "${pkgs.bash}/bin/sh" "/bin/sh" \
-
--replace "awk" "gawk" \
-
--replace "sed" "gnused"
-
-
ln -s sed $out/bin/gnused
-
'';
-
-
boot.initrd.postDeviceCommands = ''
-
rootDevice="${config.fileSystems."/".device}"
-
if [ -e "$rootDevice" ]; then
-
rootDevice="$(readlink -f "$rootDevice")"
-
parentDevice="$(lsblk -npo PKNAME "$rootDevice")"
-
TMPDIR=/run sh $(type -P growpart) "$parentDevice" "''${rootDevice#$parentDevice}"
-
udevadm settle
-
fi
-
'';
-
-
};
-
-
}
+
# This profile is deprecated, use boot.growPartition directly.
+
builtins.trace "the profile <nixos/modules/virtualisation/grow-partition.nix> is deprecated, use boot.growPartition instead"
+
{ }
+1 -3
nixos/modules/virtualisation/nova-config.nix
···
imports = [
../profiles/qemu-guest.nix
../profiles/headless.nix
-
./grow-partition.nix
];
config = {
···
autoResize = true;
};
-
virtualisation.growPartition = true;
-
+
boot.growPartition = true;
boot.kernelParams = [ "console=ttyS0" ];
boot.loader.grub.device = "/dev/vda";
boot.loader.timeout = 0;
+1 -3
nixos/modules/virtualisation/virtualbox-image.nix
···
in {
-
imports = [ ./grow-partition.nix ];
-
options = {
virtualbox = {
baseImageSize = mkOption {
···
};
config = {
-
system.build.virtualBoxOVA = import ../../lib/make-disk-image.nix {
name = "nixos-ova-${config.system.nixosLabel}-${pkgs.stdenv.system}";
···
autoResize = true;
};
+
boot.growPartition = true;
boot.loader.grub.device = "/dev/sda";
virtualisation.virtualbox.guest.enable = true;
+1 -1
pkgs/tools/misc/cloud-utils/default.nix
···
stdenv.mkDerivation rec {
# NOTICE: if you bump this, make sure to run
# $ nix-build nixos/release-combined.nix -A nixos.tests.ec2-nixops
-
# growpart is needed in initrd in nixos/modules/virtualisation/grow-partition.nix
+
# growpart is needed in initrd in nixos/system/boot/grow-partition.nix
name = "cloud-utils-${version}";
version = "0.30";
src = fetchurl {