Skip to content

Commit dd102fa

Browse files
authored
nixos-generate-config: Fix unspecified root (NixOS#390892)
2 parents ad574c3 + b82dbaf commit dd102fa

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

nixos/modules/installer/tools/nixos-generate-config.pl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ sub runCommand {
4343
if (-e "/etc/nixos-generate-config.conf") {
4444
my $cfg = new Config::IniFiles -file => "/etc/nixos-generate-config.conf";
4545
$outDir = $cfg->val("Defaults", "Directory") // $outDir;
46-
$rootDir = $cfg->val("Defaults", "RootDirectory") // $rootDir;
46+
if (defined $cfg->val("Defaults", "RootDirectory")) {
47+
$rootDir = $cfg->val("Defaults", "RootDirectory");
48+
$rootDir =~ s/\/*$//; # remove trailing slashes
49+
$rootDir = File::Spec->rel2abs($rootDir); # resolve absolute path
50+
}
4751
$kernel = $cfg->val("Defaults", "Kernel") // $kernel;
4852
}
4953

@@ -62,6 +66,8 @@ sub runCommand {
6266
$rootDir = $ARGV[$n];
6367
die "$0: ‘--root’ requires an argument\n" unless defined $rootDir;
6468
die "$0: no need to specify `/` with `--root`, it is the default\n" if $rootDir eq "/";
69+
$rootDir =~ s/\/*$//; # remove trailing slashes
70+
$rootDir = File::Spec->rel2abs($rootDir); # resolve absolute path
6571
}
6672
elsif ($arg eq "--force") {
6773
$force = 1;
@@ -85,8 +91,6 @@ sub runCommand {
8591
}
8692
}
8793

88-
$rootDir =~ s/\/*$//; # remove trailing slashes
89-
$rootDir = File::Spec->rel2abs($rootDir); # resolve absolute path
9094
die "$0: invalid kernel: '$kernel'" unless $kernel eq "lts" || $kernel eq "latest";
9195

9296
my @attrs = ();

0 commit comments

Comments
 (0)