From 611b8c4472db0bde066b97960ccfe4671ffb89fb Mon Sep 17 00:00:00 2001 From: Artturin Date: Fri, 18 Mar 2022 23:02:49 +0200 Subject: [PATCH] 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` --- nixos/modules/installer/tools/nixos-generate-config.pl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index 1a9b1d061cf1..fb5d3ba47325 100644 --- a/nixos/modules/installer/tools/nixos-generate-config.pl +++ b/nixos/modules/installer/tools/nixos-generate-config.pl @@ -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";