diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index 73dd87cef5cf..ab5b2954f6b5 100644 --- a/nixos/modules/installer/tools/nixos-generate-config.pl +++ b/nixos/modules/installer/tools/nixos-generate-config.pl @@ -346,15 +346,25 @@ EOF # Is this a btrfs filesystem? if ($fsType eq "btrfs") { - my ($status, @info) = runCommand("btrfs subvol show $rootDir$mountPoint"); + my ($status, @id_info) = runCommand("btrfs subvol show $rootDir$mountPoint"); if ($status != 0) { - die "Failed to retreive subvolume info for $mountPoint"; + die "Failed to retreive subvolume info for $mountPoint\n"; } - my @subvols = join("", @info) =~ m/Name:[ \t\n]*([^ \t\n]*)/; - if ($#subvols > 0) { + my @ids = join("", @id_info) =~ m/Object ID:[ \t\n]*([^ \t\n]*)/; + if ($#ids > 0) { die "Btrfs subvol name for $mountPoint listed multiple times in mount\n" - } elsif ($#subvols == 0) { - push @extraOptions, "subvol=$subvols[0]"; + } elsif ($#ids == 0) { + my ($status, @path_info) = runCommand("btrfs subvol list $rootDir$mountPoint"); + if ($status != 0) { + die "Failed to find $mountPoint subvolume id from btrfs\n"; + } + my @paths = join("", @path_info) =~ m/ID $ids[0] [^\n]* path ([^\n]*)/; + if ($#paths > 0) { + die "Btrfs returned multiple paths for a single subvolume id, mountpoint $mountPoint\n"; + } elsif ($#paths != 0) { + die "Btrfs did not return a path for the subvolume at $mountPoint\n"; + } + push @extraOptions, "subvol=$paths[0]"; } }