From ae813a00c8bc450a61c453152ed70ea165c8fb8a Mon Sep 17 00:00:00 2001 From: Adam Dinwoodie Date: Wed, 18 Feb 2026 10:50:58 +0000 Subject: [PATCH] nixos-install-tools: handle spaces in mount paths If a btrfs or bcachefs mountpoint has a space or some other special characters, these will mangle the command that nixos-generate-config runs to get information about the mount. Avoid this by switching from the "magic" form of calling the `open` function to the "three-argument" form, where each command argument is specified separately. https://perldoc.perl.org/functions/open#Whitespace-and-special-characters-in-the-filename-argument Fixes #491738 --- nixos/modules/installer/tools/nixos-generate-config.pl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index 96d0d68e5c93..ac406d2dfce3 100644 --- a/nixos/modules/installer/tools/nixos-generate-config.pl +++ b/nixos/modules/installer/tools/nixos-generate-config.pl @@ -24,8 +24,7 @@ sub uniq { } sub runCommand { - my ($cmd) = @_; - open FILE, "$cmd 2>&1 |" or die "Failed to execute: $cmd\n"; + open FILE, "-|", @_ or die "Failed to execute: @_\n"; my @ret = ; close FILE; return ($?, @ret); @@ -458,7 +457,7 @@ EOF # Is this a btrfs filesystem? if ($fsType eq "btrfs") { - my ($status, @info) = runCommand("@btrfs@ subvol show $rootDir$mountPoint"); + my ($status, @info) = runCommand("@btrfs@", "subvol", "show", "$rootDir$mountPoint"); if ($status != 0 || join("", @info) =~ /ERROR:/) { die "Failed to retrieve subvolume info for $mountPoint\n"; } @@ -505,7 +504,7 @@ EOF # This should work for single and multi-device systems. # still needs subvolume support if ($fsType eq "bcachefs") { - my ($status, @info) = runCommand("@bcachefs@ fs usage $rootDir$mountPoint"); + my ($status, @info) = runCommand("@bcachefs@", "fs", "usage", "$rootDir$mountPoint"); my $UUID = $info[0]; if ($status == 0 && $UUID =~ /^Filesystem:[ \t\n]*([0-9a-z-]+)/) {