1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-05 20:41:47 +02:00
Commit graph

12182 commits

Author SHA1 Message Date
John Ericson
041394b741 monitor-fd.hh: Format
It's a pretty small diff, so let's just start formatting before we make
other changes.
2025-03-23 18:00:36 -04:00
Robert Hensing
2172c17b5e
Merge pull request #12701 from mightyiam/nix-infrec-base-error
stack overflow is EvalBaseError
2025-03-21 14:10:22 +00:00
mergify[bot]
f0b7b37425
Merge pull request #12697 from NixOS/worker-abstraction
Make Goal code use abstractions over interations with Worker
2025-03-21 10:38:29 +00:00
Shahar "Dawn" Or
23c7a45a05 stack overflow is EvalBaseError 2025-03-20 17:43:20 +00:00
The Tumultuous Unicorn Of Darkness
83ec81789a
Use feature_level field from libcpuid (#12674)
Close #11375

Co-authored-by: John Ericson <git@JohnEricson.me>
2025-03-20 13:11:55 -04:00
Las
36e5aa6c7d Make Goal code use abstractions over interations with Worker
Instead of calling `worker.waitForAWhile(shared_from_this())` etc.,
the subclasses of Goal instead call protected functions defined in Goal
that abstract over these.

The code for awaiting has also been heavily simplified.
Instead of calling `addWaitee`, then suspending,
`co_await await(waitees)` is called once, which also handles the suspend.

The end-goal is to remove all manual `co_await Suspend{}`s.
2025-03-19 18:36:43 -04:00
Jörg Thalheim
c97f779dbb
Merge pull request #12692 from obsidiansystems/small-derivation-goal-cleanups
Small derivation goal cleanups
2025-03-19 23:30:23 +01:00
John Ericson
3d333e0aff
Merge pull request #12667 from NixOS/in-dir-cleanup
Cleanup `isInDir` and  `isDirOrInDir`
2025-03-19 18:01:59 -04:00
John Ericson
91e90aaee0 Clean up one path computation with / operator
Because of the previous commit, we need to use `std::filesystem::path`
anyways.
2025-03-19 17:14:55 -04:00
John Ericson
d3de22b2be isInDir and isDirOrInDir: Clean up with std::filesystem
The behavior *does* change, per the tests, but I think the new behavior
is less buggy.
2025-03-19 17:13:21 -04:00
John Ericson
3286728e40 Simplify isInDir usage with isDirOrInDir 2025-03-19 17:12:49 -04:00
Jörg Thalheim
2790f5f9ae libutil/file-descriptor: handle EAGAIN in read/write operations
We now see exception beeing thrown when remote building in master
because of writing to a non-blocking file descriptor from our json logger.

> #0  0x00007f2ea97aea9c in __pthread_kill_implementation () from /nix/store/wn7v2vhyyyi6clcyn0s9ixvl7d4d87ic-glibc-2.40-36/lib/libc.so.6
> #1  0x00007f2ea975c576 in raise () from /nix/store/wn7v2vhyyyi6clcyn0s9ixvl7d4d87ic-glibc-2.40-36/lib/libc.so.6
> #2  0x00007f2ea9744935 in abort () from /nix/store/wn7v2vhyyyi6clcyn0s9ixvl7d4d87ic-glibc-2.40-36/lib/libc.so.6
> #3  0x00007f2ea99e8c2b in __gnu_cxx::__verbose_terminate_handler() [clone .cold] () from /nix/store/ybjcla5bhj8g1y84998pn4a2drfxybkv-gcc-13.3.0-lib/lib/libstdc++.so.6
> #4  0x00007f2ea99f820a in __cxxabiv1::__terminate(void (*)()) () from /nix/store/ybjcla5bhj8g1y84998pn4a2drfxybkv-gcc-13.3.0-lib/lib/libstdc++.so.6
> #5  0x00007f2ea99f8275 in std::terminate() () from /nix/store/ybjcla5bhj8g1y84998pn4a2drfxybkv-gcc-13.3.0-lib/lib/libstdc++.so.6
> #6  0x00007f2ea99f84c7 in __cxa_throw () from /nix/store/ybjcla5bhj8g1y84998pn4a2drfxybkv-gcc-13.3.0-lib/lib/libstdc++.so.6
> #7  0x00007f2eaa5035c2 in nix::writeFull (fd=2, s=..., allowInterrupts=true) at ../unix/file-descriptor.cc:43
> #8  0x00007f2eaa5633c4 in nix::JSONLogger::write (this=this@entry=0x249a7d40, json=...) at /nix/store/4krab2h0hd4wvxxmscxrw21pl77j4i7j-gcc-13.3.0/include/c++/13.3.0/bits/char_traits.h:358
> #9  0x00007f2eaa5658d7 in nix::JSONLogger::logEI (this=<optimized out>, ei=...) at ../logging.cc:242
> #10 0x00007f2ea9c5d048 in nix::Logger::logEI (ei=..., lvl=nix::lvlError, this=0x249a7d40) at /nix/store/a7cq5bqh0ryvnkv4m19ffchnvi8l9qx6-nix-util-2.27.0-dev/include/nix/logging.hh:108
> #11 nix::handleExceptions (programName="nix", fun=...) at ../shared.cc:343
> #12 0x0000000000465b1f in main (argc=<optimized out>, argv=<optimized out>) at /nix/store/4krab2h0hd4wvxxmscxrw21pl77j4i7j-gcc-13.3.0/include/c++/13.3.0/bits/allocator.h:163
> (gdb) frame 10
> #10 0x00007f2ea9c5d048 in nix::Logger::logEI (ei=..., lvl=nix::lvlError, this=0x249a7d40) at /nix/store/a7cq5bqh0ryvnkv4m19ffchnvi8l9qx6-nix-util-2.27.0-dev/include/nix/logging.hh:108
> 108             logEI(ei);

So far only drainFD sets the non-blocking flag on a "readable" file descriptor,
while this is a "writeable" file descriptor.
It's not clear to me yet, why we see logs after that point, but it's
also not that bad to handle EAGAIN in read/write functions after all.
2025-03-19 22:02:18 +01:00
tomberek
5df1975246
Merge pull request #12570 from P-E-Meunier/macos-fix
Fix macos sandbox issue
2025-03-19 16:19:59 -04:00
Pierre-Etienne Meunier
300465c7b8 Fix macos sandbox issue
Co-authored-by: John Ericson <git@JohnEricson.me>

Co-authored-by: Poliorcetics <poliorcetics@users.noreply.github.com>
2025-03-19 17:09:18 +00:00
Jörg Thalheim
314e9fbeda libfetchers: fix double quote in path printed in logger 2025-03-19 16:04:16 +01:00
mergify[bot]
d10f9488fe
Merge pull request #12658 from obsidiansystems/local-derivation-goal-hide-and-split
Move `RestrictedStore` into its own file+header
2025-03-19 10:00:34 +00:00
Robert Hensing
95b0971031
Merge pull request #12652 from roberth/cli-json-pretty
nix-cli: Add --json --pretty / --no-pretty
2025-03-18 12:29:43 +00:00
Robert Hensing
9ff8309f47 Remove commented code
Some four years old; time to go
2025-03-18 08:14:07 +00:00
John Ericson
1c022077ea Get rid of on usage pair of actLock
Now that we have coroutines, we can go back to loops and regular RAII,
which is must less error-proone!

I look forward to removing the other instances!
2025-03-17 11:07:25 -04:00
John Ericson
7f8d348f3d Move derivationType from DerivationGoal to LocalDerivationGoal
The super class doesn't actually care.
2025-03-17 11:07:25 -04:00
John Ericson
5283589542 RestrictedStore: Move some definitions outside of the type declaration
Even when the type is not currently declared in a header, I still consider this a
more future-proof style.
2025-03-17 11:01:18 -04:00
John Ericson
5026d5af95 Move RestrictedStore into its own file+header
Perhaps more significantly, it no longer knows about
`LocalDerivationGoal`, and without any effort it also compiles on
Windows just fine. (`local-derivation-goal.{cc,hh}` is currently skipped
on Windows.)
2025-03-17 10:54:48 -04:00
John Ericson
2cfd031511
Merge pull request #12662 from obsidiansystems/local-derivation-goal-hide
Local derivation goal hide
2025-03-16 17:13:22 -04:00
Robert Hensing
e4bda20918
Merge pull request #12586 from xokdvium/refactor/chmod-if-needed
{libutil,libstore}: Factor out chmodIfNeeded
2025-03-15 09:06:28 +00:00
John Ericson
7f2b7b8bd1 Do not expose LocalDerivationGoal implementation
We just need to expose construction functions.
2025-03-14 15:57:24 -04:00
John Ericson
d572533774 Move signPathInfo to Store
Motivation is the same for moving `signRealisation` in
db8439c328.
2025-03-14 15:57:24 -04:00
Robert Hensing
1bff2aeec0
Merge pull request #12645 from xokdvium/debugger-perf
Make debugger significantly faster
2025-03-14 13:21:12 +00:00
Robert Hensing
fe00dfbd56 nix-cli: Add --json --pretty / --no-pretty
Default: istty(stdout)

This refactors `nix develop` internals a bit to use the `json` type
more. The assertion now operates in the in-memory json instead of
re-parsing it. While this is technically a weaker guarantee, we
should be able to rely on the library to get this right. It's its
most essential purpose.
2025-03-14 12:39:13 +00:00
Sergei Zimmerman
adbd08399c {libexpr,libcmd}: Make debugger significantly faster
The underlying issue is that debugger code path was
calling PosTable::operator[] in each eval method.
This has become incredibly expensive since 5d9fdab3de.

While we are it it, I've reworked the code to
not use std::shared_ptr where it really isn't necessary.

As I've documented in previous commits, this is actually
more a workaround for recursive header dependencies now
and is only necessary in `error.hh` code.

Some ad-hoc benchmarking:

After this commit:

```
Benchmark 1: nix eval nixpkgs#hello --impure --ignore-try --no-eval-cache --debugger
  Time (mean ± σ):     784.2 ms ±   7.1 ms    [User: 561.4 ms, System: 147.7 ms]
  Range (min … max):   773.5 ms … 792.6 ms    10 runs
```

On master 3604c7c51:

```
Benchmark 1: nix eval nixpkgs#hello --impure --ignore-try --no-eval-cache --debugger
  Time (mean ± σ):     22.914 s ±  0.178 s    [User: 18.524 s, System: 4.151 s]
  Range (min … max):   22.738 s … 23.290 s    10 runs
```
2025-03-13 16:24:30 +00:00
Eelco Dolstra
d0227f8d02 JSONLogger: Acquire a lock to prevent log messages from clobbering each other 2025-03-13 16:02:10 +01:00
Sergei Zimmerman
50123f2a56 libutil: Fix Pos::getSourcePath
Previous implementation didn't actually check if
std::get_if returned a nullptr:

std::optional<SourcePath> getSourcePath() const {
    return *std::get_if<SourcePath>(&origin);
}
2025-03-13 13:29:08 +00:00
Sergei Zimmerman
bf12aedf2e libutil: Document hacks and problems around Pos class
This should provide context for follow-up commits in
the patch series.
2025-03-13 13:29:08 +00:00
Sergei Zimmerman
a53b184e63 {libutil,libexpr}: Move pos-idx,pos-table code to libutil
All of this code doesn't actually depend on anything from
libexpr. Because Pos is so tigtly coupled with Error, it
makes sense to have in the same library.
2025-03-13 13:29:08 +00:00
John Ericson
ecdcba27c5 Remove unused parameter to the goal constructor
It has been unused since 37fca662b0.
2025-03-12 19:09:54 -04:00
John Ericson
1055c9fd14
Merge pull request #12630 from L-as/me/clean-up-drv-goal
Clean up derivation goals a bit
2025-03-12 15:52:05 -07:00
Jörg Thalheim
cba1a2155a
Merge pull request #12567 from obsidiansystems/slightly-rework-drv-resolution
Rework derivation input resolution
2025-03-12 23:15:45 +01:00
John Ericson
dc0bc7f0a3 Make debug message more precise 2025-03-12 18:09:38 -04:00
John Ericson
99d0dd3a43 Simplify hook error status logic
The simplification here is due to a long-standing bug, but it is not
worth fixing the bug at this time. Instead we've finally written up an
issue for the bug, and referenced the issue number in the code.
2025-03-12 18:09:38 -04:00
John Ericson
06af9cb532 Inline the try-catch BuildError in the hook case
In the local building case, there is many things which can through
`BuildError`, but in the hook case there is just this one. We can
therefore simplify the code by "cinching" down the logic just to the
spot the error is thrown.

There is other code outside `libstore/build` which also uses
`BuildError`, but I believe those cases are mistakes. The point of
`BuildError` is the narrow technical use-cases of "errors which should
not be fatal with `--keep-going`". Using it outside the
building/scheduling code doesn't really make sense in that regard. It
seems likely that those usages were instead merely because "oh, this
error has something to do with building, so I guess `BuildError` is
better than `Error`".

It is quite likely that I myself used `BuildError` incorrectly as
described above :).
2025-03-12 18:09:38 -04:00
John Ericson
a39ed67180 Do no store timestamps in the build result in the build hook case
The variables are only set by CGroup mechanisms in `killSandbox` in the
local build. In the build hook case, these variables will not be set, so
there is nothing to do.
2025-03-12 18:09:38 -04:00
Las
db8439c328 Remove signRealisation from drv goal
We can move this method from `LocalStore` to `Store` --- even if we only
want the actual builder to sign things in many cases, there is no reason
to try to enforce this policy by spurious moving the method to a
subclass.

