Commit Graph
17589 Commits
Author SHA1 Message Date
eldritch horrors 32bb2b1b5b libutil: asyncSpread
this could be a method of AsyncCollect, but putting there would require
another overload that synthesizes the empty key types we use here. even
then a separate function is slightly nicer because it spares us writing
things like `asyncCollect(someIterableOfPromises).collect()` or similar

Change-Id: Ia92abc105016414a2171e237f2a0bc6233d3ccbf
2025-03-05 18:49:45 +01:00
eldritch horrors df7e63427d libutil: add topoSortAsync
Change-Id: Icad14f3e168f9577e7b99ac5f3f552f8625aebcd
2025-03-05 17:34:25 +01:00
eldritch horrors 234fff5afc libstore: split LocalStore constructor
more precisely, split it into store preparation (which remains in the
constructor proper), db initialization, and prepared statements init.
this will let us more easily turn the dbState into a connection pool.

Change-Id: I894acd4553bc83a2d86229922b757c573e394cac
2025-03-05 17:34:25 +01:00
eldritch horrors 549f385d40 libstore: drastically shorten sqlite busy timeout
this is one of the cases retrySQLite is supposed to handle. with busy
timeouts set at the connection level we may instead wait for up to an
hour to acquire locks before actually falling back to the retrySQLite
loop, blocking an entire thread in the process. this isn't painful in
the current system that uses dedicated threads for everything, but an
async executor actually suffers. since we use sqlite in WAL mode, and
WAL mode still allows reads to happen concurrently with writes, we'll
want to not block an executor on sqlite write locks. (note that while
we do have a mutex around db access that mutex is only held inside of
retrySQLite callbacks, so it will be released where we'd block today)

do note that we don't disable the timeout completely since that could
drastically reduce write performance. multiple daemon processes using
the same database file will naturally conflict, but each write is not
usually that expensive. going to sleep immediately instead of waiting
a bit can greatly impact throughput. waiting for 50ms should be fine.

Change-Id: I2d8e36ed7a0183bbc213490ebde2c79fc6e2f4b2
2025-03-05 17:34:25 +01:00
eldritch horrors 0bb0f43aae libutil: add AsyncMutex lock waits
this is like a condition variable associated with the mutex. it's all
we'll need for the async transition, so we don't add a separate type.

Change-Id: Id9aefadd3b50e5f14f7b4d6bad41721f5249ce59
2025-03-05 16:42:11 +01:00
eldritch horrors 4cabfee3d5 libstore: asyncify IndirectRootStore::addIndirectRoot
Change-Id: I369f3b8773c0e73737f2b44228c115b134edab19
2025-03-05 16:42:11 +01:00
eldritch horrors bbe450c3af libstore: asyncify Store::getVersion
Change-Id: Ia7ef0e577122f6754a73b2293855c6ae8cfa8457
2025-03-05 16:42:11 +01:00
eldritch horrors adf33551e4 libstore: asyncify Store::setOptions
Change-Id: I80d45ccdd027663a2b7c32f21a9a78fda6906044
2025-03-05 16:42:11 +01:00
eldritch horrors 4cd14a30bc libstore: asyncify Store::isTrustedClient
Change-Id: Iabf4aa6bf04e23179f03f5d0055560970809773e
2025-03-05 16:42:11 +01:00
eldritch horrors 12e9b8da0f libstore: asyncify Store::getProtocol
Change-Id: I52744d925d1239fd326a3ec4e3a26e8e8ca44be0
2025-03-05 16:42:11 +01:00
eldritch horrors a783d2c0d9 libstore: asyncify Store::connect
Change-Id: I6668295e228092754304ef63cda0b889bd82b198
2025-03-05 16:42:11 +01:00
eldritch horrors 87efae8a53 libstore: asyncify Store::queryMissing
Change-Id: I33cc483a3a60208dc2a2c99fa277738be356f5f2
2025-03-05 16:42:11 +01:00
K900 ca89e431a3 perl: drop version check
Meson started handling those differently[0], and Perl 5.8 is old enough
that anyone running an even older Perl is honestly asking for it.

[0]: https://github.com/mesonbuild/meson/commit/a3679a64eec7c312c81d657880f34f015426c7db

Change-Id: Ifba22e38a82abf4b6965dda0eed43a3064533d25
2025-03-04 13:09:01 +03:00
eldritch horrors 9cc7d18752 disable n-e-j test until it is fixed
ma27 said it's okay. this thing fails every other ci build because it's buggy.

Change-Id: Iecfd793c22b8721c2e59e105167637d72dc53cba
2025-03-03 23:34:40 +01:00
eldritch horrors 14067da947 libstore: pass async streams to Store::add{,Multiple}ToStore
Change-Id: Idafc0d640bf66d2d28ff71ae81546db8cf463ee2
2025-03-03 21:13:44 +01:00
eldritch horrors dc8a634d24 libstore: pass async streams to Store::addToStoreFromDump
Change-Id: I1b1f7a63f093e33b0f8387e61342615708875ba7
2025-03-03 20:48:59 +01:00
eldritch horrors 6ba538a66f libstore: pass async streams to RemoteStore::addCAToStore
Change-Id: I793ec08df8e48378f471c70bf1d3cddd70954d64
2025-03-03 20:48:59 +01:00
eldritch horrors eda550246b libstore: pass async streams to BinaryCacheStore::addToStoreCommon
Change-Id: I8f9dbaa46c3644fdacb59cee2d7249ff20c3bf92
2025-03-03 20:48:59 +01:00
eldritch horrors ffbd120dcf libutil: add an async writeFile
Change-Id: I062c07446be2b282dfec6c31c21805aac9f44ff4
2025-03-03 20:48:59 +01:00
eldritch horrors ef5573065c libutil: add an async restorePath
Change-Id: I9319f3dd3db454684259d2b324412fdad6dd8a64
2025-03-03 20:48:59 +01:00
eldritch horrors 66d515a3a2 libutil: add an async nar indexer
Change-Id: I4c22364c94e2bea1f18b835d9514c4c65a530c80
2025-03-03 20:48:59 +01:00
eldritch horrors 2367521008 libutil: add an async nar parser
sadly this is a visitor-only interface; async generators are not yet a
thing and preliminary benchmarks say that overhead would be too large.

Change-Id: I0460d18eba94441cf3101d46bfffdb69cdda81d1
2025-03-03 20:48:59 +01:00
eldritch horrors 18a24393e8 libutil: add an async copyNAR overload
Change-Id: I046ff704a2d2cb5115f7bf610feac3ed3247d992
2025-03-03 20:48:59 +01:00
eldritch horrors eafc75b9e9 libutil: handle nar header in Parser as well
that'll make adding more Parser users a lot easier.

Change-Id: I88032d84b178c67896e930e275b9affe1e46ba83
2025-03-03 20:48:59 +01:00
eldritch horrors 99bc932196 libutil: add an async io header
we'll need all of these before long. we're so, so sorry.

Change-Id: I7baab54cf8a112b74d52e3a53f82836bd9f7cb83
2025-03-03 20:48:59 +01:00
eldritch horrors 3844e34053 libutil: add box_ptr<T>::take
sometimes it's useful to turn a box into a unique_ptr. let's have that.

Change-Id: I3d142c6e157c5e61c16f3953b3b8b4cd616f0e93
2025-03-03 20:48:59 +01:00
eldritch horrors bcea854b1f libstore: use nar_index in BinaryCacheStore::addToStoreCommon
we could have constructed a nar accessor from an index just as well, but
we don't need any of the advanced accessor features like retrieving file
contents or full path-string based access to the archive. using an index
directly is simpler and faster, although in practice we shouldn't notice

Change-Id: Ic521536cd89e88cbe5aba4f26bf40f0c40d09341
2025-03-03 20:48:59 +01:00
eldritch horrors 7160096a51 libstore: add a toJSON for nar indices
this lives with the NarAccessor (for now) because only the nar accessor
consumes this format in-tree, and produces the same format for a second
type of data source (an FSAccessor instead of a precomputed nar index).

Change-Id: I54cddcf59a4e0501b5cc296c606f063feee5fb3b
2025-03-03 20:48:59 +01:00
eldritch horrors 4bcc9fc0bb libstore: use new indexer in NarAccessor
Change-Id: Id8f33d19aa33d6ff2ccad4469b052f8834b3547f
2025-03-03 20:48:59 +01:00
eldritch horrors 0d81e81dd1 libutil: add a nar indexer
we'll use this in NarAccessor to provide actually safe indexing of
archives. NarAccessor currently is not fully correct: it relies on
the parser not buffering anything to produce correct file offsets,
but only the nar implementation itself can reasonably expect that.

Change-Id: I64f300b86d8844b876a3ace723546ea7d7b4628b
2025-03-03 20:48:59 +01:00
Maximilian BoschandGerrit Code Review 18975fa016 Merge "libexpr: improve error reporting if NIX_PATH item cannot be downloaded" into main 2025-03-03 08:43:54 +00:00
eldritch horrors 201c0d5b7f libstore: more explicitly discard uninteresting nar
this wasn't fully correct to begin with; if restorePath threw an
exception we would not have discarded the nar, but if deletePath
threw an exception we would have. discarding the nar in this way
also lets us not swallow nar parser exceptions when adding a nar
for a valid path, potentially notifying clients of corruption in
their own data sources. ideally we would never read the nar when
we're not interested anyway, but that needs a new wire protocol.

Change-Id: Ie5e10a9bee05b67ec2adb9c4f7c9319a4e644e31
2025-03-03 03:04:49 +01:00
eldritch horrors 338f624220 libstore: simplify Store::addToStoreSlow
the web of sinks and sources is really convoluted. all we want to do is
to always write the full path dump into narHashSink, also write the nar
(during recursive import) or only file data (during flat import) into a
dedicate non-sha256 hash sink, and maybe check that the path was a file
(when doing flat imports). the graphviz diagram did not improve things.

Change-Id: I2d036358a78963222da3db885cf6971e51369344
2025-03-03 03:04:49 +01:00
eldritch horrors f039abeb64 libutil: make direct nar dumping public
ma27 asked for it, for hydra reason. where's heracles when you need him?

Change-Id: I15719a97a037dbe8b0d4d2ec89191597857e2a0f
2025-03-03 03:04:49 +01:00
eldritch horrors 446e22323e libstore: pass around prepared dumps, not paths and filters
this fully decouples the possibly-never-async bits of dumping from the
generation of dump bitstream. having the two separate will allow us to
change store import methods to use async streams, not our sync sources

Change-Id: I9dbd5e30ad3ee380c244b4a3760c11e37db3895f
2025-03-03 03:04:49 +01:00
eldritch horrors 4af06b2717 libutil: split path dumping and filtering
filtering of paths may call into nixlang code, and in turn may call into
the async runtime. dumps and dump preparations should thus be considered
never-async, but we can't mark them as such yet because async methods do
call them without issue at time of writing. we cannot mark them as such;
only a single function in libexpr may cause such problems. fetchers also
use dumpPath with filters, but those filters never call into async code.

Change-Id: Ica0bd853419e08cd5b0f7926820e3c5a8d0f4688
2025-03-03 02:02:49 +00:00
eldritch horrors 3bf0dcaef3 libstore: split fetchToStore
only a single caller uses flat fetching at all. it still makes sense to
not inline that single caller for now, mostly due to activity reporting

Change-Id: I1a6420868443c3a684deafc7a4f567d4d4b1bd53
2025-03-03 02:02:49 +00:00
eldritch horrors f12cb77442 libstore: split Store::addToStore
same as before, only for a different method.

Change-Id: Id7238b26a25c21fe09df7147b16a39cc5371d8c0
2025-03-03 02:02:49 +00:00
Raito BezariusandGerrit Code Review 271f0e2507 Merge "libexpr: fix checkSourcePath purity regression" into main 2025-03-03 02:00:35 +00:00
Maximilian Bosch 079fe0ca50 libexpr: improve error reporting if NIX_PATH item cannot be downloaded
Last week I was hunting a production issue at work related to CppNix and
the only hint I had was this warning. While the cause was clearly a
CppNix issue since it was related to the libgit2-backed tarball cache,
the fact that this exception was hidden, made it way harder to discover
this. It would've saved me a lot of time[1] if the error was just
printed out (and thus would've ended up in the logs).

This is what this patch results in:

  $ nix-instantiate -I https://notexisting.com --find-file . --option connect-timeout 1
  warning: error: unable to download 'https://notexisting.com': Resolving timed out after 1001 milliseconds (curl error code=28); retrying in 265 ms
  warning: error: unable to download 'https://notexisting.com/': Connection timed out after 1002 milliseconds (curl error code=28); retrying in 523 ms
  warning: error: unable to download 'https://notexisting.com/': Connection timed out after 1001 milliseconds (curl error code=28); retrying in 1324 ms
  warning: error: unable to download 'https://notexisting.com/': Connection timed out after 1000 milliseconds (curl error code=28); retrying in 2670 ms
  warning:
         … while downloading https://notexisting.com to satisfy NIX_PATH lookup (ignoring)

         warning: unable to download 'https://notexisting.com/': Connection timed out after 1001 milliseconds (curl error code=28)
  /path/to/nix/path/root

The `unable to download` part was hidden before. Granted, this is not the most
interesting showcase given the retries before, but I'd still argue that
this is useful for cases where you don't have a connection timeout (and
this was just the most trivial way to test for me).

[1] Unlucky as I was, I had to mount an older backup and nixos-enter
    into the mount to reproduce this.

Change-Id: If2894369fc0b159a307b448e1ce7d9b54a327df6
2025-03-02 23:31:11 +01:00
Maximilian BoschandGerrit Code Review c0668db12c Merge "subprojects/nix-eval-jobs: bring back constituents" into main 2025-03-02 22:02:22 +00:00
eldritch horrors f1ecfbdd48 libstore: split Store::computeStorePathForPath
the two variants compute their store path hashes very differently, and
the flat version ignores the filter passed in by the user entirely. in
a future change we want to move filters out of store methods entirely,
splitting them now will make that task a lot easier when we are ready.

Change-Id: I5f23a26ca08e81923f33adf687056d0d464c2cb8
2025-03-02 17:37:12 +00:00
eldritch horrors 349516d6c7 libstore: remove unused parameter of Store::addToStore
Change-Id: I2816ed2689da8adb5634da180389e049e6ace6bc
2025-03-02 17:37:12 +00:00
eldritch horrors 8ce7d59c45 libstore: specialize Store::computeStorePathForPath
it's only used once at all, only with SHA256, and the hash it returned
was always ignored. probably a relic of a bygone age, but today is not
the time to clean this up. not before addToStore is rewritten, anyway.

Change-Id: I20e0b5a9bc85ccd05db79bf44f3e972fbd174902
2025-03-02 17:37:12 +00:00
eldritch horrors b5aa3a4197 libutil: inline ChainSource into sole remaining user
Change-Id: If0c81472a2e9b70e695631c147ce7eaae28d69d6
2025-03-02 17:37:12 +00:00
eldritch horrors 820c9bdaf5 libstore: don't abort when flat-importing non-files
fixes #705

Change-Id: I3be20235006425dd3bb6156510d021699f05b9ba
2025-03-02 17:37:12 +00:00
Alois Wohlschlager 9d99a7c2cf libexpr: fix checkSourcePath purity regression
Starting with commit 0dbfa7b26e access would also
be allowed to ancestors of allowed paths. This is (ironically) a significant
purity regression, since several users of the purity checks will themselves
assume that arbitrary descent is allowed. For example, `builtins.readDir` and
`builtins.path` could now refer to the filesystem root, breaking purity
entirely in the latter case by allowing to read arbitrary files. Restore the
previous behaviour of only allowing access to explicitly allowed paths.

Change-Id: Ie64180733ab735da9873255e1ccbf95ba7c9161c
2025-03-02 18:30:30 +01:00
eldritch horrors 94f15cb5a4 libutil: also test nar copies
Change-Id: Ia57005c476f289c7fbcbf7b96d6aa8e9d403bb86
2025-03-02 16:56:06 +00:00
Rebecca TurnerandJade Lovelace 20fea96996 Fix piping nix store ls output on macOS
`writeLogsToStderr` uses a static mutex in order to prevent log output
from being interleaved. On macOS, it was possible for a logger in a
non-main thread to call this function after the static mutex was
destructed, leading to strange errors. Deliberately leaking the mutex
prevents the destructor from being called, fixing the issue.

Closes #702

Co-Authored-By: Jade Lovelace <jadel@mercury.com>
Co-Authored-By: eldritch horrors <pennae@lix.systems>

Change-Id: I14c80134cc493972752fad56b7f15fad8e4d5a5b
2025-02-28 18:17:47 -08:00
jadeandGerrit Code Review 99bc6867e8 Merge "daemon: test group membership better on macOS" into main 2025-02-28 22:20:29 +00:00