Commit Graph
18042 Commits
Author SHA1 Message Date
eldritch horrors 5f42f66afa libstore: rpc-ish-ify remaining RemoteStore methods
oops, forgot a few

Change-Id: Ic9ed34c29d26e94109d5f69eb90f334f26170ec3
2025-06-17 14:34:05 +02:00
Jade Lovelace 833aef5bcb fix(rl-next): systemd unit description is using wrong section
> The resource control configuration options are configured in the
> [Slice], [Scope], [Service], [Socket], [Mount], or [Swap] sections,
> depending on the unit type.

Reported by Worm on matrix.

Change-Id: I5f942b864e40bc461e8751cdf8337b1f8c2bbce4
2025-06-17 05:05:48 +00:00
Ruby Iris Juric e01ad92c9c libstore/local-derivation-goal: cleanup "hash mismatch" error formatting
The previous format was a little bit messy, with inconsistent alignment of items in each line after the main error
message. The format has been cleaned up, by aligning the start of all values on the same column, and right-aligning
their labels.

Change-Id: Ic9bb3300faef00cd2e51ebb2f5e0077ade2ff949
2025-06-17 12:50:23 +10:00
Lily Ballard 97f1c5cfa1 Fix markdown link edge cases
Lowdown doesn't quite conform to CommonMark in parsing shortcut links
that are followed by a parenthesized expression, which looks like
`[link text] (unrelated text)`. CommonMark says the space there is
significant and ensures the `[link text]` is parsed as a shortcut link,
but Lowdown parses this like `[link text](unrelated text)`.

This fixes the output of `nix help`. The other case of a near-link was
in the `nix-env --install` docs, which don't get parsed by Lowdown, but
it turns out the link reference definition was missing. The generated
manpage stripped the brackets but the HTML manual page rendered the
broken link with brackets.

Change-Id: I6a6a69641fd2dbf9930bcd875ed21ea80fba909a
2025-06-15 19:04:00 -07:00
eldritch horrors 7453e2979f libstore: asyncify S3BinaryCacheStore
this has side-effects for FileTransfer as well since that uses S3Helper
for s3:// urls. the side effects should be entirely positive though: we
can run multiple s3 requests in parallel without explicitly running any
of them from thread pools (the aws s3 client takes care of that for us)

