1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00
Commit graph

12171 commits

Author SHA1 Message Date
Jörg Thalheim
6867a4688a
Merge pull request #13233 from xokdvium/function-args-opt
libexpr: Use `attrs.alreadySorted()` in primop_functionArgs
2025-05-20 08:29:42 +02:00
Sergei Zimmerman
49d026083b
Use transparent comparators for StringMap and StringPairs 2025-05-19 20:38:19 +00:00
Sergei Zimmerman
8ee513379a
Use StringMap instead of std::map<std::string, std::string> throughout the codebase 2025-05-19 20:33:28 +00:00
Sergei Zimmerman
a4bfd559f1
libexpr: Use attrs.alreadySorted() in primop_functionArgs
Formals are already sorted as it's an invariant of `Formals`.
2025-05-19 19:53:20 +00:00
Eelco Dolstra
8c10104e9e
Merge pull request #13228 from Mic92/json-utils
libutil-tests/json-utils: fix -Werror=sign-compare error
2025-05-19 16:15:09 +02:00
Robert Hensing
f18af849fe
Merge pull request #13170 from MattSturgeon/fix/call-flake/rel-path
Use correct parent `outPath` for relative path inputs
2025-05-19 14:13:54 +02:00
Jörg Thalheim
1290b7e53d libutil-tests/json-utils: fix -Werror=sign-compare error
I am on a newer different nixpkgs branch, so I am getting this error
2025-05-19 09:26:24 +02:00
Jörg Thalheim
e7078d4de1
Merge pull request #13142 from xokdvium/gc-root-boost-regex
libstore: Use `boost::regex` for GC root discovery
2025-05-18 21:44:41 +02:00
Jörg Thalheim
638b7ec6c5
Merge pull request #13219 from xokdvium/eval-profiler
libexpr: Add `EvalProfiler` and use it for `FunctionCallTrace`
2025-05-18 21:35:43 +02:00
Sergei Zimmerman
fa6f69f9c5
libexpr: Use EvalProfiler for FunctionCallTrace
This wires up the {pre,post}FunctionCallHook machinery
in EvalState::callFunction and migrates FunctionCallTrace
to use the new EvalProfiler mechanisms for tracing.

Note that branches when the hook gets called are marked with [[unlikely]]
as a hint to the compiler that this is not a hot path. For non-tracing
evaluation this should be a 100% predictable branch, so the performance
cost is nonexistent.

Some measurements to prove support this point:

```
nix build .#nix-cli
nix build github:nixos/nix/d692729759e4e370361cc5105fbeb0e33137ca9e#nix-cli --out-link before
```

(Before)

```
$ taskset -c 2,3 hyperfine "GC_INITIAL_HEAP_SIZE=16g before/bin/nix eval nixpkgs#gnome --no-eval-cache" --warmup 4
Benchmark 1: GC_INITIAL_HEAP_SIZE=16g before/bin/nix eval nixpkgs#gnome --no-eval-cache
  Time (mean ± σ):      2.517 s ±  0.032 s    [User: 1.464 s, System: 0.476 s]
  Range (min … max):    2.464 s …  2.557 s    10 runs
```

(After)

```
$ taskset -c 2,3 hyperfine "GC_INITIAL_HEAP_SIZE=16g result/bin/nix eval nixpkgs#gnome --no-eval-cache" --warmup 4
Benchmark 1: GC_INITIAL_HEAP_SIZE=16g result/bin/nix eval nixpkgs#gnome --no-eval-cache
  Time (mean ± σ):      2.499 s ±  0.022 s    [User: 1.448 s, System: 0.478 s]
  Range (min … max):    2.472 s …  2.537 s    10 runs
```
2025-05-18 11:55:39 +00:00
Sergei Zimmerman
6b4a86a9e3
libexpr: Add EvalProfiler
This patch adds an EvalProfiler and MultiEvalProfiler that can be used
to insert hooks into the evaluation for the purposes of function tracing
(what function-trace currently does) or for flamegraph/tracy profilers.

See the following commits for how this is supposed to be integrated into
the evaluator and performance considerations.
2025-05-18 11:55:37 +00:00
Matt Sturgeon
46beb9af76
Use correct parent outPath for relative path inputs
Ensure relative path inputs are relative to the parent node's _actual_
`outPath`, instead of the subtly different `sourceInfo.outPath`.

