1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 14:21:48 +02:00
Commit graph

20318 commits

Author SHA1 Message Date
Robert Hensing
c79b8018c0
Merge pull request #13407 from xokdvium/smaller-value
libexpr: Reduce the size of Value down to 16 bytes (on 64 bit systems)
2025-07-03 00:12:47 +02:00
Sergei Zimmerman
5a20a48f13
libexpr: Reduce the size of Value down to 16 bytes
This shaves off a very significand amount of memory used
for evaluation as well as reduces the GC-managed heap.

Previously the union discriminator (InternalType) was
stored as a separate field in the Value, which takes up
whole 8 bytes due to padding needed for member alignment.
This effectively wasted 7 whole bytes of memory. Instead
of doing that InternalType is instead packed into pointer
alignment niches. As it turns out, there's more than enough
unused bits there for the bit packing to be effective.

See the doxygen comment in the ValueStorage specialization
for more details.

This does not add any performance overhead, even though
we now consistently assert the InternalType in all getters.

This can also be made atomic with a double width compare-and-swap
instruction on x86_64 (CMPXCHG16B instruction) for parallel evaluation.
2025-07-02 22:27:37 +03:00
Sergei Zimmerman
e73fcf7b53
libexpr: Use proxy ListView for all Value list accesses
This also makes it possible to make `payload` field private
in the `ValueStorage` class template.
2025-07-02 21:57:02 +03:00
Sergei Zimmerman
c39cc00404
libexpr: Factor out Payload union to a default implementation of ValueStorage
This factors out most of the value representation into a mixin class.
`finishValue` is now gone for good and replaced with a simple template
function `setStorage` which derives the type information/disriminator from
the type of the argument. Likewise, reading of the value goes through function
template `getStorage`.

An empty type `Null` is introduced to make the bijection InternalType <-> C++ type
complete.
2025-07-02 21:51:15 +03:00
Sergei Zimmerman
810455f1b8
libexpr: Simplify Value::is* methods by introducing isa function template 2025-07-02 21:51:12 +03:00
Sergei Zimmerman
1a033ee4ee
libexpr: Use single tSmallList Value discriminator for small lists 2025-07-02 21:51:09 +03:00
Sergei Zimmerman
ea32580c9b
libexpr: Format value.hh
The following commits will touch this file significantly, so
it's better to get the formatting out of the way first.
2025-07-02 21:51:07 +03:00
Robert Hensing
04a731b4b9
Merge pull request #13387 from NaN-git/opt-listToAttrs
libexpr: don't allocate additional set in `builtins.listToAttrs`
2025-07-02 11:55:39 +02:00
Robert Hensing
4bf23d242d
Merge pull request #13416 from xokdvium/pragma-once-missing
libfetchers: Add missing include guard to git-lfs-fetch.hh
2025-07-02 11:52:03 +02:00
Sergei Zimmerman
d16af1d099
libfetchers: Add missing include guard to git-lfs-fetch.hh
This is a publicly installed header without a header guard.
Doesn't seem right.
2025-07-02 00:57:35 +03:00
Eelco Dolstra
5879ab1577
Merge pull request #13400 from NixOS/fix-deep-overrides
Fix deep flake input overrides
2025-07-01 19:34:55 +02:00
Eelco Dolstra
4458a9061b
Merge pull request #13406 from xokdvium/libflake-dead-code
libflake: Remove unused maybeParseFlakeRef and maybeParseFlakeRefWith…
2025-07-01 17:03:00 +02:00
Eelco Dolstra
9600eaef2e
Merge pull request #13412 from xokdvium/read-directory-caching
libutil: Use caching `directory_entry` API in `PosixSourceAccessor::r…
2025-07-01 16:59:40 +02:00
Sergei Zimmerman
8708e9a526
libutil: Use caching directory_entry API in PosixSourceAccessor::readDirectory
Previous use of symlink_status() always translated into a stat call, leading
to huge performance penalties for by-name-overlay in nixpkgs. The comment
below references the possible caching, but that seemed to be erroneous, since
the correct way to make use of the caching API is by calling a bunch of `is_*`
functions [1]. For example, here's how libstdc++ does that [2], [3].

This translates to great nixpkgs eval performance improvements:

```
Benchmark 1: GC_INITIAL_HEAP_SIZE=4G result/bin/nix-instantiate ../nixpkgs -A hello --readonly-mode
  Time (mean ± σ):     186.7 ms ±   6.7 ms    [User: 121.3 ms, System: 64.9 ms]
  Range (min … max):   179.4 ms … 201.6 ms    16 runs

