1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 00:11:17 +02:00
Commit graph

12190 commits

Author SHA1 Message Date
John Ericson
49f486d8e0 MonitorFdHup: Don't sleep anymore
After the previous commit it should not be necessary. Furthermore, if we
*do* sleep, we'll exacerbate a race condition (in conjunction with
getting rid of the thread cancellation) that will cause test failures.
2025-03-23 19:15:27 -04:00
Jade Lovelace
9b3352c3c8 daemon: remove workaround for macOS kernel bug that seems fixed
This was filed as https://github.com/nixos/nix/issues/7584, but as far
as I can tell, the previous solution of POLLHUP works just fine on macOS
14. I've also tested on an ancient machine with macOS 10.15.7, which
also has POLLHUP work correctly.

It's possible this might regress some older versions of macOS that have
a kernel bug, but I went looking through the history on the sources and
didn't find anything that looked terribly convincingly like a bug fix
between 2020 and today. If such a broken version exists, it seems pretty
reasonable to suggest simply updating the OS.

Change-Id: I178a038baa000f927ea2cbc4587d69d8ab786843

Based off of commit 69e2ee5b25752ba5fd8644cef56fb9d627ca4a64. Ericson2314 added
additional other information.
2025-03-23 19:05:45 -04:00
Félix Baylac Jacqué
1c636284a3 MonitorFdHup: replace pthread_cancel trick with a notification pipe
On https://github.com/NixOS/nix/issues/8946, we faced a surprising
behaviour wrt. exception when using pthread_cancel. In a nutshell when
a thread is inside a catch block and it's getting pthread_cancel by
another one, then the original exception is bubbled up and crashes the
process.

We now poll on the notification pipe from the thread and exit when the
main thread closes its end. This solution does not exhibit surprising
behaviour wrt. exceptions.

Co-authored-by: Mic92 <joerg@thalheim.io>

Fixes https://github.com/NixOS/nix/issues/8946

See also Lix https://gerrit.lix.systems/c/lix/+/1605 which is very
similar by coincidence. Pulled a comment from that.
2025-03-23 18:34:52 -04:00
John Ericson
cb95791198 MonitorFdHup: introduce a num_fds variable
Better than just putting `1` in multiple spots.
2025-03-23 18:23:07 -04:00
John Ericson
d028bb4c4a MonitorFdHup: Cleanup a bit with designated initializers 2025-03-23 18:23:07 -04:00
Jörg Thalheim
8e0bc2c3a8 MonitorFdHup: raise explicit SysError rather unreachable
Syscalls can fail for many reasons and we don't want to loose the errno
and error context.
2025-03-23 18:22:48 -04:00
Sergei Zimmerman
44055dc09d
libcmd/repl: Fix missing runNix in repl
Without this :u, :sh and :i repl commands fail with:

> Cannot run 'nix-shell'/`nix-env` because no method of calling the Nix
> CLI was provided. This is a configuration problem pertaining to how
> this program was built.

Remove the default ctor argument as it evidently makes catching
refactoring bugs much harder. `NixRepl` implementation lives completely
in `repl.cc`, so we can be as explicit as necessary.
2025-03-23 22:13:14 +00:00
Sergei Zimmerman
8066e4b0c3
libcmd/repl: Make AbstractNixRepl::create respect its store argument
The only reference (according to clangd) to this function also uses `openStore`,
so this is a no-op.
2025-03-23 22:10:43 +00:00
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