Additionally, non-flake inputs now also have a `sourceInfo` attribute.

This fixes the relationship between `self.outPath` and
`self.sourceInfo.outPath` in some edge cases.

Fixes #13164
2025-05-18 00:38:17 +01:00
Eelco Dolstra
fd407141e1 Make nix profile install an alias of nix profile add 2025-05-17 21:07:24 +02:00
Graham Christensen
b37d1cdd8e Rename nix profile install to nix profile add. 2025-05-17 21:07:24 +02:00
Eelco Dolstra
efcb9e36a9 Remove global fetcher cache
The cache is now part of fetchers::Settings.
2025-05-17 19:54:32 +02:00
Eelco Dolstra
7d89e46f65 Sync: Support moving out of another Sync 2025-05-17 19:38:36 +02:00
Eelco Dolstra
39f9f5d1b6
Merge pull request #13206 from obsidiansystems/goal-init-dedup
Deduplicate the goal creation functions
2025-05-17 09:07:51 +02:00
Sergei Zimmerman
5ea81f5b8f
libexpr: Actually cache line information in PosTable
Previous code had a sneaky bug due to which no caching
actually happened:

```cpp
auto linesForInput = (*lines)[origin->offset];
```

That should have been:
```cpp
auto & linesForInput = (*lines)[origin->offset];
```

See [1].

Now that it also makes sense to make the cache bound in side
in order not to memoize all the sources without freeing any memory.
The default cache size has been chosen somewhat arbitrarily to be ~64k
origins. For reference, 25.05 nixpkgs has ~50k .nix files.

Simple benchmark:

```nix
let
  pkgs = import <nixpkgs> { };
in
builtins.foldl' (acc: el: acc + el.line) 0 (
  builtins.genList (x: builtins.unsafeGetAttrPos "gcc" pkgs) 10000
)
```

(After)

```
$ hyperfine "result/bin/nix eval -f ./test.nix"
Benchmark 1: result/bin/nix eval -f ./test.nix
  Time (mean ± σ):     292.7 ms ±   3.9 ms    [User: 131.0 ms, System: 120.5 ms]
  Range (min … max):   288.1 ms … 300.5 ms    10 runs
```

(Before)

```
hyperfine "nix eval -f ./test.nix"
Benchmark 1: nix eval -f ./test.nix
  Time (mean ± σ):     666.7 ms ±   6.4 ms    [User: 428.3 ms, System: 191.2 ms]
  Range (min … max):   659.7 ms … 681.3 ms    10 runs
```

If the origin happens to be a `all-packages.nix` or similar in size then the
difference is much more dramatic.

[1]: 22e3f0e987
2025-05-15 23:07:25 +00:00
Sergei Zimmerman
4711720efe
libutil: Add LRUCache::getOrNullptr
For heavier objects it doesn't make sense to return
a std::optional with the copy of the data, when it
can be used by const reference.
2025-05-15 22:28:41 +00:00
John Ericson
7bd9eef772 Deduplicate the goal creation functions
The weak reference logic is the same in both these cases, and if/when I
get rid `addWantedOutputs`, also in the `DerivationGoal` case.
2025-05-15 16:59:48 -04:00
John Ericson
01207fd101 Remove useDerivation
Try to make `DerivationGoal` care less whether we're working from an
in-memory derivation or not.

It's a clean-up in its own right, but it will also help with other
cleanups under the umbrella of #12628.
2025-05-15 13:40:26 -04:00
John Ericson
c1085ce849 Get rid of virtual Goal::init()
Now, each class provides the initial coroutine by value. This avoids
some sketchy virtual function stuff, and will also be further put to
good use in the next commit.
2025-05-15 13:40:26 -04:00
Eelco Dolstra
0b46025f7a
Merge pull request #13196 from Mic92/store-config-base
rename StoreDirConfigItself to StoreDirConfigBase
2025-05-15 12:03:11 +02:00
Jörg Thalheim
2dd2142754 rename StoreDirConfigItself to StoreDirConfigBase
context: https://github.com/NixOS/nix/pull/13154#discussion_r2081904653
2025-05-15 11:24:42 +02:00
John Ericson
99cb85cd37 Revert "If a substitute closure is incomplete, build dependencies, then retry the substituter"
As summarized in
https://github.com/NixOS/nix/issues/77#issuecomment-2843228280 the
motivation is that the complicated retry logic this introduced was
making the cleanup task #12628 harder to accomplish. It was not easy to
ascertain just what policy / semantics the extra control-flow was
implementing, in order to figure out a different way to implementing it
either.

After talking to Eelco about it, he decided we could just....get rid of
the feature entirely! It's a bit scary removing a decade+ old feature,
but I think he is right. See the release notes for more explanation.

This reverts commit 299141ecbd.

Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
2025-05-14 20:16:40 -04:00
John Ericson
f70796309d
Merge pull request #13193 from xokdvium/lru-cache
libutil: Less unnecessary copying in `LRUCache`
2025-05-14 19:29:53 -04:00
John Ericson
d7481b4b63 Factor out resolveStoreConfig
Leverage #10766 to show how we can now resolve a store configuration
without actually opening the store for that resolved configuration.

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2025-05-14 18:30:25 -04:00
Sergei Zimmerman
d955b401a7
libutil: Sprinkle some noexcept on LRUCache::{size,clear}
The underlying containers are already noexcept to destroy and dtors are
noexcept in general.
2025-05-14 22:14:46 +00:00
Sergei Zimmerman
2f2e04142e
libutil: Simplify LRUCache::get by using list splice
Splicing the list element to the back can be done in
a much simpler and concise way without the need for
erasing and re-inserting the element. Doing it this
way is equivalent to just moving node pointers around,
whereas inserting/erasing allocates/deallocates new nodes.
2025-05-14 22:05:53 +00:00
Sergei Zimmerman
cd61e922ff
libutil: Use heterogeneous lookup for LRUCache
This gets rid of some ugly std::string_view -> std::string
conversions, which are an eye-sore and lead to extra copying.
2025-05-14 21:42:35 +00:00
Sergei Zimmerman
90d70aa4c9
libutil: Format lru-cache.hh
Rip off the band-aid for further refactors. The diff is
very small, so it makes to get it out of the way first.
2025-05-14 21:23:13 +00:00
John Ericson
d972f9e2e2 Split out store-open.hh and store-registration.hh
The existing header is a bit too big. Now the following use-cases are
separated, and get their own headers:

- Using or implementing an arbitrary store: remaining `store-api.hh`

  This is closer to just being about the `Store` (and `StoreConfig`)
  classes, as one would expect.

- Opening a store from a textual description: `store-open.hh`

  Opening an aribtrary store implementation like this requires some sort
  of store registration mechanism to exists, but the caller doesn't need
  to know how it works. This just exposes the functions which use such a
  mechanism, without exposing the mechanism itself

- Registering a store implementation: `store-registration.hh`

  This requires understanding how the mechanism actually works, and the
  mechanism in question involves templated machinery in headers we
  rather not expose to things that don't need it, as it would slow down
  compilation for no reason.
2025-05-14 16:07:57 -04:00
Jörg Thalheim
e088ab3eaf
Merge pull request #13154 from obsidiansystems/split-store-config
Stores no longer inherit from their configs
2025-05-14 21:08:40 +02:00
Jörg Thalheim
addb9f8418
Merge pull request #13180 from Jaculabilis/reload-flakes
nix repl: remember :load-flake calls for :reload
2025-05-14 20:35:58 +02:00
Tim Van Baak
fb510a9e50 nix repl: remember :load-flake calls for :reload
Fixes #8753
2025-05-13 20:56:41 -07:00
Sergei Zimmerman
20a724d131
docs: Fix miscellaneous typos and formatting issues 2025-05-13 22:20:11 +00:00
John Ericson
934918ba16 Stores no longer inherit from their configs
Fix #10766

See that ticket for details.

Progress (I hope!) towards #11139.

