From 7fae42352235b9315021005928fea9a058c516e8 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Sat, 30 Aug 2014 15:33:44 -0700 Subject: [PATCH] nixos/generate-config: Support detecting nested subvolumes --- .../installer/tools/nixos-generate-config.pl | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index 73dd87cef5c..ab5b2954f6b 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]"; } }