nixos-generate-config: Detect btrfs subvolumes
This commit is contained in:
parent
babcd70c36
commit
36a47733a2
|
@ -20,6 +20,13 @@ sub uniq {
|
||||||
return @res;
|
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.
|
# Process the command line.
|
||||||
my $outDir = "/etc/nixos";
|
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.
|
# Emit the filesystem.
|
||||||
$fileSystems .= <<EOF;
|
$fileSystems .= <<EOF;
|
||||||
fileSystems.\"$mountPoint\" =
|
fileSystems.\"$mountPoint\" =
|
||||||
|
|
|
@ -38,6 +38,7 @@ let
|
||||||
nixos-generate-config = makeProg {
|
nixos-generate-config = makeProg {
|
||||||
name = "nixos-generate-config";
|
name = "nixos-generate-config";
|
||||||
src = ./nixos-generate-config.pl;
|
src = ./nixos-generate-config.pl;
|
||||||
|
path = [ pkgs.btrfsProgs ];
|
||||||
perl = "${pkgs.perl}/bin/perl -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl";
|
perl = "${pkgs.perl}/bin/perl -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue