nixos/nixos-generate-config: fix specifying --root /mnt --dir adir

it should save to `$PWD/adir` instead of `/mnt/adir`
and --dir adir should save to `$PWD/adir` instead of `/adir`
This commit is contained in:
Artturin 2022-03-18 23:02:49 +02:00
parent 00487b5a87
commit 611b8c4472

View file

@ -51,6 +51,7 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
$n++;
$rootDir = $ARGV[$n];
die "$0: --root requires an argument\n" unless defined $rootDir;
die "$0: no need to specify `/` with `--root`, it is the default\n" if $rootDir eq "/";
$rootDir =~ s/\/*$//; # remove trailing slashes
$rootDir = File::Spec->rel2abs($rootDir); # resolve absolute path
}
@ -617,7 +618,12 @@ EOF
if ($showHardwareConfig) {
print STDOUT $hwConfig;
} else {
$outDir = "$rootDir$outDir";
if ($outDir eq "/etc/nixos") {
$outDir = "$rootDir$outDir";
} else {
$outDir = File::Spec->rel2abs($outDir);
$outDir =~ s/\/*$//; # remove trailing slashes
}
my $fn = "$outDir/hardware-configuration.nix";
print STDERR "writing $fn...\n";