Commit Graph
100 Commits
Author SHA1 Message Date
eldritch horrors 6f0bf9798a libstore: process post-build-hook logs directly
using a sink for this has long been a bit weird anyway. originally it
was necessary due to api limitations, but it hasn't been for a while.

Change-Id: I3dfa157944618349bfd6f398ee1667fc31519d86
2025-09-11 16:36:52 +00:00
eldritch horrors d5970d8a8b libutil: remove unused logger function
Change-Id: I8505346baa88b9f174707e127f1c78088238cf3e
2025-08-25 21:00:15 +00:00
eldritch horrors ed9a78fccd treewide: colorize logs by default
printTaggedWarning already colorized its messages. we can do the same
for most other log messages.

Change-Id: Idcd31bbf4f8d0d703395b0d2b7b9bc33264d969f
2025-08-25 21:00:15 +00:00
eldritch horrors 18285afa76 treewide: force log format strings to be literals
luckily none of these a format strings vulnerabilities because
boost::format is smart enough to throw an exception when given
fewer format string arguments than are requested by specifiers

Change-Id: I5fa78f0d1396263271f6e1dbcee9c0b2e9e18c34
2025-08-25 21:00:15 +00:00
eldritch horrors 466115c9c8 treewide: don't call Logger output functions directly
always use log macros, which also have the benefit of respecting the
verbosity setting without needing virtual function calls to read it.

Change-Id: I1c605562a53e54140724d5225e040abcf49ac996
2025-08-25 21:00:15 +00:00
eldritch horrors 4c6c01786f treewide: turn nix::warn into a macro
we add two variants: one that just prints a message at the warning
level (mirroring the other printer macros), and one that also adds
the colored "warning: " prefix the function added. since there are
no overriders of this function in tree it looks safe to remove it.

Change-Id: I7008fd0f31d59fbc9259472e29359c8df19ff87d
2025-08-25 21:00:15 +00:00
eldritch horrors 03ab20e191 libutil, cli: remove Logger::warn
only use the free function instead, so we can turn that into a macro.

Change-Id: I0319e9f7bdebb96f6159053e8b7b7a82559c9b33
2025-08-25 21:00:15 +00:00
eldritch horrors f40a60f46a libutil: make log macros usable outside of nix namespaces
mostly useful for nix-eval-jobs which currently has to call the logger
functions directly because its main code *isn't* in the nix namespace.

Change-Id: Ia8440d86a293d9006ffef2562b1859e9aaa79a62
2025-08-25 21:00:15 +00:00
eldritch horrors be438c62e1 nix/eval: remove --write-to
it's broken, can write arbitrary file paths when run as root, and only
supports strings and recursive sets of strings. this was only used for
manpage generation in a build system that has not woken up since 1976.

fixes #974
fixes #227

Change-Id: I4f18599685a3077c15ddc02c759558f986c8c6e4
2025-08-23 10:39:30 +00:00
eldritch horrors 001c70d2ba libstore: mark all non-local stores as thread-unsafe
this pretty much only impacts store verification via the nix3 cli. no
other thread pools are left, and the verification pool may *actually*
be important for throughput since verification involves much hashing.

Change-Id: I32152e6169a82a1268a790e333f21a0430ede7f4
2025-08-19 13:08:53 +00:00
eldritch horrors 3cecd2306b nix/sigs: remove sign pool
signing is very cheap, it's only the store access that is expensive.
http binary caches parallelize async accesses extremely well though.

Change-Id: Ifdbf398bd328ba16ec4e8caba3f5f99a6cf3e046
2025-08-19 13:08:53 +00:00
eldritch horrors d63edddeb0 libstore: remove debug info upload pool
Change-Id: Ife5f69ddaeb82f002f4dfe05347fe700d201df72
2025-08-19 13:08:53 +00:00
eldritch horrors 13509ef773 libstore: rewrite debug info upload with generators
Change-Id: I1b0424c3b8aed5a90d1ca3d61b11cc5a1bf92cf0
2025-08-19 13:08:53 +00:00
eldritch horrors c917f4ec78 nix/sigs: remove CopySigs thread pool
we don't have benchmarks for this one, but a 10x improvement seems likely.

Change-Id: I76f4e9c9ebff86fd7d451ed7e125ab309011457e
2025-08-19 13:08:53 +00:00
eldritch horrors 20f84eb6bf libstore: remove queryValidPaths thread pool
this is used by nix-env and copyPaths, which in turn is used to upload
to binary caches. for a large path set we have seen 10x a improvement.

