Skip to content

libutil: Expose spawnProgram and implement fd redirections - #16504

Merged
xokdvium merged 7 commits into
masterfrom
spawn-program
Oct 5, 2026
Merged

xokdvium merged 7 commits into
masterfrom
spawn-program

Conversation

@xokdvium

Copy link
Copy Markdown
Contributor

Motivation

Mostly replaces #16454 in a way that allows us to simplify the code rather than making it more convoluted (well, other than the file descriptor redirection dance, but that's unavoidable).

After this it should be quite easy to get rid of most non-test calls to startProcess. That way we get better performance via vfork on linux and gain more windows portability.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions Bot added new-cli Relating to the "nix" command repl The Read Eval Print Loop, "nix repl" command and debugger fetching Networking with the outside (non-Nix) world, input locking labels Sep 21, 2026
Comment thread src/libutil/windows/processes.cc
Comment thread src/libutil/windows/processes.cc
Comment thread src/libutil/include/nix/util/processes.hh Outdated
SpawnOptions is a bundle of parameters describing how to spawn an executable
into a process, while RunOptions also has additional information about how to
run that process to completion. This split would allow us to expose a spawnProcess
(probably renamed to spawnProgram for clarity) for the unix case (once we have FD
redirections plumbed through) and get rid of most instances of startProcess.

It would have been nice to use inheritance for this, but we can't have designated
initialisers for them without something like [1].

[1]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2287r3.html
Addresses the TODO. The logic is already identical.
The distinction from startProcess should be much more clear.
spawnProgram is the precursor to runProgram2 (or rather a soon-to-be
more general version of it).
Now there's only a single runProgram2 implementation in platform-independent
code and spawnProgram fd redirection semantics closely mirror that of posix_spawn.

Also some windows bugs are fixed along the way, namely the fact that mergeStderrToStdout
wasn't respected and stdin wasn't inherited by default. The inheritance semantics are now
also properly documented in the code (although they are suboptimal - but at least consistent).
It's only implemented for Linux (although we should probably grab some insights
from QEMU's exit-with-parent and implement that on darwin and FreeBSD), so technically
the change to unix/processes.cc is redundant.
This removes windows ifdefs since it can now compile, but it won't
really work without other changes.

For now it's just switching the unix case to the nicer interface.
Comment thread src/libutil/include/nix/util/processes.hh Outdated
@xokdvium
xokdvium enabled auto-merge October 5, 2026 21:24
Comment thread src/libfetchers/git-lfs-fetch.cc
@xokdvium
xokdvium added this pull request to the merge queue Oct 5, 2026
Merged via the queue into master with commit a498f12 Oct 5, 2026
28 of 29 checks passed
@xokdvium
xokdvium deleted the spawn-program branch October 5, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetching Networking with the outside (non-Nix) world, input locking new-cli Relating to the "nix" command repl The Read Eval Print Loop, "nix repl" command and debugger

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants