Skip to content

Commit eddf30c

Browse files
authoredJan 6, 2018
nixos: introduce boot.growPartition (#33521)
Move it from being a profile
1 parent 51110e2 commit eddf30c

File tree

9 files changed

+57
-58
lines changed

9 files changed

+57
-58
lines changed
 

‎nixos/modules/module-list.nix

+1
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@
680680
./system/activation/top-level.nix
681681
./system/boot/coredump.nix
682682
./system/boot/emergency-mode.nix
683+
./system/boot/grow-partition.nix
683684
./system/boot/initrd-network.nix
684685
./system/boot/initrd-ssh.nix
685686
./system/boot/kernel.nix

‎nixos/modules/rename.nix

+3
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ with lib;
186186
(mkRenamedOptionModule [ "config" "fonts" "fontconfig" "ultimate" "forceAutohint" ] [ "config" "fonts" "fontconfig" "forceAutohint" ])
187187
(mkRenamedOptionModule [ "config" "fonts" "fontconfig" "ultimate" "renderMonoTTFAsBitmap" ] [ "config" "fonts" "fontconfig" "renderMonoTTFAsBitmap" ])
188188

189+
# Profile splitting
190+
(mkRenamedOptionModule [ "virtualization" "growPartition" ] [ "boot" "growPartition" ])
191+
189192
# Options that are obsolete and have no replacement.
190193
(mkRemovedOptionModule [ "boot" "initrd" "luks" "enable" ] "")
191194
(mkRemovedOptionModule [ "programs" "bash" "enable" ] "")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This module automatically grows the root partition.
2+
# This allows an instance to be created with a bigger root filesystem
3+
# than provided by the machine image.
4+
5+
{ config, lib, pkgs, ... }:
6+
7+
with lib;
8+
9+
{
10+
11+
options = {
12+
boot.growPartition = mkEnableOption "grow the root partition on boot";
13+
};
14+
15+
config = mkIf config.boot.growPartition {
16+
17+
boot.initrd.extraUtilsCommands = ''
18+
copy_bin_and_libs ${pkgs.gawk}/bin/gawk
19+
copy_bin_and_libs ${pkgs.gnused}/bin/sed
20+
copy_bin_and_libs ${pkgs.utillinux}/sbin/sfdisk
21+
copy_bin_and_libs ${pkgs.utillinux}/sbin/lsblk
22+
23+
substitute "${pkgs.cloud-utils}/bin/.growpart-wrapped" "$out/bin/growpart" \
24+
--replace "${pkgs.bash}/bin/sh" "/bin/sh" \
25+
--replace "awk" "gawk" \
26+
--replace "sed" "gnused"
27+
28+
ln -s sed $out/bin/gnused
29+
'';
30+
31+
boot.initrd.postDeviceCommands = ''
32+
rootDevice="${config.fileSystems."/".device}"
33+
if [ -e "$rootDevice" ]; then
34+
rootDevice="$(readlink -f "$rootDevice")"
35+
parentDevice="$(lsblk -npo PKNAME "$rootDevice")"
36+
TMPDIR=/run sh $(type -P growpart) "$parentDevice" "''${rootDevice#$parentDevice}"
37+
udevadm settle
38+
fi
39+
'';
40+
41+
};
42+
43+
}

‎nixos/modules/virtualisation/amazon-image.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ with lib;
1111
let cfg = config.ec2; in
1212

1313
{
14-
imports = [ ../profiles/headless.nix ./ec2-data.nix ./grow-partition.nix ./amazon-init.nix ];
14+
imports = [ ../profiles/headless.nix ./ec2-data.nix ./amazon-init.nix ];
1515

1616
config = {
1717

@@ -21,7 +21,7 @@ let cfg = config.ec2; in
2121
}
2222
];
2323

24-
virtualisation.growPartition = cfg.hvm;
24+
boot.growPartition = cfg.hvm;
2525

2626
fileSystems."/" = {
2727
device = "/dev/disk/by-label/nixos";

‎nixos/modules/virtualisation/google-compute-image.nix

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let
66
gce = pkgs.google-compute-engine;
77
in
88
{
9-
imports = [ ../profiles/headless.nix ../profiles/qemu-guest.nix ./grow-partition.nix ];
9+
imports = [ ../profiles/headless.nix ../profiles/qemu-guest.nix ];
1010

1111
system.build.googleComputeImage = import ../../lib/make-disk-image.nix {
1212
name = "google-compute-image";
@@ -29,6 +29,7 @@ in
2929
autoResize = true;
3030
};
3131

32+
boot.growPartition = true;
3233
boot.kernelParams = [ "console=ttyS0" "panic=1" "boot.panic_on_fail" ];
3334
boot.initrd.kernelModules = [ "virtio_scsi" ];
3435
boot.kernelModules = [ "virtio_pci" "virtio_net" ];
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,3 @@
1-
# This module automatically grows the root partition on virtual machines.
2-
# This allows an instance to be created with a bigger root filesystem
3-
# than provided by the machine image.
4-
5-
{ config, lib, pkgs, ... }:
6-
7-
with lib;
8-
9-
{
10-
11-
options = {
12-
13-
virtualisation.growPartition = mkOption {
14-
type = types.bool;
15-
default = true;
16-
};
17-
18-
};
19-
20-
config = mkIf config.virtualisation.growPartition {
21-
22-
boot.initrd.extraUtilsCommands = ''
23-
copy_bin_and_libs ${pkgs.gawk}/bin/gawk
24-
copy_bin_and_libs ${pkgs.gnused}/bin/sed
25-
copy_bin_and_libs ${pkgs.utillinux}/sbin/sfdisk
26-
copy_bin_and_libs ${pkgs.utillinux}/sbin/lsblk
27-
28-
substitute "${pkgs.cloud-utils}/bin/.growpart-wrapped" "$out/bin/growpart" \
29-
--replace "${pkgs.bash}/bin/sh" "/bin/sh" \
30-
--replace "awk" "gawk" \
31-
--replace "sed" "gnused"
32-
33-
ln -s sed $out/bin/gnused
34-
'';
35-
36-
boot.initrd.postDeviceCommands = ''
37-
rootDevice="${config.fileSystems."/".device}"
38-
if [ -e "$rootDevice" ]; then
39-
rootDevice="$(readlink -f "$rootDevice")"
40-
parentDevice="$(lsblk -npo PKNAME "$rootDevice")"
41-
TMPDIR=/run sh $(type -P growpart) "$parentDevice" "''${rootDevice#$parentDevice}"
42-
udevadm settle
43-
fi
44-
'';
45-
46-
};
47-
48-
}
1+
# This profile is deprecated, use boot.growPartition directly.
2+
builtins.trace "the profile <nixos/modules/virtualisation/grow-partition.nix> is deprecated, use boot.growPartition instead"
3+
{ }

‎nixos/modules/virtualisation/nova-config.nix

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ with lib;
66
imports = [
77
../profiles/qemu-guest.nix
88
../profiles/headless.nix
9-
./grow-partition.nix
109
];
1110

1211
config = {
@@ -15,8 +14,7 @@ with lib;
1514
autoResize = true;
1615
};
1716

18-
virtualisation.growPartition = true;
19-
17+
boot.growPartition = true;
2018
boot.kernelParams = [ "console=ttyS0" ];
2119
boot.loader.grub.device = "/dev/vda";
2220
boot.loader.timeout = 0;

‎nixos/modules/virtualisation/virtualbox-image.nix

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ let
88

99
in {
1010

11-
imports = [ ./grow-partition.nix ];
12-
1311
options = {
1412
virtualbox = {
1513
baseImageSize = mkOption {
@@ -23,7 +21,6 @@ in {
2321
};
2422

2523
config = {
26-
2724
system.build.virtualBoxOVA = import ../../lib/make-disk-image.nix {
2825
name = "nixos-ova-${config.system.nixosLabel}-${pkgs.stdenv.system}";
2926

@@ -71,6 +68,7 @@ in {
7168
autoResize = true;
7269
};
7370

71+
boot.growPartition = true;
7472
boot.loader.grub.device = "/dev/sda";
7573

7674
virtualisation.virtualbox.guest.enable = true;

‎pkgs/tools/misc/cloud-utils/default.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
stdenv.mkDerivation rec {
77
# NOTICE: if you bump this, make sure to run
88
# $ nix-build nixos/release-combined.nix -A nixos.tests.ec2-nixops
9-
# growpart is needed in initrd in nixos/modules/virtualisation/grow-partition.nix
9+
# growpart is needed in initrd in nixos/system/boot/grow-partition.nix
1010
name = "cloud-utils-${version}";
1111
version = "0.30";
1212
src = fetchurl {

0 commit comments

Comments
 (0)
Please sign in to comment.