Change-Id: Ieadd0e66180e5ceecefaf944a5bb2f0523374954
2025-08-19 13:08:53 +00:00
eldritch horrors 5fc6ab2e50 libutil: make generator iterators adl-visible
lets us use generators in algorithms that use adl iterator access

Change-Id: I05b06f070e370ef21c693e61979d07d9b7206a9f
2025-08-19 13:08:53 +00:00
eldritch horrors 5a30005e2f libutil: remove unused runAsyncInNewThread
Change-Id: I55d161201737fc6b7dbfb0a387b253939dfe5784
2025-08-19 13:08:53 +00:00
eldritch horrors 3de996f521 libexpr: stringviewify some more APIs
notably this also includes the symbol table because it stores real
strings that are referenced by eval values, and an upcoming change
will make it impossible to share those strings with value strings.

Change-Id: I20a3644db8aa0850efe29630e0b73d424cb2aa56
2025-08-17 14:55:13 +02:00
eldritch horrors 8208c6ebb7 libexpr: don't read Value::string.s directly
Change-Id: I0f224459fcbff8bc53c3668bc6ea52881c453fd0
2025-08-17 12:11:19 +00:00
eldritch horrors 935901cd46 nix/ls: fall back to downloading the nar if the .ls is bad
fixes #959

Change-Id: I1715f6fcc938dac7287d9cf4a85e93c9d66768a0
2025-08-15 18:05:06 +02:00
eldritch horrors 612d553a4f libstore: fail makeLazyNarAccessor for broken .ls files
Change-Id: I58ecc89046ee5fc58d05c980acb3616e91ee4741
2025-08-15 18:05:06 +02:00
eldritch horrors c3bfb6fe17 testing: unbreak functional tests in devshells
turns out that adding busybox to checkInputs just totally trashes f1 testing.

Change-Id: Iac8d49a59a39c44e0663d7ae760e0a0473ebf7fd
2025-08-15 15:26:27 +02:00
eldritch horrors 4a119e6e46 libutil: support async deserialization on musl
use a thread pool and allow only buffered sources for performance. we
may want to use this code path unconditionally due to gc interactions
of fibers in circumstances we should not even be able to trigger, but
if that becomes important we will have a useful implementation ready.

Change-Id: Ib4e1531fe920847d8e30a42e8df393ace549f52e
2025-08-12 14:14:35 +02:00
eldritch horrors a9117791e2 libutil: remove unused FdSource::specialEndOfFileError
Change-Id: Ia03e270c359014ab3675a043bad342c4bbfdbafd
2025-08-06 14:43:47 +00:00
eldritch horrors 22cf5eb989 libstore: use async io for remote store IO
this means both the worker protocol and the serve protocol, i.e.
ssh-ng/local connections and legacy ssh connections. now we have
no blocking reads left anywhere in our client store connections.

Change-Id: I2f628d4d2e71ef0a7006918f175192f3f58eea95
2025-08-06 14:43:47 +00:00
eldritch horrors db0ed505e9 libutil: add async serialization helpers
Change-Id: I5c123e1ac31172d61c9e1d293e99ca1022bcec4e
2025-08-05 19:10:46 +00:00
eldritch horrors 7e8b44d718 libutil: allow access to async stream buffers
this is easier than remembering which buffer was used during construction.

Change-Id: I64a8bdcbc0104c5a4a3330266b508cfd9297852e
2025-08-05 19:49:11 +02:00
eldritch horrors d5cfc6f19c libstore/remote: frame buffers, don't buffer frames
shoving a nar dump directly into a framed sink created a bunch of tiny
frames, each of which requires at least two syscalls to read. this can
lead to immense performance loss when using a daemon; we have seen 15%
in benchmarks on main and even more with async code involved ... oops.

Change-Id: I8529506e3de74d92834d1f4ee228dcaf32eb756c
2025-08-01 01:10:50 +02:00
eldritch horrors 98a27fbfd2 bench: soup up the benchmark script
add daemon support, fix the rebuild cases by using an installer config

Change-Id: I47cbb0dd401abf5e041e9936077e502f5e0cabf9
2025-07-31 15:15:24 +00:00
eldritch horrors f0150eb8a3 libutil: add AsyncFramedInputStream
the async version of FramedSource, with all its weaknesses for bug-compat.

