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;