From 36a47733a264dbfe0d8cb62a1a0d5d4d4b07b715 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Wed, 18 Jun 2014 18:43:00 -0500 Subject: nixos-generate-config: Detect btrfs subvolumes --- .../installer/tools/nixos-generate-config.pl | 21 +++++++++++++++++++++ nixos/modules/installer/tools/tools.nix | 1 + 2 files changed, 22 insertions(+) (limited to 'nixos') diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index 66a8152a3a6cc..cabdb09ec9c18 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 = ; + 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 .= <