Change-Id: Ifcdd4a5819f7cf25a0e8b01c63975ffead54079c
2025-07-29 13:37:53 +00:00
eldritch horrors 96200d5768 libstore: use async io from RemoteStore::Connection::processStderr
this lets us avoid a bunch of fcntl calls to unset and re-set O_NONBLOCK
on remote store connections. the overhead of these isn't high, but doing
it is still wasteful and a maintenance burden when we have async readers

Change-Id: I900cdca2a16202380c8b6f9b86da7d9b0f1e34ac
2025-07-29 13:37:53 +00:00
eldritch horrors 7f22e9e6cc libutil: duplicate deserializers for async streams
this is needed to asyncify the wire protocol deserializers.

Change-Id: I8087c852ab7b64bc1749310aa1493912af8b1c6e
2025-07-29 13:37:53 +00:00
eldritch horrors 45d81027e3 libutil: remove readInt, readLongLong
the former isn't even int, it's unsigned. the latter is uint64. both
should be explicit about this to avoid problems that we have already
had, such as the FramedSource wire protocol writing using 64 bits to
write frame sizes, but 32 bits to read them. large frames will cause
the reading end to crash with an unnecessary serialization exception

Change-Id: I3c15e911f649eec719d4b1c135dde1b6ba020271
2025-07-29 12:25:56 +00:00
eldritch horrors 7923dcc034 libtuil: remove deserializing operator>>
they will not work well with async deserialization and are not used
consistently anyway. just like the serializing operator<< these are
protocol stability hazards: changing the type of a field influences
the wire protocol layout and type constraints, which is not amazing

Change-Id: I54b20a133048f4ca15a9fb0f4d8b94dc78f62d89
2025-07-29 11:54:33 +00:00
eldritch horrors d647bf7d0a libutil: remove unused readString overload
Change-Id: I8419efe895617b5473170f3cbb76697f0aa2def2
2025-07-29 11:47:40 +00:00
eldritch horrors 51a7f1f37a libutil: add AsyncInputStream::readRange
this is an equivalent of the regular kj read interface which also takes
a min/max pair. we do not need this very often though, so we'll keep it
as a separate method for now. if we do find we use it more than read we
can still rename read to readSingle and readRange to read. we will see.

Change-Id: Ib04ca146911adae7081cf4b2df097217ea5fe9f8
2025-07-29 11:47:40 +00:00
eldritch horrors 874e878ba0 libutil: move LengthSink into sole user
this should've been a filter from the start. since filter support in the
old IO model is very bad we just move it into the only use of it instead

Change-Id: Ifb9cfecf07587ae1d2d55072ddf505c86c79cc1b
2025-07-29 10:42:00 +00:00
eldritch horrors db7c3a88b2 libutil: move SizedSource into its only user
we should not encourage this kind of framing. in the future we will have
to do this on async streams, which we *absolutely* should not encourage.

Change-Id: Ib89e144afb564284db64fc7367cba7fffc18fdaf
2025-07-29 10:42:00 +00:00
eldritch horrors 5c2ee71c61 libstore: update exceptionAbortsDownload test
the exception no longer actually matters, only that the download stream
is destroyed before the download finishes does. exceptions during drain
calls on the returned stream will cause the stream to be destroyed, but
draining this stream is just a remnant of the old download-to-sink API.

Change-Id: Ic6de40deb2ccff09d77180148afe746f29f55d23
2025-07-29 10:42:00 +00:00
eldritch horrors 0acb43f6d3 libutil: pass owned sources to makeDecompressionSource
we lose reference lifetime constraints for minimal runtime overhead.

Change-Id: I198b521a0fc56f9a3499ec1d6ae9aa8655daa59e
2025-07-29 10:42:00 +00:00
eldritch horrors 173e6fe995 libstore: optimize nar copy stream adapter
we don't need to report progress for every read call. that's way too
much. batching like this greatly reduces CPU usage for copies out of
or into remote buidlers due to likewise greatly reduced log traffic.

Change-Id: I3db2b2ab113fbaadefc69cfde6f977fb0c6cd5ad
2025-07-28 23:57:16 +02:00
eldritch horrors 57b1c289b5 treewide: drop PushActivity in favor of explicit context
PushActivity does not work with async code since we have no such thing
as promise-local storage. it will be confusing at best, and completely
wrong at worst, with the current thread-local linking state. if we can
find a way to get promise-local storage we may want to bring this back
though, explicit context passing is rather error-prone. luckily we are
not using parent links for anything important, just to keep the multi-
line activity display from filling up with stuff we're already showing

