nixos-generate-config: Detect btrfs subvolumes

This commit is contained in:
William A. Kennington III 2014-06-18 18:43:00 -05:00
parent babcd70c36
commit 36a47733a2
2 changed files with 22 additions and 0 deletions

View File

@ -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\" =

View File

@ -38,6 +38,7 @@ let
nixos-generate-config = makeProg {
name = "nixos-generate-config";
src = ./nixos-generate-config.pl;
path = [ pkgs.btrfsProgs ];
perl = "${pkgs.perl}/bin/perl -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl";
};