Change-Id: I67232e604ebb12982b63770f1661ea1d56c5087b
2025-06-15 14:08:48 +00:00
eldritch horrors 1729c8ca3e libstore: asyncify curl return streams
making stores and their users fully async requires all data streams to
be async. the most notable data streams in common usage are curl first
and remote stores second. curl is much more contained today and easier
to asyncify (with the preparatory work we've done in the past commits)

Change-Id: I2d6ff4687ee2b47e4efaa6714827b7283bed941d
2025-06-15 13:36:31 +00:00
eldritch horrors 04a2aba00a libstore: explicitly init curl transfer sources
this too will make it easier to make the streams async.

Change-Id: I9a961fc667042e0aed23d2241326f1ea719bc7a4
2025-06-15 13:36:31 +00:00
eldritch horrors 490c4e3694 libstore: extract closures in curl wrapper to methods
turning them into promises will be much less problematic this way.

Change-Id: I055186a6318fb75c67ae5e7f57561b2cd62d874e
2025-06-15 13:36:31 +00:00
eldritch horrors de89c7f7c8 libstore: asyncify curl interface
Change-Id: I3fc93016b8ac5e59d9062d4f4aead19ae051a680
2025-06-15 13:36:31 +00:00
eldritch horrors a0d5900408 libstore: asyncify BinaryCacheStore::upsertFile
Change-Id: I8e72399c5bfdf70b551fff832b3002ef21f1ef58
2025-06-15 13:36:31 +00:00
eldritch horrors c76f0467b2 libstore: asyncify BinaryCacheStore::fileExists
Change-Id: I7574f61bf222389606be87bbaff486b386cdbecd
2025-06-15 13:36:31 +00:00
eldritch horrors c108f339f5 libstore: asyncify BinaryCacheStore::getFile
Change-Id: If3a1f127470fdaffb0bf79e0692c5d6baf21f18e
2025-06-15 13:36:31 +00:00
eldritch horrors 9f32ab85e8 libstore: asyncify BinaryCacheStore::getFileContents
Change-Id: I7972d6da6d0ac535d2d20c85390c6d67242cab35
2025-06-15 13:36:31 +00:00
eldritch horrors 743703ce35 libstore: asyncify Store::narFromPath return stream
Change-Id: I051c58e650109c70021c0e0a745c7342226e295b
2025-06-15 13:36:31 +00:00
eldritch horrors d824753377 libutil: add async decompression support
it's a real mess, but it's also the best we can reasonably do.

Change-Id: I3b84840cede0363396bdf290d6e6b0e03ace513c
2025-06-15 15:35:51 +02:00
1e34c37477 flake/inputs: 24.11-small -> 25.05-small
We upgrade to 25.05 release, which contains the curl commit
https://github.com/curl/curl/commit/5fbd78eb2dc4afbd8884e8eed27147fc3d4318f6
done in
https://github.com/NixOS/nixpkgs/pull/396200#issuecomment-2795944006.

This fixes HTTP transfers generating arbitrary errors and possibly
failing unusually.

Users who are already depending on 25.05-small or a recent unstable
already had the fix.

Special mention to the Linux kernel who gave me the opportunity to get
on a 24 hours bisection side quest to fix the local release engineering
test.

Special thanks to everyone who had to endure me ranting.

Change-Id: I866caf65d5ea103f1fa5eccd57df8031c9eacda0
Co-authored-by: eldritch horrors <pennae@lix.systems>
Co-authored-by: helle <helle@h3l.li>
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-13 18:15:47 +00:00
helle db56d236dd tests/functional2: fixes prerequisite to ruff upgrade to 0.11.10
Most of these are simple fixes and clarifications. One set of fixes will
come in the commit that actually upgrades nixpkgs and hence ruff as it
will otherwise cause errors here.

Change-Id: Ie857da0f6cf728478700ec2d24cf518f8c7b7815
2025-06-13 12:51:34 +02:00
eldritch horrors ee06552402 libstore: asyncify RemoteStore::Connection::processStderr
we need a wrapper type for the remote exception because our Result type
does not deal well with its good type being the same as its error type.
we could have also return a `Result<Result<void>>` to fix this, but the
wrapper type clarifies via its name where the exception_ptr originates.

Change-Id: Ia6ce67b962cb8d6528b017f4cb682a55d6918939
2025-06-11 22:59:23 +00:00
eldritch horrors 7a10df6e76 libstore: asyncify RemoteStore connection setup
without this processStderr cannot be turned into a promise.

Change-Id: Ia8ee44e9e2344f61c2c63b787b42f867864c7119
2025-06-11 22:32:49 +02:00
eldritch horrors cc04a433f0 libstore: remove flushing from processStderr
it's part of sending the command and should be treated as such.

Change-Id: I7406ead5cd08c79efe50f3b0fcb522a18d9d7bcf
2025-06-11 22:29:30 +02:00
eldritch horrors 8b3fdbc847 libstore: add framed data support to sendCommand
the subframing layer is ... a bit of challenge. since the old code is
synchronous but wants to handle errors asynchronously anyway it is on
the subframing layer to *spawn a thread* that polls for errors on the
wire, while non-framed commands handle errors synchronously once they
have sent all their data. this encapsulation of the wires is far from
perfect (let alone legible), but hopefully it will be only temporary.

Change-Id: I26d8020549b767794cae121313360c488504995f
2025-06-11 22:29:30 +02:00
eldritch horrors 1a2247560d libstore: encapsulate reading simple command results
much the same as the previous change, but on the receiving side.

Change-Id: I9f8a156a9d8fccaf91347e34a5b6baf301df5800
2025-06-11 22:29:30 +02:00
eldritch horrors 2128a2dbac libstore: encapsulate sending of simple commands
use a new helper method to send simple command data (that is, command
data that doesn't involve nested framing) to the daemon. this wraps a
large chunk of wire io, and once all wire io is wrapped thusly we can
replace the sink/source io model with new async input/output streams.

Change-Id: Ief9f520263c230a98403b8756bde917fd1cb236e
2025-06-11 22:29:30 +02:00
eldritch horrors ec374bc6e2 libstore: deserialize findRoots data as vector-of-tuples
a size_t followed by as many pairs of things is exactly the format of a
vector of two-element tuples. it would also be the format of a map, but
Roots is a map of sets. rather than adding a serialization format fixed
to this map type (or some wrapper) we can deserialize the response as a
vector and convert it to the map-of-sets later as this is not run much.

Change-Id: I3950c0f7cc59661576170ace10b25a6f8af1464b
2025-06-11 22:29:30 +02:00
eldritch horrors ab8f4ae7e3 libstore: add CommonProto code for bool/unsigned/uint64_t
we will need these very soon to make the daemon wires more rpc-like.

Change-Id: Ib54acdff0899d70a4c9b1d00c144932c37fdff91
2025-06-11 22:29:30 +02:00
eldritch horrors 87fbc15938 libutil: make the pool element factory a promise
processStderr of RemoteStore wants to be a promise and it must be used
from connection setup, so the pool factory callback must be a promise.

Change-Id: I9ac742b6048ae6dba0bfa5dcb58971386229690b
2025-06-11 22:28:44 +02:00
eldritch horrors 56847dc10d libutil: make Buffered{Sink,Source} io buffer shareable
async io for remote store connections needs some sync parts still for
serialization purposes, and those will have to reuse async io buffers

Change-Id: I05e066e3bf8c4318dc23306383f6a849d018ef91
2025-06-11 18:11:57 +00:00
eldritch horrors 7d681a5049 libutil: add io buffer abstraction
the rpc transition will require sync and async objects to share a single
io buffer (since defining serializers on async is an immense pain in the
tail, slow, and ultimately not necessary). a generic buffer class allows
us to reuse existing serializers more readily (reuse them at all, even).

Change-Id: I5ebba8449f26f2bb76016818928183c7e0123be0
2025-06-11 18:11:57 +00:00
eldritch horrors cc560704de libstore: have SSH use a socketpair, not two pipes
remote store async io will need to set O_NONBLOCK on the connection fds,
and right now the number of fds can vary between connection types: local
connections have one one fd for the sink/source pair since they use unix
sockets, but ssh connections have two because ssh uses pipes. this makes
it rather hard to manage flags correctly, and even harder to wait for io
readiness on both directions using kj. using sockets for ssh fixes this.

Change-Id: I0f563ece7627cd3fbd0f5ce21c25140469729e5a
2025-06-11 18:11:57 +00:00
eldritch horrors 9c4fd3d881 libstore: remove unused RemoteStore::Connection::closeWrite
Change-Id: I4a25807ad870c4704b8efa70e5652206ae654995
2025-06-11 18:11:57 +00:00
Raito Bezarius bea24c8d27 libutil/cgroup: destroy state record at destroy time
If state records are not destroyed at destroy time, this might confuse a
new build that thinks there's a remnant of a cgroup when actually it was
destroyed.

This fixes a bunch of inoffensive and noisy warnings about cgroups being
deleted by someone else.

Reported-by: Ramses <@rvdp:infosec.exchange>
Change-Id: Ib3d33f4ecd6143f33e032c5107b288b4ecabaee1
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-11 15:53:04 +02:00
Raito Bezarius 7bd82718e2 libstore/platform/linux: destroy cgroup before we release user locks
User locks are taken to avoid another build grabbing the same UID.

Under build user contention, it is possible to recycle the same UID from
another build which did not run the Goal destructor yet.

Prior to this change, cgroups were destroyed at Goal destruction time,
but user locks were released at `buildDone()` time.

Therefore, it was possible to have 2 builds fights for the same cgroup
and mess with it, resulting in confusion.

To avoid this, we override `cleanupHookFinally` in charge to release the
user locks and we destroy the cgroup before releasing the locks.

Statistics are kept in the `cgroup` object a bit longer and can be
obtained at `killSandbox(true)` time.

`AutoDestroyCgroup::kill` now ignore if the cgroup path has already been
destroyed, as kill is idempotent.

Reported-by: Ramses <@rvdp:infosec.exchange>
Reported-by: Frederico Schonborn <@fredericoschonborn:matrix.org>
Change-Id: Idfbf9aaf010c5f718f2c1c38548383d912d8ee95
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-11 13:47:38 +02:00
Raito Bezarius 797c6d4cd4 libutil/file-system: make AutoDelete not copyable and movable
Such a RAII structure should NEVER be copyable or movable, otherwise:

```
AutoDelete x;

x = AutoDelete(p, false);
```

will trigger the immediate deletion of `p`!

This fixes an annoying bug where the state record for cgroups was
deleted immediately as soon as it was created.

Change-Id: I2bfbc0815706700a0a75b79d1059cc552119b2c9
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 23:29:10 +02:00
Raito Bezarius 9f9fced2dd libstore/build/worker: clean up cgroup error messages typos
It's `delegated` and not `delgated`, also it's `DelegateSubgroup` and
not `DelegateSubtree` which I clearly hallucinated because of subtree
vs. sub(c)group.

Change-Id: Icfaa6116fa83416c431820978ef35aa8aa943feb
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 23:29:10 +02:00
a527bb251a libstore/build: cgroup delegation to sandbox
We offer full cgroup delegation to our sandbox now, required for running
containers inside the sandbox.

To run systemd-nspawn or containers managers inside the sandbox, there
is a need for one extra ingredient now: control over your own cgroup
subtree inside the sandbox.

If, in addition, you need multiple UIDs, for e.g. rootless usecases, you
need to run with the `uid-range` system feature.

Therefore, when the daemon or Nix runs under the right condition, e.g.
systemd-style delegation of the cgroup subtree while placing the
nix-daemon in a supervisor sub-cgroup, we create a new sub-cgroup for
each build based on the build UID and delegate that sub-cgroup to the
builder's process.

Additionally, `uid-range` always request the `cgroups` feature now, as
`uid-range` builds would probably always benefit from having cgroups
delegated, but the converse is not true.

Inspired from https://github.com/NixOS/nix/pull/11412 with a different
design that does not use function-local statics to derive the root
cgroup.

Co-authored-by: Linus Heckemann <git@sphalerite.org>
Co-authored-by: Parker Hoyes <contact@parkerhoyes.com>
Change-Id: Ic8947c5adaf4b5bbd153386e05fad65a935274fa
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 20:50:00 +02:00
Raito Bezarius 1783d5b348 libstore/build: drop cgroups experimental feature
We drop it to re-introduce it via the concept of build context which
will control in which cgroup a certain build should be spawned.

Change-Id: I4b4705d768129a6d7c0f061dc2163ba116088b18
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 16:00:51 +00:00
Raito Bezarius 21dbd7745d libstore/binary-cache-store: skip NAR listings if it's not possible to serialize it
Some source trees might not be representable inside of the NAR listing
format v1 as file paths (on Linux) are not guaranteed to be valid UTF-8.

When something like this happens on a large-scale build farm, a
mysterious "queued" but impossible to process job appears, this is
because we cannot write the NAR listing and serialization always fails.

Why did this work before? nlohmann was introduced _after_ such paths
were ingested, see: 09f00dd4d0.

What happened for such previously mis-serialized NAR listings?

```
curl -v 'https://cache.nixos.org/nz8p9hn00r6z7s57581c1hiv39pa1ia6.ls' |
brotli -d | jq .
```

This fixes the build of `sub-batch`
(https://github.com/kl/sub-batch/tree/master/tests/rename_invalid_utf8)
on ForkOS infrastructure.

Many thanks to Puck for the assistance on holding `rr` right on this one
and finding the history of these changes.

Change-Id: I2c2fbac70818e02810f9fd236c3a248187bf5fe7
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 15:22:22 +00:00
Raito Bezarius 1e71df37b7 doc/manual/rl-next: mention symbol value reuse
Forgotten in the symbol value reuse chain.

Change-Id: I7050f56cffcddce5fae4f74ebb35a9fe108a5dcf
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 16:25:29 +02:00
Raito Bezarius ebc8f56b52 libexpr/primops: pass the underlying Value of symbols if possible
Instead of allocating a new Value and copy the symbol string
representation inside of it, we can pass along the underlying Value,
which avoids (garbage collected) allocations.

This results in:

* a ~8 % reduction for `gc.totalBytes` over
  `nixos.ec2.closures.x86_64-linux` for NixOS 24.11. (920MiB → 842MiB)
* a slight reduction in CPU time due to less allocations being performed
  at all

Change-Id: I097f586dbc98f889fbc62d0a5f80c9d76ddedfd2
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 13:58:08 +02:00
Raito Bezarius 5e98a2159b libexpr/symbol-table: introduce InternedSymbol
The backing storage for symbols becomes a class storing a Value and a
string.

The Value is itself a string which contents points to the owned string.

Recovering a `SymbolStr` is still possible.

Change-Id: I171151abc3c0a513f2150c4b54edd61dea256cce
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 13:58:08 +02:00
Raito Bezarius 364e94fe23 libexpr/value: do not depend on Symbol
The symbol table will contain types that encloses a Value, thus, it
needs to depend upon the Value header, whereas the Value header depends
on `Symbol` for typedefs.

We move the typedefs in the place where they are used.

Change-Id: Ic533e5aad927b9bc4a9d1723430e90e86a4b5466
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 13:58:08 +02:00
Raito Bezarius 95ea358f98 libexpr/print: drop redundant constructor in emplace_back call
Change-Id: I79210edfede0a1d17f38b5834515f56d44c97466
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 13:58:08 +02:00
Tom HubrechtandRaito Bezarius ac3b742510 libexpr/symbol-table: remove unused field from SymbolTable::symbols
Change-Id: Id16ba5c9b7941757746d0cb79eb14463845aadb1
2025-06-10 13:58:08 +02:00
Raito BezariusandTom Hubrecht 5db71cfb3b libutil: add should emplace inside a ChunkedVector
This simplifies many call-sites where construction can take place
automatically.

Change-Id: I87f697d55375676345b388024eb8df900bf808de
Co-authored-by: Tom Hubrecht <github@mail.hubrecht.ovh>
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-10 13:58:06 +02:00
Qyriad d8b1bb5862 build: fix Meson warning about lix-clang-tidy not having meson_version
This fixes Meson's "Project does not target a minimum version but uses
feature introduced in '1.1': meson.options file" warning.

Silly Meson.

I also added a note in the top-level meson.build to indicate
`meson_version` is specified in more than one place.

Change-Id: I2c04278bb46a562a1c96cd2e5e4d9ce59ce8e125
2025-06-09 14:10:44 +02:00
Raito Bezarius b70bbbe680 misc/pre-commit: add automatic clang-format of changed lines
Lix has a style guide:
https://wiki.lix.systems/books/lix-contributors/page/code but
contributors like me have been unable to enforce it, which is sad.

To avoid further violations of that style guide, we enable a pre-commit
hook for clang formatting of the changed lines.

Change-Id: I217452efa3ac8bd66b4d3a08a6fe9a241207790b
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-07 15:27:11 +02:00
Raito Bezarius c19a0fe288 devshell: add git-clang-format
This is useful to reformat only changed hunks of a file via
`clang-format`.

Change-Id: I9aa8526d75fd2301113ee57f3a2e595f3b03504f
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-07 15:27:11 +02:00
Commentator2.0 004a505dc6 tests/functional2/nix: fix config serialization
Currently, the typecheck for the config values is only done
half-heartedly only checking if something is either a list or non-list
item, but not checking what type the list items are

this commit fixes the typecheck and adds test for proper serialization

Change-Id: Ifd93842b19b1dd870bdb3af0c000243b4380e7aa
2025-06-07 00:14:57 +02:00
Commentator2.0 0625e69912 tests/functional2: fix bad error message when merging files
The error message used to only contain the last key of the merge failure
this commit changes the message to contain the full path to the merge
conflict, resolving ambiguity

Change-Id: I9848a559b1b888e50a548eef8609bf34506040de
2025-06-07 00:14:57 +02:00
Commentator2.0 afa5b924cd tests/functional2: improve type checking util
currently, there is a small helper funciton in lang_util to check if
something is of a list type generic

to improve re-usability, this function is moved to utils and improved to
be also check for nested iterables and such

Change-Id: I92984daa4c4decf13d340a2ea5e52f724cee800e
2025-06-07 00:14:57 +02:00