summary refs log tree commit diff
path: root/nixos/modules/installer/tools/nixos-generate-config.pl
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/modules/installer/tools/nixos-generate-config.pl')
-rw-r--r--nixos/modules/installer/tools/nixos-generate-config.pl21
1 files changed, 21 insertions, 0 deletions
diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl
index c507f7f979fa..93a348f27174 100644
--- a/nixos/modules/installer/tools/nixos-generate-config.pl
+++ b/nixos/modules/installer/tools/nixos-generate-config.pl
@@ -20,6 +20,13 @@ sub uniq {
     return @res;
 }
 
+sub runCommand {
+    my ($cmd) = @_;
+    open FILE, "$cmd 2>/dev/null |" or die "Failed to execute: $cmd\n";
+    my @ret = <FILE>;
+    close FILE;
+    return ($?, @ret);
+}
 
 # Process the command line.
 my $outDir = "/etc/nixos";
@@ -337,6 +344,20 @@ EOF
         }
     }
 
+	# Is this a btrfs filesystem?
+	if ($fsType eq "btrfs") {
+		my ($status, @info) = runCommand("btrfs subvol show $rootDir$mountPoint");
+		if ($status != 0) {
+			die "Failed to retreive subvolume info for $mountPoint";
+		}
+		my @subvols = join("", @info) =~ m/Name:[ \t\n]*([^ \t\n]*)/;
+		if ($#subvols > 0) {
+			die "Btrfs subvol name for $mountPoint listed multiple times in mount\n"
+		} elsif ($#subvols == 0) {
+			push @extraOptions, "subvol=$subvols[0]";
+		}
+	}
+
     # Emit the filesystem.
     $fileSystems .= <<EOF;
   fileSystems.\"$mountPoint\" =