1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-11 21:16:02 +01:00
Commit graph

21662 commits

Author SHA1 Message Date
Bernardo Meurer Costa
a9aaf0ed1d
refactor(libstore/find-cycles): use SourceAccessor for filesystem access
Replace direct `std::filesystem` operations with `SourceAccessor`..
2025-10-25 20:54:23 +00:00
Bernardo Meurer Costa
7a7b9fdf1c
perf(libstore/find-cycles): optimize transformEdgesToMultiedges to O(n)
Replace the multi-pass O(n²) algorithm with a single-pass O(n) approach
using hashmaps to track path endpoints.

Before:
- First pass: O(n*m) to join each edge with existing multiedges
- Second pass: O(m²) repeated merging until no more merges possible
- Required multiple iterations through the entire dataset

Now:
- Single O(n) pass through edges
- Two hashmaps (pathStartingAt, pathEndingAt) enable O(1) lookups
- Immediately identifies connections without linear searches
- Handles all cases in one pass:
  * Extending existing paths (prepend/append)
  * Joining two separate paths
  * Forming cycles when a path connects to itself
2025-10-25 20:54:23 +00:00
Bernardo Meurer Costa
daeee65a51
test(libstore): add parametrized tests for transformEdgesToMultiedges 2025-10-25 20:54:22 +00:00
Bernardo Meurer Costa
eea31494c1
fix(libstore/find-cycles): install header in public include directory
Move `find-cycles.hh` to `src/libstore/include/nix/store/build/` to
ensure it is properly installed as a public header and can be used by
tests and other consumers of the library.
2025-10-25 20:54:22 +00:00
Bernardo Meurer Costa
908469badb
refactor(libstore/find-cycles): conditionally include archive.hh on macOS only
Since caseHackSuffix is only used inside `#ifdef __APPLE__` blocks, gate
the archive.hh include with the same condition.
2025-10-25 20:54:22 +00:00
Bernardo Meurer Costa
5069b48da6
refactor(libstore/find-cycles): use std::filesystem::path parameter
Changed `walkAndScanPath` to take `std::filesystem::path` instead of `string`,
eliminating repeated string→path conversions throughout the function.
2025-10-25 20:54:21 +00:00
Bernardo Meurer Costa
d381d24fe3
refactor(libstore/find-cycles): rename scanForCycleEdges2 → walkAndScanPath
The "2" suffix was unclear and didn't communicate the function's purpose.
The new name better describes what it does: walks the filesystem tree and
scans each file using the provided sink.
2025-10-25 20:54:21 +00:00
Bernardo Meurer Costa
c70df0a2da
refactor(libstore/find-cycles): use std::filesystem::path operator/
Replace string concatenation for path joining with type-safe
`std::filesystem::path operator/`.
2025-10-25 20:54:21 +00:00
Bernardo Meurer Costa
18bf16ee76
refactor(libstore/find-cycles): add explicit include for caseHackSuffix
Added explicit `#include "nix/util/archive.hh"` since we use the
caseHackSuffix constant from it.
2025-10-25 20:54:20 +00:00
Bernardo Meurer Costa
8aa1564070
style(libstore/find-cycles): modernize type aliases (typedef → using) 2025-10-25 20:54:20 +00:00
Bernardo Meurer Costa
ce70994454
refactor(libstore/find-cycles): use portable std::filesystem and readFile APIs
Replaced POSIX-specific file operations with portable alternatives to
improve Windows compatibility.
2025-10-25 20:54:20 +00:00
Bernardo Meurer Costa
7eaa4991a4
fix(libstore/find-cycles): add second pass to merge multiedges
The single-pass greedy algorithm could fail to connect all edges if
they arrived in certain orders. For example, edges A→B, C→D, D→A, B→C
would result in two paths [D→A→B→C] and [C→D] instead of one complete
cycle.

Added a second pass that repeatedly tries to merge existing multiedges
with each other until no more merges are possible. This ensures we find
complete cycle paths regardless of edge discovery order.
2025-10-25 20:54:19 +00:00
Bernardo Meurer Costa
8f19a6cb83
style(libstore/find-cycles): use initializer list for edge construction 2025-10-25 20:54:19 +00:00
Bernardo Meurer Costa
22e74e5f1e
refactor(libstore/find-cycles): remove unused refLength constant
After refactoring to use `RefScanSink`, we no longer manually search for
hashes in buffers, so the `refLength` constant (hash length) is unused.
`RefScanSink` handles this internally.
2025-10-25 20:54:19 +00:00
Bernardo Meurer Costa
591851cd5e
fix(libstore/find-cycles): use readFull for robust file reading
Replaced raw `read()` with `readFull()` helper, which properly
handles partial reads and `EINTR`. The previous code manually checked
for errors but didn't handle the case where `read()` returns fewer
bytes than requested.
2025-10-25 20:54:19 +00:00
Bernardo Meurer Costa
2e9ea55795
refactor(libstore/find-cycles): make edges member private
Moved the `edges` member variable from public to private section for
better encapsulation. Access is provided through the `getEdges()`
method.
2025-10-25 20:54:18 +00:00
Bernardo Meurer Costa
5eebcf46fe
refactor(libstore/find-cycles): remove unused hashPathMap parameter
The `hashPathMap` was being passed to `CycleEdgeScanSink` and stored as
a member variable, but was never actually used. The sink only needs the
hash strings for detection via `RefScanSink`, not the full `StorePath`
mapping.
2025-10-25 20:54:18 +00:00
Bernardo Meurer Costa
5803daa940
perf(libstore/find-cycles): avoid copying StringSet on every chunk
Previously, `CycleEdgeScanSink::operator()` copied the entire
`getResult()` `StringSet` twice on every 64KB chunk to detect newly
found hashes. For large files, this created O(n * chunks) overhead.

Now we track which hashes have been recorded for the current file using
`recordedForCurrentFile`, avoiding the set copies. The insert() returns
true only for newly seen hashes, making this O(1) per hash found.
2025-10-25 20:54:18 +00:00
Bernardo Meurer Costa
f7c4bcee9d
refactor(libstore/find-cycles): use RefScanSink 2025-10-25 20:54:17 +00:00
Bernardo Meurer Costa
d44c8c8b69
feat(libstore): make cycle errors more verbose
Co-Authored-By: Milan Hauth <milahu@gmail.com>
2025-10-25 20:54:17 +00:00
John Ericson
bef3c37cb2
Merge pull request #14351 from obsidiansystems/json-project-reference
Clean up JSON utils in a few ways
2025-10-25 19:32:30 +00:00
John Ericson
0f0d9255c6 Clean up JSON utils in a few ways
In particular

- Remove `get`, it is redundant with `valueAt` and the `get` in
  `util.hh`.

- Remove `nullableValueAt`. It is morally just the function composition
  `getNullable . valueAt`, not an orthogonal combinator like the others.

- `optionalValueAt` return a pointer, not `std::optional`. This also
  expresses optionality, but without creating a needless copy. This
  brings it in line with the other combinators which also return
  references.

- Delete `valueAt` and `optionalValueAt` taking the map by value, as we
  did for `get` in 408c09a120, which
  prevents bugs / unnecessary copies.