Change-Id: Ie373d713080a3db811b2d5abd681f78137735e45
2025-07-25 13:05:24 +02:00
eldritch horrors e88a85bd92 build-remote: don't copy failed paths with ssh-ng & --keep-going
checking that the remote build actually succeeded only implied-trusted
remotes or CA derivations makes *absolutely* no sense. we should check
that builds have succeeded before trying to copy them from the remote.

Change-Id: Ib2cf216c580f4c577dd9fef8849acc033ae082b9
2025-07-24 17:56:05 +02:00
eldritch horrors 43d6a79863 libstore: work around capnp fd passing bug
capnp does not handle fd passing correctly in all circumstances. we hit
such cirumstances when passing large closures path lists to build-hook.
since capnp seems to ignore fds passed in non-final segments of any rpc
message we just ensure that the capability including the log fd will be
small enough to not be fragmented on the receiving side of the channel.

cf https://github.com/capnproto/capnproto/issues/2359

Change-Id: Id22309264936b3a57bcc68a0753c3bfb3c9a43d2
2025-07-23 13:53:24 +00:00
eldritch horrors 72cad8918b libstore: fix remote build failures killing everything
remote builds failures used to be signaled via exit status 1 of the
build hook, which in turn only happened because the build errors we
got from remote stores was thrown and bubbled up to main which then
logged the error and exited with code 1. with rpc we cannot do this
any more. barring a rewrite of the worker infra to allow for errors
being reported with something other than process exit codes this is
the best can do. ideally we would wrap remote builds in a new goal.
(and then remove all exit code shenanigans from DerivationGoal too)

fixes #928

Change-Id: Idc3ede3cbaca34c8c8e40247da52794f2a5013b9
2025-07-22 15:32:25 +02:00
eldritch horrors 9eb3c1be80 daemon: restore daemon-trust-override
apparently this feature got lost in the migration to exec'ing daemons.

Change-Id: Iac9425cf6d20781bb49e5cf12f2056f4a3ec23ba
2025-07-22 12:33:49 +00:00
eldritch horrors cb96940042 libstore: pass a log pipe into build-hook
this way we don't have to duplicate build log parsing in the hook.

Change-Id: I1c96b75aea3b4bb747aa0f0cc76c00eace8911c4
2025-07-22 12:33:49 +00:00
eldritch horrors 6ddd3045f0 testing: remove obsolete daemon tests
remove all daemon version checks targeting daemons we no longer support.

Change-Id: If722024c3d66c73fa1b3cdd63134a09389ac6ea5
2025-07-22 10:39:32 +00:00
eldritch horrors d8dfffbe37 daemon: use kj for splicing stdio connections
drop our reimplementation of splice for non-linux in favor of using kj
pumpTo. this avoids select() for its O(maxfd) behavior, and if kj ever
uses something more efficient than read/write loops we'll benefit too.

Change-Id: Id01ba84bf8831455af2d9755bf1a3039d215bb47
2025-07-22 10:39:32 +00:00
eldritch horrors 2fc47b65b8 libstore: weaken tmpdir root access mode
libarchive *should* not break with 0710 on the tmpdir root on darwin,
just like it doesn't break on linux, but for some reason it does. the
restriction to 0710 can be weakened to 0750 with causing any trouble.

fixes #921

Change-Id: Ia9fc2f8eb9695fc19cefae9857368d5a4e58c8b9
2025-07-20 16:25:04 +00:00
eldritch horrors 9d8ab80435 libstore: don't wait for empty cgroups to empty
oops. m(

Change-Id: Ia421589e76a9740b3e49133598c893339f92250e
2025-07-18 18:57:19 +02:00
eldritch horrors 6d6cccee75 libstore: restrict build-hook parallelism
previously we only had one build hook in waiting at most because build
hook rpc was synchronous. now that it no longer is we attempt to start
one hook per derivation, which depending on scheduling can be a *very*
large number. restrict the waiting hook count to 4 to some concurrency
without collecting a large number of hooks that may never do anything.

Change-Id: Ic0b1125cec4acd69e8a0d4639c232e71b825e01d
2025-07-18 13:43:02 +02:00
eldritch horrors ae3b8e58c3 libstore: chown build dirs with --keep-failed
although we only chown if the build was requested by a local daemon
user. daemonless invocations will not chown as they do not have to.
remote builds *can* chown to the remote builder user, but that does
not seem to happen (for some reason keep-failed is not propagated).

Change-Id: Ic0ead406b38b4ca0556fec42d84888efa25123bf
2025-07-17 15:05:32 +02:00
eldritch horrors 9d5a5c4dc0 libstore: add intermediate directory to build-dirs
this makes the actual build directories used by builders invisible and
inaccessible to other processes on the system, avoiding another vector
for outside processes to interfere with builds or pass credentials the
build sandbox should not have access to into the build sandbox anyway.

fixes #919

Change-Id: Ifaa4d8e3940cfde1406e925f75c1375d2e86d81a
2025-07-16 23:02:16 +00:00
eldritch horrors 8f325fe436 libstore: convert build-hook protocol to rpc
Change-Id: I8da74acdc965aba5091c089101745f7aa501befa
2025-07-15 20:33:30 +02:00
eldritch horrors 8a5a477ca3 treewide: add first batch of capnp rpc types
this touches both libutil and libstore because with no rpc users it
doesn't make that much sense to separate the two. note that all our
strings are represented as Data (ie, blobs) because capnp Text must
be nul-terminated. while it's technically possible to use Text with
strings containing non-terminating NULs it is a bit of a hassle and
could lead to rpc users erroneously stopping at the first NUL byte.

Change-Id: I4c75e03b79a226ffa8d7cd985e3ac632a0cd7c1c
2025-07-15 20:33:30 +02:00
eldritch horrors ca12657a68 build: add capnp compiler wrapper
we need this to generate dependency information, and it'll be the entry
point for custom codegen once we need it. a wrapper also makes it a lot
easier to generate a whole namespace's worth of rpc definitions at once

Change-Id: Iba7a1c92a8a40bede9ed71aa3ab455477ff5e568
2025-07-15 06:40:48 +00:00
eldritch horrors ea11d075e6 libutil: add low-level provider to AsyncContext
without it we can't wrap socket fds for capnp rpc.

Change-Id: I0d603c82d8574b7b0f6eb07b2dff655d94418ec9
2025-07-15 06:40:48 +00:00
eldritch horrors 4a1d16ebca libstore: asyncify build-remote functions
Change-Id: I9fbee928eb955e03c41dfe8ce74bd8a90f5e26cd
2025-07-15 06:40:48 +00:00
eldritch horrors 6877ae5fb8 libstore: handle the entire hook lifecycle in tryBuildHook
if the hook accepts the build request we can handle the entire request
in tryBuildHook. there is no need to punt a partially handled build to
the caller (we only did this to minimize churn during asyncification).

Change-Id: Iec3e35a8103da4fc5fbef394cc28a134ee62a198
2025-07-15 06:40:48 +00:00
eldritch horrors 07ba511921 libutil: add a type-mapping TRY_AWAIT
mapping the result of an await operation before unpacking it lets us
inject rpc type conversion functions without duplicating all that is
needed for proper exception wrapping and async error traces support.

Change-Id: Ibcba1cc6d2b275757e3475881ef20f95dd4d684f
2025-07-15 06:40:48 +00:00
eldritch horrors e01ae1f453 libutil: add generic unix socketpair wrapper
previously we used this only for SSH, but other uses may appear soon.

Change-Id: Ibe9666d63aaea07525ebad57decda88b11964cc0
2025-07-15 06:40:48 +00:00
eldritch horrors b43d7b8136 libstore: don't use Outcome<void, T> in goals
`Outcome<void, T>` and `Result<std::optional<T>>` can be interpreted as
being the same thing, but the latter is easier to use: not only do they
allow TRY_AWAIT usage for their promises, we also don't have the error/
exception confusion of outcomes (where the T above is the "error" type)

Change-Id: I92c9241481cecc97e2992445b3dced53c82a2524
2025-07-14 17:02:30 +00:00
eldritch horrors 280772583f libutil: remote unsafeLockFileSingleThreaded
while this does require spawning a thread for every contended lock now
we don't expect performance to be impacted. only build-remote used the
synchronous method, and it only used it to serialize uploads to remote
builders. these uploads are expensive enough to dwarf the thread cost.

Change-Id: Iad0aa0cd738bc96fd06a90d655803dadffa09c47
2025-07-14 17:02:30 +00:00
eldritch horrors df45583c7a libutil: add AsyncContext::timeoutAfter
this is just a Result-aware version of kj's Timer::timeoutAfter.

Change-Id: I17ff77d40201996b9dafc32bbff0298db8a4fcc9
2025-07-14 17:02:30 +00:00
eldritch horrors 9c1e7d4d07 libstore: use AsyncInputStream for reading builder output
DerivationGoal::InputStream existed only because we did not have an
error-reporting AsyncInputStream of our own yet. we do have one now
though and can thus delete old code in favor of the generic variant

Change-Id: I01c7c564554f8794bdf54603b239b7a808faeda0
2025-07-14 17:02:30 +00:00
eldritch horrors 334b8e2b20 libstore: add log-fd to ssh-ng as well
this way we can get ssh error message if connection setup fails.

Change-Id: Ifc001f77ec0477fb9786f7767a47f3745d6475ff
2025-07-14 17:02:30 +00:00
eldritch horrors d20c3d3643 libutil: remove ErrorInfo::programName
it's effectively unused. one use is a write and a read immediately after
the write, the other use checks whether it's not equal to itself (..wat)

Change-Id: I5f6ce26e75a6bfa500c2e9ac3fc70e8dafc9bd74
2025-07-14 17:02:30 +00:00
eldritch horrors 1a0d05d852 libstore, build-remote: delete static ssh:// fds
this was a mess. ssh:// remotes used the extra static fds for build
logs, ssh-ng:// remotes did not. ssh-ng remotes did not use them at
all since ssh-ng never redirected them to begin with. we now create
pipes dynamically and only for ssh:// builders, then translate logs
received over these pipes into the same format used by ssh-ng. this
requires a new activity we did not have before, but since we have a
great many activities that rarely show up already this shouldn't be
a problem for external tooling. if anything external tools can tell
what's going on much better now (at least for ssh:// remote builds)

Change-Id: I02010cee45598362a947faa3a5b04800d39daa31
2025-07-09 18:21:20 +00:00
eldritch horrors 11d854281a build-remote: extract connecting to builder
Change-Id: I364f20f1c689f87dd4e6ec98a36b43f34647ff43
2025-07-09 15:48:07 +00:00
eldritch horrors a17771569e build-remote: extract machine selection
Change-Id: Id5abe9a46ee8ba71f00379af31b442c3fa7cda92
2025-07-09 14:20:51 +02:00
eldritch horrors 44895d1ed5 build-remote: extract error message printer
Change-Id: I5eab56be27d6178caa341fb2ff1f52475252aab8
2025-07-09 14:20:51 +02:00
eldritch horrors 487b37291f libutil: optimize Sync<T, AsyncMutex>
async queries easily lead to high contention on the localstore sqlite
lock. optimizing the lock wakeup scheme improves query performance by
a linear factor (with the O(waiters) wakeup replaced by O(1) wakeup).
on 100k drv closures we're now at 55s query, down from >8min in 2.93.

Change-Id: I9b96e792c4518a782c690dea92e61260f08f0bad
2025-07-07 18:13:16 +00:00
eldritch horrors 33784540c4 libutil: fix signaling handling on darwin
this partially reverts commit 0cc021ee15,
which for some reason is completely broken on darwin: there seems to be
no way to receive process-directed signals on a non-main thread. trying
to do it anyway will fail silently. since we only ever used kj for this
to get signal handling timeouts on darwin (which lacks sigtimedwait) to
print a nice message about retrying ^C again we can work around this by
moving the message printing into a fresh, unrelated, non-signal thread.

Change-Id: I5939c6ec62a7e1dc1b3f16067f77277533949fa0
2025-07-06 17:47:42 +02:00
eldritch horrors 29d9a88af6 libutil: handle sigint only once per thread
many a cleanup path has been broken by interruptions being thrown every
time checkInterrupt is called. we should only throw *once* though; more
than one Interrupted exception for the same event is not only confusing
but also breaks all cleanup paths at the first checkInterrupt call site
(e.g. #900, the cgroup cleanup saga, temp dirs not being removed, etc).

Change-Id: Ibfabf7f6af6ac2b78ad93582c254bbc48fcb3073
2025-07-06 10:45:55 +00:00
eldritch horrors b1544582af libutil: quit immediately on second sigint
we must be crash-safe *anyway*, and being unable to interrupt lix if it
gets stuck somewhere that never calls checkInterrupt is really annoying

Change-Id: I7c40271c3da7e69d8735e22b7b7c4751b5306ab6
2025-07-05 16:27:47 +02:00
eldritch horrors 0cc021ee15 libutil: asyncify signal handler thread
macos doesn't have sigtimedwait and we need signal wait timeouts in
order to print a "please hit ^C again" message with a bit of delay.

Change-Id: If574fb1a9de0b19975b34fc63662b089eaedc9d2
2025-07-04 22:59:13 +02:00
eldritch horrors 9dbf46f573 cli: asyncify daemonLoop
another checkInterrupt can be a makeInterruptible wrapper now. this is
also necessary to add a second daemon socket for the new rpc protocol.

Change-Id: I55055f975335a75708f1f73edb75f7bfe77a5938
2025-07-04 21:12:12 +02:00
eldritch horrors 362bfd827f cli: drop extraneous daemon thread
it was only needed because we forked subdaemons and couldn't reuse the
main aio root. we now fork+exec, so the main aio root is always valid.

Change-Id: Ia19e20d52d65fe72721292be091f182a8a77a7cb
2025-07-04 14:16:33 +02:00
eldritch horrors a232d14e9c libutil: remove unused ProcessOptions members
neither are set to non-default values any more.

Change-Id: Iffe0f230c51324530dd1ad865e16e159f97ef827
2025-07-04 14:01:11 +02:00
eldritch horrors ebf665b1c8 libutil: remove unused DoSignalSave
all uses are DoSignalSave::Save now, and introducing new DontSave uses
should be avoided as much as possible. process management is already a
mess, simplifying it somewhat will make our life easier in the future.

Change-Id: I77eecabe45bee9de18fba0dfc948403d3ce46dfe
2025-07-04 14:01:11 +02:00
eldritch horrors 7b37d5ea6a cli: fork+exec subdaemons, don't just fork
this resolves problems with aio roots becoming invalid after fork (which
so far forced us to run the daemon loop in an aio-rootless thread), does
not require restarting the signal handler thread in the subdaemon (since
we no longer lose it), and is a step towards solving #18 (with transient
daemons doing the store manipulation started transparently when needed).

Change-Id: Iad0149cbc807e31964407c9a83d12314702c8122
2025-07-04 14:01:11 +02:00
eldritch horrors dffb8e9865 libutil/runProgram2: add explicit argv0 support
Change-Id: I292aed7f25de1c193f6e2374c1f6a7ba9d272dd4
2025-07-04 14:01:11 +02:00
eldritch horrors 164d23f38d libutil/runProgram2: support posix_spawn-like dup-to-self redirections
posix_spawn unsets CLOEXEC for fds that are dup'd onto their existing fd
number. this is very useful when inheriting fd numbers exceeding stderr.

Change-Id: I6f14585d424ded6741fdd087f0c4d33a05936bcc
2025-07-04 14:01:11 +02:00
eldritch horrors 0f0718422f libutil: rename runProgram redirections to make more sense
the `from`/`to` naming only made sense for unidirectional output fds,
for others (and for the dup2 api in general) it was backwards. rename
them to `dup`/`from` to make this look more like the assignment it is

Change-Id: Iee50d06f9cfcea765ace6cfbe85b192829207e5f
2025-07-04 14:01:08 +02:00
eldritch horrors 897f87e76a libutil: allow non-blocking fds for writeFull
writing to non-blocking fds happens during remote builds due to the way
file descriptions are shared between processes. we can either poll when
writing to non-blocking fds are reset fd flags. polling is just easier.
unfortunately there is no reasonable way to test this that isn't flaky.

fixes #896

Change-Id: I1d8666df57da97199247f0770c547d0180f6ce07
2025-07-03 22:37:40 +02:00
eldritch horrors bfabaa688f libutil: fix segfault in makeInterruptible callback
cancelling the promise returned by makeInterruptible could free the
fulfiller before the interrupt callback handle, and no order of the
attachments made a difference. we must resort to putting fulfillers
into shared_ptrs so we can capture them in interrupt callbacks now.
(alternatively we could add another kind of interrupt callback, but
the complexity of doing that outweighs the cost of one shared_ptr.)

fixes #895

Change-Id: I008b160482fd4d81a29d7e9e452dcda858b090b9
2025-07-01 23:12:49 +02:00
eldritch horrors ed3c202c20 libstore: be more economical about fcntl on RemoteStore
download progress reports send a STDERR_RESULT frame. many concurrent
downloads send many STDERR_RESULT frames. each of these frames has us
run the report loop once. since many frames can happen in very little
time we may receive many frames in a single read from the socket, and
that in turn means we don't have to fcntl that socket on every round.
we must still ensure that the socket is in the correct state for each
part of the loop, and this does mean we may run two unnecessary fcntl
sequences per processStderr call. that's a small price to pay though.

Change-Id: I7af607d8c759b76aff0f6016435955e2f9456923
2025-07-01 17:06:26 +02:00
eldritch horrors ce6eba531e libutil: add makeNonBlocking, resetNonBlocking
these are used often enough that deduplicating them is worth it. we do
lose some error fidelity, but valid fds will never cause an error here

Change-Id: I2b91b4848f546a894a2a6c2d36c32a892fb73c9f
2025-07-01 17:06:26 +02:00
eldritch horrors 6e7c0812c7 libstore: drop checkInterrupt from LocalStore::verifyPath
it's only called by verifyStore, and verifyStore is only called by the
daemon and `nix-store --verify`. both pass the promise to `blockOn()`.

Change-Id: I829c0d189fa913cd8566ddd1a578c50e60fb2ddb
2025-06-30 21:46:29 +00:00
eldritch horrors 32cfbe3959 drop checkInterrupt from ThreadPool items
all of them block on a promise very soon after starting. only
queryValidPaths needs to make sure not to swallow Interrupted
exceptions to exit quickly instead of trying all paths first.

Change-Id: I4f99f5d75d7057bad109dc0131aa58e84275e362
2025-06-30 21:46:29 +00:00
eldritch horrors 96fbc29f09 libutil: checkInterrupt in AsyncIoRoot::blockOn
checkInterrupt is cheap, waiting for a promise isn't. checking for
interruptions before any top-level promise is awaited lets us drop
a bunch of checkInterrupt calls elsewhere, such as in thread pools

Change-Id: Id543edf9411e53b2a5bbec77d3084a8f65aaea46
2025-06-30 21:46:29 +00:00
eldritch horrors 2c00a68624 libutil: explicitly declare and document our reserved signals
Change-Id: Ia27cce0d3577219b7476f7ce6dade4387ba727b2
2025-06-30 21:46:29 +00:00
eldritch horrors 325f937cca remove old commented-out checkInterrupt calls
Change-Id: I843ee341ecfb4cb8be995b9e5ac628f75a4c7e4b
2025-06-30 21:46:29 +00:00
eldritch horrors ac80a11300 packaging: unbreak static builds
Change-Id: I84dbf66d2d4116c531384445a108d1eab7752ffb
2025-06-27 22:53:28 +02:00
eldritch horrors e356d54d7a libstore: don't delete already valid outputs after build
eagerly consider outputs as not needing deletion during output
registration rather than only doing so after registration. not
waiting for registration to succeed may keep store paths alive
in the file system if registration fails for some reason; that
seem preferrable to the possibility of having another instance
of this bug. since we only leave *good* outputs around there's
not much to worry about except maybe bit of wasted disk space.

fixes #883

Change-Id: I8c22c92e39b9e203f1061278f86cde19dc4474a4
2025-06-27 15:38:53 +02:00
eldritch horrors a0a00948df libstore: fix scratch output cleanup
the daemon must use real store paths, not virtual store paths. using
virtual paths may inadvertently delete paths in the system nix store
when a build was run on a redirected store as root, which isn't good

Change-Id: Id048b236bda0e0ab1f3be6ccba0ddc1de2a3e941
2025-06-27 15:38:53 +02:00
eldritch horrors e3caf98a8f libstore: wait for cgroups to die on cleanup
killing a cgroup via `cgroup.kill` is not synchronous, we need to give
the processes in the group some time to wake up and exit. due to a few
historical accidents in the codebase we cannot do this asycnhronously,
e.g. with a kj promise without creating yet more problems. we will, at
some point in the future, have to move cgroup management into the main
daemon rather than doing it with RAII wrappers within every subdaemon.

Change-Id: I03bf9060144b5737729f2b05c25771c674fd154c
2025-06-25 14:59:58 +00:00
eldritch horrorsandRaito Bezarius 749afbbe99 libstore: don't default build-dir to temp-dir
if a build directory is accessible to other users it is possible to
smuggle data in and out of build directories. usually this ins only
a build purity problem, but in combination with other issues it can
be used to break out of a build sandbox. to prevent this we default
to using a subdirectory of nixStateDir (which is more restrictive).

Fixes CVE-2025-52991.

Change-Id: Iacfc9b50534de158618c815f9fb99d7dae1be4d0
2025-06-24 10:49:49 +00:00
a959290f41 libstore: use pasta for FODs if available
This allows using a userspace program, pasta, to handle comms between
the build sandbox, and the outside world; allowing for full isolation
including the network namespace, closing the "fixed-output derivation
talks to the host over an abstract domain socket" hole for good.

Fixes CVE-2025-46416.

Co-Authored-By: Puck Meerburg <puck@puckipedia.com>
Change-Id: Ifd499b7dbb3784600a6e842fede65fc031ff9f15
2025-06-24 10:49:49 +00:00