Now, we might technically sign class, but CA derivations is
experimental, and @Ericson2314 is going to revisit all this stuff with
issue #11896 anyways.
2025-03-12 18:09:38 -04:00
Las
0e7e1f5b57 Remove registerOutputs from drv goal
Easy to inline in one spot, and assert in the other.
2025-03-12 18:09:38 -04:00
Las
a87589a035 Simplify local drv goal a bit more
- `chrootParentDir` can be a local variable instead of a class variable.

- `getChildStatus` can be inlined. Again, we have the `assert(!hook);`
  in the local building case, which makes for a simpler thing inlined.
2025-03-12 18:09:38 -04:00
Las
4b521f14ac Remove privateNetwork variable from local drv goal
Can just inline its definition, it was immutable.
2025-03-12 18:09:38 -04:00
John Ericson
87824bca6b Avoid pointless mutation
The code that was in between is now gone. We can just set `st` correctly
the first time.
2025-03-12 18:08:58 -04:00
John Ericson
145aa2f118 Remove dead hook code in LocalDerivationGoal::tryLocalBuild
The `assert` above proves that `hook` is not set.
2025-03-12 18:08:10 -04:00
Las
75feeecd5d Start simplifying {Local,}DerivationGoal cleanup code
Thanks to the previous commit, we can inline all these small callbacks.
In the build-hook case, they were empty, and now they disappear
entirely.

While `LocalDerivationGoal` can be used in the hook case (we use it
based on whether we have a local store, not based on whether we are
using the build hook, a decision which comes later), the previous
commit's inline moved the code into a spot where we know we are cleaning
up after local building, *not* after running the build hook. This allows
for much more simplification.
2025-03-12 18:05:08 -04:00
Las
e87ba85705 Inline buildDone from DerivationGoal into use sites
The basic idea is that while we have duplicated this function, we now
have one call-site in the local build case, and one call site in the
build hook case. This unlocks big opportunities to specialize each copy,
since they really shouldn't be doing the same things. By the time we are
are done, there should not be much duplication left.

See #12628 for further info.
2025-03-12 18:00:07 -04:00
John Ericson
1de97bbe2e Factor out "last 10 log lines" error message code
This will help avoid duplication later. In particular, the next commit
will not need to duplicate as much.
2025-03-12 18:00:07 -04:00
Jörg Thalheim
e9f1761597 libfetchers/git: fix caching head when using shallow clones
the old code was using the wrong cache directory, which lead to a
warning on every nix flake update

Update src/libfetchers/git.cc
2025-03-12 22:32:05 +01:00