Skip to content

Commit 3ff8d0e

Browse files
committed
fix(FreeBSD): remove null terminator from executable path
On FreeBSD, sysctl(KERN_PROC_PATHNAME) returns a null-terminated string with pathLen including the terminator. This causes Nix to fail during manual generation with: error: … while calling the 'concatStringsSep' builtin at /nix/var/nix/builds/nix-63232-402489527/source/doc/manual/generate-settings.nix:99:1: 98| in 99| concatStrings (attrValues (mapAttrs (showSetting prefix) settingsInfo)) | ^ 100| error: input string '/nix/store/gq89cj02b5zs67cbd85vzg5cgsgnd8mj-nix-2.31.2/bin/nix␀' cannot be represented as Nix string because it contains null bytes The issue occurs because generate-settings.nix reads the nix binary path from JSON and evaluates it as a Nix string, which cannot contain null bytes. Normal C++ string operations don't trigger this since they handle null-terminated strings correctly. Strip the null terminator on FreeBSD to match other platforms (Linux uses /proc/self/exe, macOS uses _NSGetExecutablePath). Credit: @wahjava (FreeBSD ports and Nixpkgs contributor)
1 parent c9fe290 commit 3ff8d0e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/libutil/current-process.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ std::optional<Path> getSelfExe()
134134
return std::nullopt;
135135
}
136136

137+
// FreeBSD's sysctl(KERN_PROC_PATHNAME) includes the null terminator in
138+
// pathLen. Strip it to prevent Nix evaluation errors when the path is
139+
// serialized to JSON and evaluated as a Nix string.
140+
path.pop_back();
141+
137142
return Path(path.begin(), path.end());
138143
#else
139144
return std::nullopt;

0 commit comments

Comments
 (0)