-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keep-paths: keep store paths alive without touching the filesystem. #1938
Conversation
Before this, scripts that do a nix build whose validity needn't extend past the script's lifetime would have to either hope there was no garbage collection between the build and the usage of it or create a temporary directory and manage cleanup. With nix keep-paths, path lifetimes can track script lifetimes (or shorter) without any races or possibly interrupted cleanup steps.
This does not necessarily seem better than using |
With |
With |
@edolstra You don't have to do anything to clean up the process. If your shell dies, it closes the fd and keep-paths gets a HUP. |
(my test only closes the fd manually because I wanted to validate gc worked afterwards) |
On the other hand, doesn't this solution require work on the daemon side while not fully eliminating the race condition? Maybe just nohup a process that (independently of Nix) waits for its |
@7c6f434c What race condition is there? Note that the daemon already supports process-lifetime temporary roots (this is how there's no chance of GC between evaluation and building in nix-build). |
@7c6f434c If we're spawning a background process already, why not just have something that actually tracks roots with process lifetime, rather than hopefully having a chance to clean up a tempdir? |
@shlevy You need to find |
@7c6f434c Well if this gets merged the next step would be a But, there's actually no risk even with your approach if you simply re-run nix-build after you register the root. Agreed it's verbose though. |
I am not sure it will Just Work, as you have to specify the FD at some point as there is no safe FD number to assume (if we include scripts running under ulimit). But yes, it will be nice. What is a rough outline of the needed flags/open FDs/communication with daemon? Double-build is one of the multiple available ways that are verbose enough to incentivise Using It Wrong. |
coproc nix keep-paths
nix-build --store keep-paths://auto?in=${COPROC[1]}&out=${COPROC[0]} |
(obviously the |
And some quoting is also needed. Frankly, that looks scary enough to wrap, and if I wrap it anyway, I can wrap using a solution that works now: |
Still it would be nice to be able to keep store paths in a race free way alive without using the filesystem (e.g. for Maybe something like a "file descriptor api" for nix would be handy? Something like this: Allow passing a file descriptor from the parent process, which is used as a communication channel. The nix process communicates when the build is done and outputs the build result over the |
Before this, scripts that do a nix build whose validity needn't extend
past the script's lifetime would have to either hope there was no
garbage collection between the build and the usage of it or create a
temporary directory and manage cleanup. With nix keep-paths, path
lifetimes can track script lifetimes (or shorter) without any races or
possibly interrupted cleanup steps.