`adl_serializer<DerivationOptions::OutputChecks>::from_json` was the one
use of `getNullable`. I give it a little static function for the
ultimate creation of a `std::optional` it does need to do (after
switching it to using `getNullable . valueAt`. That could go in
`json-utils.hh` eventually, but I didn't bother for now since only one
things needs it.

Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
2025-10-25 14:49:51 -04:00
Sergei Zimmerman
f0b95b6d5b
Merge pull request #14274 from lovesegfault/nix-s3-versioned
feat(libstore): support S3 object versioning via versionId parameter
2025-10-25 08:39:12 +00:00
Bernardo Meurer Costa
e38128b90d
feat(libstore): support S3 object versioning via versionId parameter
S3 buckets support object versioning to prevent unexpected changes,
but Nix previously lacked the ability to fetch specific versions of
S3 objects. This adds support for a `versionId` query parameter in S3
URLs, enabling users to pin to specific object versions:

```
s3://bucket/key?region=us-east-1&versionId=abc123
```
2025-10-25 07:57:58 +00:00
John Ericson
e213fd64b6
Merge pull request #14352 from NixOS/source-paths-tests
tests/functional: Add source-paths tests
2025-10-24 23:50:07 +00:00
Eelco Dolstra
1cd8458c28
tests/functional: Add source-paths tests
This has already been implemented in 1e709554d5
as a side-effect of mounting the accessors in storeFS. Let's test this so it
doesn't regress.

(cherry-picked from https://github.com/NixOS/nix/pull/12915)
2025-10-25 02:13:30 +03:00
John Ericson
ecaf9470b9
Merge pull request #14344 from obsidiansystems/json-schema-deriving-path
JSON Schema for `DerivedPath`
2025-10-24 23:09:08 +00:00
Sergei Zimmerman
8b7e03f0f9
Merge pull request #14350 from lovesegfault/s3-binary-cache-store
refactor(libstore): expose HttpBinaryCacheStore and add S3BinaryCacheStore
2025-10-24 22:59:02 +00:00
Sergei Zimmerman
04606d50d1
Merge pull request #14343 from NixOS/epipe-graceful
Revert "libmain: Catch logger exceptions in `handleExceptions`"
2025-10-24 22:52:29 +00:00
Bernardo Meurer Costa
476c21d5ef
refactor(libstore): expose HttpBinaryCacheStore and add S3BinaryCacheStore
Move HttpBinaryCacheStore class from .cc file to header to enable
inheritance by S3BinaryCacheStore. Create S3BinaryCacheStore class that
overrides upsertFile() to implement multipart upload logic.
2025-10-24 21:54:13 +00:00
John Ericson
1a9ba0d6fe
Merge pull request #14333 from lovesegfault/upsert-size-hint
refactor(libstore): add sizeHint parameter to upsertFile()
2025-10-24 19:29:06 +00:00
John Ericson
648714cd44
Merge pull request #14336 from lovesegfault/filetransfer-delete
feat(libstore): add DELETE method support to FileTransfer
2025-10-24 18:50:53 +00:00
Bernardo Meurer Costa
6b7223b6b7
refactor(libstore): add sizeHint parameter to upsertFile()
Add a sizeHint parameter to BinaryCacheStore::upsertFile() to enable
size-based upload decisions in implementations. This lays the groundwork
for reintroducing S3 multipart upload support.
2025-10-24 18:49:28 +00:00
Bernardo Meurer Costa
afe5ed879f
feat(libstore): add DELETE method support to FileTransfer
Add support for HTTP DELETE requests to FileTransfer infrastructure:

This enables S3 multipart upload abort functionality via DELETE requests
to S3 endpoints.
2025-10-24 18:03:14 +00:00
Bernardo Meurer Costa
d924374bf2
docs(libstore): document verb() method returns verb root for gerund form
Add documentation to FileTransferRequest::verb() explaining that it returns
a verb root intended to be concatenated with "ing" to form the gerund.
2025-10-24 18:03:13 +00:00
Bernardo Meurer Costa
f1968ea38e
refactor(libstore): replace HTTP method boolean flags with enum
Replace the individual boolean flags (head, post) with a unified
HttpMethod enum struct in FileTransferRequest.
2025-10-24 18:03:12 +00:00
John Ericson
8d338c9234 JSON Schema for DerivedPath
Note that this is "deriving path" in the manual -- the great sed of the
code base to bring it in sync has yet to happen yet.
2025-10-24 12:08:00 -04:00
John Ericson
9a695f9067
Merge pull request #14348 from NixOS/fetchClosure-access
Allow access to the result of fetchClosure
2025-10-24 15:44:31 +00:00
Sergei Zimmerman
925c0fa4a2
Merge pull request #14346 from NixOS/remove-verify-tls
libstore/filetransfer: Remove verifyTLS from FileTransferRequest, sin…
2025-10-24 10:48:43 +00:00
Eelco Dolstra
7308fde0bc Allow access to the result of fetchClosure 2025-10-24 11:11:03 +02:00
Sergei Zimmerman
324bfd82dc
Merge pull request #14337 from lovesegfault/fix-post-large
fix(libstore): use CURLOPT_POSTFIELDSIZE_LARGE for POST requests
2025-10-23 22:00:08 +00:00
Sergei Zimmerman
8e01e4ad5c
Merge pull request #14347 from NixOS/mahic-nix-cache-hook-fix
ci: Bump magic-nix-cache with post-build-hook fix
2025-10-23 22:43:46 +00:00
Sergei Zimmerman
4c4eb5d07f
ci: Bump magic-nix-cache with post-build-hook fix
No tagged release with the fix for [^].

[^]: 578f01e147
2025-10-24 01:34:09 +03:00
Sergei Zimmerman
b5ae3e10c2
libstore/filetransfer: Remove verifyTLS from FileTransferRequest, since it's always true
This variable is always true, so there's no use-case for it anymore.
2025-10-24 00:29:10 +03:00
Sergei Zimmerman
4f5af471fb
Revert "libmain: Catch logger exceptions in handleExceptions"
This reverts commit 90d1ff4805.

The initial issue with EPIPE was solved in 9f680874c5.
Now this patch does move bad than good by eating up boost::io::format_error that are
bugs.
2025-10-23 23:49:41 +03:00
Sergei Zimmerman
b9af19cedf
Merge pull request #14295 from NixOS/s3-store-human-readable-uri
libstore: Implement getHumanReadableURI for S3BinaryCacheStoreConfig
2025-10-23 19:33:49 +00:00
Eelco Dolstra
d6f1e2de21
Merge pull request #14323 from NixOS/skip-nar-parse
addToStore(): Don't parse the NAR

* StringSource: Implement skip()

This is slightly faster than doing a read() into a buffer just to
discard the data.

* LocalStore::addToStore(): Skip unnecessary NARs rather than parsing them

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-10-23 22:17:09 +03:00
John Ericson
5d365cd61f
Merge pull request #14341 from obsidiansystems/fix-golden-tests
Fix some characterization tests
2025-10-23 19:08:43 +00:00
John Ericson
c87f29a0b6 Fix some characterization tests
A few changes had cropped up with `_NIX_TEST_ACCEPT=1`:

1. Blake hashing test JSON had a different indentation

2. Store URI had improper non-quoted spaces

(1) was is just fixed, as we trust nlohmann JSON to parse JSON
correctly, regardless of whitespace.

For (2), the existing URL was made a read-only test, since we very much
wish to continue parsing such invalid URLs directly. And then the
original read/write test was updated to properly percent-encode the
space, as the normal form should be.
2025-10-23 14:03:21 -04:00
Eelco Dolstra
0a74b4905c
Merge pull request #14332 from NixOS/cleanup-ci
ci: Assorted collection of cleanups
2025-10-23 16:50:11 +00:00