Co-Authored-By: Sergei Zimmerman <xokdvium@proton.me>
2025-05-13 15:56:35 -04:00
Jörg Thalheim
f0f196cef0
Merge pull request #13175 from xokdvium/optimise-fetchtarball
libutil/tarfile: Create the scratch `std::vector` only once
2025-05-13 14:21:26 +02:00
Sergei Zimmerman
7628155d2b
libutil/tarfile: Create the scratch std::vector only once
I can't find a good way to benchmark in isolation from the
git cache, but common sense dictates that creating (and destroying)
a 131KiB std::vector for each regular file from the archive imposes
quite a significant overhead regardless of the IO bound git cache.

AFAICT there is no reason to keep a copy of the data since
it always gets fed into the sink and there are no coroutines/threads
in sight.
2025-05-13 10:50:46 +00:00
Sergei Zimmerman
18a5589f9a
libstore: Depend on boost_regex explicitly 2025-05-13 08:51:46 +00:00
Eelco Dolstra
bdb3f613dd Improve 'cannot read file from tarball' error
It now says e.g.

  error: cannot read file from tarball: Truncated tar archive detected while reading data
2025-05-13 10:32:12 +02:00
Jörg Thalheim
ed521760bc
Merge pull request #13161 from NixOS/remove-final
nix flake prefetch: Remove __final
2025-05-13 08:50:36 +02:00
Jörg Thalheim
0f985fea11
Merge pull request #13138 from NixOS/register-builtin-builders
Register builtin builders
2025-05-13 08:50:19 +02:00
Jörg Thalheim
6fdb170fb3
Merge pull request #13159 from NixOS/ignore-dir
Avoid unnecessarily updating old lock files with 'dir' parameters
2025-05-12 22:34:50 +02:00
Eelco Dolstra
5a84237209 Improve build failure error messages
They're now laid out in a more readable way, and they shows the output
paths (if known).
2025-05-12 15:06:54 +02:00
Eelco Dolstra
c686de6505 nix flake prefetch: Remove __final
This is currently an internal attribute, not intended to be shown to
users.

Fixes #13150.
2025-05-09 16:44:48 +02:00
Eelco Dolstra
d00682beb2 Backward compatibility hack for dealing with dir in URL-style flakerefs 2025-05-09 10:10:42 +02:00
Sergei Zimmerman
3a1301cd6d
libstore: Use boost::regex for GC root discovery
As it turns out using `std::regex` is actually the bottleneck
for root discovery. Just substituting `std::` -> `boost::`
makes root discovery twice as fast (3x if counting only userspace time).

Some rather ad-hoc measurements to motivate the switch:

(On master)

```
nix build github:nixos/nix/1e822bd4149a8bce1da81ee2ad9404986b07914c#nix-cli --out-link result-1e822bd4149a8bce1da81ee2ad9404986b07914c
taskset -c 2,3 hyperfine "result-1e822bd4149a8bce1da81ee2ad9404986b07914c/bin/nix store gc --dry-run --max 0"
Benchmark 1: result-1e822bd4149a8bce1da81ee2ad9404986b07914c/bin/nix store gc --dry-run --max 0
  Time (mean ± σ):     481.6 ms ±   3.9 ms    [User: 336.2 ms, System: 142.0 ms]
  Range (min … max):   474.6 ms … 487.7 ms    10 runs
```

(After this patch)

```
taskset -c 2,3 hyperfine "result/bin/nix store gc --dry-run --max 0"
Benchmark 1: result/bin/nix store gc --dry-run --max 0
  Time (mean ± σ):     254.7 ms ±   9.7 ms    [User: 111.1 ms, System: 141.3 ms]
  Range (min … max):   246.5 ms … 281.3 ms    10 runs
```

`boost::regex` is a drop-in replacement for `std::regex`, but much faster.
Doing a simple before/after comparison doesn't surface any change in behavior:

```
result/bin/nix store gc --dry-run -vvvvv --max 0 |& grep "got additional" | wc -l
result-1e822bd4149a8bce1da81ee2ad9404986b07914c/bin/nix store gc --dry-run -vvvvv --max 0 |& grep "got additional" | wc -l
```
2025-05-06 21:58:52 +00:00
John Ericson
1594d4b879 Fix windows warning 2025-05-06 15:02:10 -04:00
Eelco Dolstra
060c34b664 Attempt to fix macOS build 2025-05-06 08:50:14 +02:00