From 3ff8d0ece49dd5a46b0633b75526cb37c470c122 Mon Sep 17 00:00:00 2001 From: Jon Hermansen Date: Sat, 22 Nov 2025 03:59:29 -0500 Subject: [PATCH] fix(FreeBSD): remove null terminator from executable path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/libutil/current-process.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libutil/current-process.cc b/src/libutil/current-process.cc index c7d3b78d0..bc5700803 100644 --- a/src/libutil/current-process.cc +++ b/src/libutil/current-process.cc @@ -134,6 +134,11 @@ std::optional getSelfExe() return std::nullopt; } + // FreeBSD's sysctl(KERN_PROC_PATHNAME) includes the null terminator in + // pathLen. Strip it to prevent Nix evaluation errors when the path is + // serialized to JSON and evaluated as a Nix string. + path.pop_back(); + return Path(path.begin(), path.end()); #else return std::nullopt;