From 417ad31ca5c149ff85bd5a4f61c81253e4906b65 Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 25 Nov 2022 08:38:05 +0100 Subject: types: fix negative relative disk size --- example/negative-size.nix | 27 +++++++++++++++++++++++++++ tests/negative-size.nix | 11 +++++++++++ types.nix | 10 +++++----- 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 example/negative-size.nix create mode 100644 tests/negative-size.nix diff --git a/example/negative-size.nix b/example/negative-size.nix new file mode 100644 index 0000000..e41bae6 --- /dev/null +++ b/example/negative-size.nix @@ -0,0 +1,27 @@ +{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: { + disk = { + disk0 = { + device = builtins.elemAt disks 0; + type = "disk"; + content = { + type = "table"; + format = "gpt"; + partitions = [ + { + name = "nix"; + type = "partition"; + part-type = "primary"; + start = "0%"; + end = "-10MiB"; + bootable = true; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + } + ]; + }; + }; + }; +} diff --git a/tests/negative-size.nix b/tests/negative-size.nix new file mode 100644 index 0000000..224b00c --- /dev/null +++ b/tests/negative-size.nix @@ -0,0 +1,11 @@ +# this is a regression test for https://github.com/nix-community/disko/issues/52 +{ pkgs ? (import { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest +}: +makeDiskoTest { + disko-config = ../example/negative-size.nix; + testBoot = false; + extraTestScript = '' + machine.succeed("mountpoint /mnt"); + ''; +} diff --git a/types.nix b/types.nix index d4d6256..e09ca9d 100644 --- a/types.nix +++ b/types.nix @@ -394,7 +394,7 @@ rec { readOnly = true; type = types.functionTo types.str; default = dev: '' - parted -s ${dev} mklabel ${config.format} + parted -s ${dev} -- mklabel ${config.format} ${concatMapStrings (partition: partition._create dev config.format) config.partitions} ''; }; @@ -480,18 +480,18 @@ rec { type = types.functionTo (types.functionTo types.str); default = dev: type: '' ${optionalString (type == "gpt") '' - parted -s ${dev} mkpart ${config.name} ${diskoLib.maybeStr config.fs-type} ${config.start} ${config.end} + parted -s ${dev} -- mkpart ${config.name} ${diskoLib.maybeStr config.fs-type} ${config.start} ${config.end} ''} ${optionalString (type == "msdos") '' - parted -s ${dev} mkpart ${config.part-type} ${diskoLib.maybeStr config.fs-type} ${diskoLib.maybeStr config.fs-type} ${config.start} ${config.end} + parted -s ${dev} -- mkpart ${config.part-type} ${diskoLib.maybeStr config.fs-type} ${diskoLib.maybeStr config.fs-type} ${config.start} ${config.end} ''} # ensure /dev/disk/by-path/..-partN exists before continuing udevadm trigger --subsystem-match=block; udevadm settle ${optionalString (config.bootable) '' - parted -s ${dev} set ${toString config.index} boot on + parted -s ${dev} -- set ${toString config.index} boot on ''} ${concatMapStringsSep "" (flag: '' - parted -s ${dev} set ${toString config.index} ${flag} on + parted -s ${dev} -- set ${toString config.index} ${flag} on '') config.flags} # ensure further operations can detect new partitions udevadm trigger --subsystem-match=block; udevadm settle -- cgit v1.2.3