Benchmark 2: GC_INITIAL_HEAP_SIZE=4G nix-instantiate ../nixpkgs -A hello --readonly-mode
  Time (mean ± σ):     230.6 ms ±   5.0 ms    [User: 126.9 ms, System: 103.1 ms]
  Range (min … max):   225.1 ms … 241.4 ms    13 runs
```

[1]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0317r1.html
[2]: 8ea555b7b4/libstdc%2B%2B-v3/include/bits/fs_dir.h (L341-L348)
[3]: 8ea555b7b4/libstdc%2B%2B-v3/include/bits/fs_dir.h (L161-L163)
2025-06-30 23:29:07 +03:00
Philipp Otterbein
fa3d7e6f68 libexpr: don't allocate additional set in builtins.listToAttrs 2025-06-29 01:41:16 +02:00
Sergei Zimmerman
75412ebc30
libflake: Remove unused maybeParseFlakeRef and maybeParseFlakeRefWithFragment
These wrappers don't seem to be used anywhere in and out of tree.
Also the declaration in the header has an incorrect function name `maybeParseFlake`.

Closes #11948
2025-06-27 23:33:54 +03:00
Sergei Zimmerman
acfdacc971
Merge pull request #13401 from NixOS/split-flake-command
Move FlakeCommand into a header, allow separate registration of subcommands
2025-06-26 19:02:59 +03:00
Eelco Dolstra
eaced1e0d2 Move FlakeCommand into a header, allow separate registration of subcommands
This allows us to start splitting up src/nix/flake.cc.
2025-06-26 17:14:32 +02:00
Eelco Dolstra
b415faceca Don't allow flake inputs to have both a flakeref and a follows
Having both doesn't make sense so it's best to disallow it. If this
causes issues we could turn into a warning.
2025-06-26 12:56:54 +02:00
Eelco Dolstra
637c4f3ad7 Add tests for deep overrides
Taken from https://github.com/NixOS/nix/pull/6621.

Co-authored-by: Sebastian Ullrich <sebasti@nullri.ch>
2025-06-26 12:56:49 +02:00
Eelco Dolstra
7c0ea143d8 Fix deep overrides
An override like

  inputs.foo.inputs.bar.inputs.nixpkgs.follows = "nixpkgs";

implicitly set `inputs.foo.inputs.bar` to `flake:bar`, which led to an
unexpected error like

  error: cannot find flake 'flake:bar' in the flake registries

We now no longer create a parent override (like for `foo.bar` in the
example above) if it doesn't set an explicit ref or follows
attribute. We only recursively apply its child overrides.

Fixes https://github.com/NixOS/nix/issues/8325, https://github.com/DeterminateSystems/nix-src/issues/95, https://github.com/NixOS/nix/issues/12083, https://github.com/NixOS/nix/issues/5790.
2025-06-26 12:56:39 +02:00
Robert Hensing
df2d5f276a
Merge pull request #13395 from xokdvium/libstore-tests-leaks
libstore-tests: Don't leak memory in tests
2025-06-25 22:41:00 +02:00
Sergei Zimmerman
55d12dfc5d
libstore-tests: Don't leak memory in tests
We shouldn't leak memory in unit tests in order
to make enabling ASAN easier.
2025-06-25 00:07:58 +03:00
Eelco Dolstra
448cfb71ea Merge remote-tracking branch 'cve/fod-cves-master' 2025-06-24 16:02:58 +02:00
Robert Hensing
f9afc1e68c
Merge pull request #13393 from egorkonovalov/patch-1
Fix typo: remove an extra word
2025-06-23 16:07:14 +02:00
Egor Konovalov
df21f24987
Fix link
Remove extra `realise`
2025-06-23 11:26:59 +02:00
Robert Hensing
6a74590063
Merge pull request #13388 from NaN-git/opt-string_view
libexpr: further removal of `std::string` copies
2025-06-23 09:05:28 +02:00
Eelco Dolstra
37685b1c9c Fix Darwin test failure in repl.sh
Fixes

  error:
         … while processing sandbox path '/private/tmp/nix-shell.0MDgyx/nix-test/ca/repl/store/nix/var/nix/builds/nix-build-simple.drv-65916-3910734210' (/private/tmp/nix-shell.0MDgyx/nix-test/ca/repl/store)

         error: 'nix' is too short to be a valid store path

which happened because we were now putting the build directory
underneath the store directory.
2025-06-22 16:49:44 +02:00
Eelco Dolstra
2e2fe4cb07 Cleanup 2025-06-22 16:49:44 +02:00
Eelco Dolstra
5acf50a327 Disallow the build directory having world-writable parents 2025-06-22 16:49:44 +02:00
eldritch horrors
88b7db1ba4 libstore: Don't default build-dir to temp-dir, store setting
If a build directory is accessible to other users it is possible to
smuggle data in and out of build directories. Usually this is only
a build purity problem, but in combination with other issues it can
be used to break out of a build sandbox. to prevent this we default
to using a subdirectory of nixStateDir (which is more restrictive).

(cherry picked from pennae Lix commit 55b416f6897fb0d8a9315a530a9b7f0914458ded)
(store setting done by roberth)
2025-06-22 16:49:44 +02:00
Eelco Dolstra
9af4c267c6 Chown structured attr files safely 2025-06-22 16:48:34 +02:00
Eelco Dolstra
a4b5584fb1 Replace 'bool sync' with an enum for clarity
And drop writeFileAndSync().
2025-06-22 16:48:34 +02:00
Eelco Dolstra
479c356510 Drop guessOrInventPathFromFD()
No need to do hacky stuff like that when we already know the original path.
2025-06-22 16:48:34 +02:00
Eelco Dolstra
e5dc3e84f0 Tweak comment 2025-06-22 16:48:34 +02:00
Raito Bezarius
4ea4813753 libstore: ensure that temporary directory is always 0o000 before deletion
In the case the deletion fails, we should ensure that the temporary
directory cannot be used for nefarious purposes.

Change-Id: I498a2dd0999a74195d13642f44a5de1e69d46120
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
Raito Bezarius
5ec047f348 libutil: ensure that _deletePath does NOT use absolute paths with dirfds
When calling `_deletePath` with a parent file descriptor, `openat` is
made effective by using relative paths to the directory file descriptor.

To avoid the problem, the signature is changed to resist misuse with an
assert in the prologue of the function.

Change-Id: I6b3fc766bad2afe54dc27d47d1df3873e188de96
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
Raito Bezarius
4e59d3fdb2 libstore: ensure that passAsFile is created in the original temp dir
This ensures that `passAsFile` data is created inside the expected
temporary build directory by `openat()` from the parent directory file
descriptor.

This avoids a TOCTOU which is part of the attack chain of CVE-????.

Change-Id: Ie5273446c4a19403088d0389ae8e3f473af8879a
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
Raito Bezarius
034f59bbb9 libutil: writeFile variant for file descriptors
`writeFile` lose its `sync` boolean flag to make things simpler.

A new `writeFileAndSync` function is created and all call sites are
converted to it.

Change-Id: Ib871a5283a9c047db1e4fe48a241506e4aab9192
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
Raito Bezarius
002d202653 libstore: chown to builder variant for file descriptors
We use it immediately for the build temporary directory.

Change-Id: I180193c63a2b98721f5fb8e542c4e39c099bb947
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
Raito Bezarius
6a5b6ad3b7 libstore: open build directory as a dirfd as well
We now keep around a proper AutoCloseFD around the temporary directory
which we plan to use for openat operations and avoiding the build
directory being swapped out while we are doing something else.

Change-Id: I18d387b0f123ebf2d20c6405cd47ebadc5505f2a
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
Raito Bezarius
7226a116a0 libutil: guess or invent a path from file descriptors
This is useful for certain error recovery paths (no pun intended) that
does not thread through the original path name.

Change-Id: I2d800740cb4f9912e64c923120d3f977c58ccb7e
Signed-off-by: Raito Bezarius <raito@lix.systems>
2025-06-22 16:48:33 +02:00
John Ericson
b9b510d692
Merge pull request #13383 from xokdvium/meson-format-multiline
Restore multiline formatting of lists in meson files
2025-06-20 18:19:03 -04:00
Sergei Zimmerman
a4dcce36c9
Merge pull request #13382 from synalice/patch-3
Update docs
2025-06-20 23:18:11 +03:00
Sergei Zimmerman
6ef683cb2a
Restore multiline formatting of lists in meson files
Applies a workaround to enforce multiline formatting
of lists to reduce code churn introduced in 93a42a5971.
2025-06-20 23:12:36 +03:00
Nikita Krasnov
785f3867fd
Update docs 2025-06-20 21:19:13 +03:00
Robert Hensing
42ea2724a8
Merge pull request #13353 from lucperkins/messages-present-tense
Rework future tense in user-facing messages
2025-06-20 10:43:03 +02:00
Luc Perkins
3132aba8e4
Fix broken test 2025-06-19 15:23:10 -07:00
Luc Perkins
9c120596ec
Merge remote-tracking branch 'upstream/master' into messages-present-tense 2025-06-19 10:51:50 -07:00
Jörg Thalheim
aa1629ca35
Merge pull request #13378 from NixOS/improve-rosetta-hint
Improve the Rosetta installation hint
2025-06-19 16:38:10 +02:00