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

13074 commits

Author SHA1 Message Date
Jörg Thalheim
4a7285c649
Merge pull request #13688 from xokdvium/odr-toplevel-types
treewide: Move private types and code into anonymous namespaces
2025-08-05 14:05:16 +02:00
Sergei Zimmerman
e3d7f20afe libstore: Remove dead variable 2025-08-05 14:03:38 +02:00
Sergei Zimmerman
866d5e6cf4
treewide: Sprinkle more anonymous namespace for classes private to TUs
This code should be private to the corresponding translation units.
2025-08-05 02:25:40 +03:00
Sergei Zimmerman
0118e5ea5d
libutil: Move Ctx type from the nix namespace to Hash class
Same as previous commit. This really should not be a part of
the `nix` namespace. Otherwise the doxygen documentation is
really confusing.
2025-08-05 02:20:28 +03:00
Sergei Zimmerman
5ee0d5669e
libstore: Move State to an anonymous namespace
Having a State class in the nix namespace is asking
for ODR trouble. This class is already private to the
translation unit, let's move it into an anonymous namespace.
2025-08-05 02:15:21 +03:00
Sergei Zimmerman
aea312dae3
nix-cli: Move nix2 binaries sources properly into nix subproject
There have been prior concerns about reogranizing the repo, but
this seems like a trivial simplification which will not interfere
with either our packaging or the modular builds in nixpkgs.
2025-08-05 02:10:21 +03:00
John Ericson
23c87d8a21 Encapsulate invalidBase32, avoid 0xFF magic number
This keeps things fast by making the function inline, but also prevents
people from having to know about the `0xFF` implementation detail
directly, instead making one go through a `std::optional` (which could be
fused away with a sufficiently smart compiler).

Additionally, the base "nix32" implementation is moved to its own header
file pair, as it is logically distinct and prior to the `Hash` data
type. It would probably be nice to do this with all the hash format
implementations.
2025-08-04 15:32:38 -04:00
John Ericson
6ab8cbe31a
Merge pull request #13680 from avnik/avnik/fast-base32
Improve base-32 hash decoding performance with reverse map
2025-08-04 14:22:59 -04:00
Jörg Thalheim
c7af923865
Merge pull request #13445 from xokdvium/simplify-util-url
libutil: Use Boost.URL for URI parsing
2025-08-04 19:46:58 +02:00
WxNzEMof
0a96b7e627 Recognize "identity" compression method
Some binary caches (incorrectly) use this header to indicate lack of
compression, inspired by the valid "identity" token in the
"Accept-Encoding" header.
2025-08-04 17:00:38 +00:00
Sergei Zimmerman
20df0e5fa7
libstore-tests: Add reference scanning benchmark
This benchmark should provide a relatively realistic
scenario for reference scanning.

As shown by the following results, reference scanning code
is already plenty fast and is definitely not a bottleneck:

```
BM_RefScanSinkRandom/10000               1672 ns         1682 ns       413354 bytes_per_second=5.53691Gi/s
BM_RefScanSinkRandom/100000             11217 ns        11124 ns        64341 bytes_per_second=8.37231Gi/s
BM_RefScanSinkRandom/1000000           205745 ns       204421 ns         3360 bytes_per_second=4.55591Gi/s
BM_RefScanSinkRandom/5000000          1208407 ns      1201046 ns          597 bytes_per_second=3.87713Gi/s
BM_RefScanSinkRandom/10000000         2534397 ns      2523344 ns          273 bytes_per_second=3.69083Gi/s
```

(Measurements on Ryzen 5900X via `nix build --file ci/gha/tests componentTests.nix-store-tests-run -L`)
2025-08-04 02:11:14 +03:00
Alexander V. Nikolaev
4bfc007a7b
Improve base-32 hash decoding performance with reverse map
The changes include:

* Defining nix32Chars as a constexpr char[].
* Adding a constexpr std::array<unsigned char, 256> (reverseNix32Map) to map characters to their base-32 digit values at compile time.
* Replacing the slow character search loop with a direct lookup using reverseNix32Map.
* Removing std::once_flag/isBase32 logic in references.cc in favor of reverseNix32Map

Signed-off-by: Alexander V. Nikolaev <avn@avnik.info>
2025-08-03 19:00:56 +03:00
John Ericson
51a32e4645
Merge pull request #13679 from xokdvium/build-benchmarks-in-ci
libstore-tests: Build benchmarks in GHA CI
2025-08-02 19:44:04 -04:00
Sergei Zimmerman
ea1f67393d
libstore-tests: Build and run benchmarks in CI
This changes our GHA CI and nix-store-tests packaging
to build and run the benchmarks. This does not affect
the default packaging - the overrides apply only for the
GHA CI.
2025-08-03 01:09:04 +03:00
Sergei Zimmerman
b2b2f2dc53
libstore-tests: Split bench-main into a separate file
This makes it easier to add new benchmarks.
2025-08-03 01:03:40 +03:00
Sergei Zimmerman
b8301b2c25
libstore-tests: Add nix-store-benchmarks as a meson benchmark 2025-08-03 01:03:37 +03:00
Sergei Zimmerman
5db50e3f77
meson: Disable PCH for GCC
GCC doesn't really benefit as much as Clang does from
using precompiled headers. Another aspect to consider is that
clangd doesn't really like GCC's PCH flags in the compilation database,
so GCC based devshells would continue to work with clangd.

This also has the slight advantage of ensuring that our includes are in
order, since we build with both Clang and GCC.
2025-08-03 00:08:40 +03:00
John Ericson
8652b6b417 Store StructuredAttrs directly in Derivation
Instead of parsing a structured attrs at some later point, we parsed it
right away when parsing the A-Term format, and likewise serialize it to
`__json = <JSON dump>` when serializing a derivation to A-Term.

The JSON format can directly contain the JSON structured attrs without
so encoding it, so we just do that.
2025-07-29 17:28:16 -04:00
John Ericson
b062730665
Merge pull request #13569 from Mic92/benchmark
add derivation parser benchmark
2025-07-29 14:41:10 -04:00
Jörg Thalheim
1989dd7bf9 add derivation parser benchmark
the current identified bottlenecks are parseString in derivations.cc and dirOf (because of std::filessystem creation).
2025-07-29 16:51:55 +02:00
Oleksandr Knyshuk
6d46dc9f6a
Add warn-short-path-literals setting
Add a new setting to warn about path literals that don't start with "." or "/". When enabled,
expressions like `foo/bar` will emit a warning suggesting to use `./foo/bar` instead.

A functional test is included.

The setting defaults to false for backward compatibility but could eventually default to true in
the future.

Closes: #13374

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2025-07-29 15:47:58 +02:00
Eelco Dolstra
5fe6c53703 nix flake prefetch-inputs: Add
This command fetches all inputs of a flake in parallel.

Example runtime for

  $ chmod -R u+w /tmp/nix2; rm -rf /tmp/nix2; rm ~/.cache/nix/fetcher-cache-v3.sqlite*; rm -rf ~/.cache/nix/tarball-cache/ ~/.cache/nix/gitv3/; time nix flake prefetch-inputs --store /tmp/nix2 https://api.flakehub.com/f/pinned/informalsystems/cosmos.nix/0.3.0/018ce9ed-d0be-7ce5-81b6-a3c6e3ae1187/source.tar.gz

with http-connections = 1:

real    4m11.859s
user    2m6.931s
sys     0m25.619s

and http-connections = 25 (the default):

real    0m57.146s
user    2m49.506s
sys     0m36.008s
2025-07-28 18:53:49 +02:00
John Ericson
d21e3f88ec Implement support for Git hashing with SHA-256
SHA-256 is Git's next hash algorithm. The world is still basically stuck
on SHA-1 with git, but shouldn't be. We can at least do our part to get
ready.

On the C++ implementation side, only a little bit of generalization was
needed, and that was fairly straight-forward. The tests (unit and
system) were actually bigger, and care was taken to make sure they were
all cover both algorithms equally.
2025-07-25 10:19:08 -04:00
Robert Hensing
49f411c08c Update developer facing links to nix.dev
Not broken, but it's a tiny bit quicker
2025-07-25 10:59:44 +02:00
Robert Hensing
b7782809cb docs, messages: Resolve nixos.org/manual/nix/stable redirect
Loads a bit quicker
2025-07-25 10:18:13 +02:00
Robert Hensing
35835e0644 Fix documentation link
The file was renamed. We've also moved to nix.dev, but that was
redirected properly.
Closes #13488
2025-07-25 10:18:11 +02:00
Eelco Dolstra
cbdb497c79
Merge pull request #13478 from NixOS/posix-source-accessor-concurrent-map
PosixSourceAccessor: Use concurrent_flat_map
2025-07-24 11:19:37 +02:00
Robert Hensing
eed1d370d0
Merge pull request #13521 from fzakaria/fzakaria/issue-11266
Unpeel reference for git+file
2025-07-23 22:36:44 +02:00
Eelco Dolstra
3a67cafa0d Merge branch 'master' (reformat) 2025-07-23 21:22:27 +02:00
Eelco Dolstra
72e8f7cd35 Merge branch 'master' (pre-reformat) 2025-07-23 21:22:19 +02:00
Jens Petersen
ff6ab3b213
meson: libfetchers needs libgit2 1.9+
libfetchers uses `git_mempack_write_thin_pack` which was introduced in libgit2-1.9.0

This avoids error like:

../src/libfetchers/git-utils.cc: In member function ‘virtual void nix::GitRepoImpl::flush()’:
../src/libfetchers/git-utils.cc:270:13: error: ‘git_mempack_write_thin_pack’ was not declared in this scope
  270 |             git_mempack_write_thin_pack(mempack_backend, packBuilder.get())
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~

on older libgit2 (like 1.7.2 in Centos Stream 10)
2025-07-22 22:58:55 +08:00
Farid Zakaria
98858148dc Add unit test 2025-07-21 21:56:11 -07:00
Farid Zakaria
33ceea6099 Unpeel reference for git+file
If the reference for git+file is an annotated tag, the revision will
differ than when it's fetched using other fetchers such as `github:`
since Github seems to automatiacally peel to the underlying commit.

Turns out that rev-parse has the capability through it's syntax to
request the underlying commit by "peeling" using the `^{commit}` syntax.

This is safe to apply in all scenarios where the goal is to get an
underlying commit.

fixes #11266
2025-07-21 21:10:41 -07:00
Sergei Zimmerman
e2b0ff18f8
Merge pull request #13514 from OPNA2608/fix/meson-powerpc-cpu-names
treewide: Fix Meson CPU names for powerpc CPUs
2025-07-22 01:48:22 +03:00
OPNA2608
6db6190002 treewide: Fix Meson CPU names for powerpc CPUs 2025-07-21 19:03:49 +02:00
Sergei Zimmerman
9dae9f6cab
nix-cli: Speed up builds by using precompiled headers 2025-07-20 22:02:01 +03:00
Sergei Zimmerman
46469983e7
libcmd: Speed up builds by using precompiled headers 2025-07-20 22:01:59 +03:00
Sergei Zimmerman
af6c84b523
libexpr: Speed up builds by using precompiled headers 2025-07-20 22:01:56 +03:00
Sergei Zimmerman
33d031095f
libstore: Speed up builds by using precompiled headers 2025-07-20 22:01:53 +03:00
Sergei Zimmerman
e920e28734
libutil: Speed up builds by using precompiled headers 2025-07-20 22:01:51 +03:00
Sergei Zimmerman
bd1d2d1041
libutil: Use Boost.URL in parseURL
Boost.URL is a significantly more RFC-compliant parser
than what libutil currently has a bundle of incomprehensible
regexes.

One aspect of this change is that RFC4007 ZoneId IPv6 literals
are represented in URIs according to RFC6874 [1].

Previously they were represented naively like so: [fe80::818c:da4d:8975:415c\%enp0s25].
This is not entirely correct, because the percent itself has to be pct-encoded:

> "%" is always treated as
   an escape character in a URI, so, according to the established URI
   syntax [RFC3986] any occurrences of literal "%" symbols in a URI MUST
   be percent-encoded and represented in the form "%25".  Thus, the
   scoped address fe80::a%en1 would appear in a URI as
   http://[fe80::a%25en1].

[1]: https://datatracker.ietf.org/doc/html/rfc6874

Co-authored-by: Jörg Thalheim <joerg@thalheim.io>
2025-07-18 21:24:01 +03:00
Sergei Zimmerman
d020f21a2a
libutil: Use default operator== for ParsedURL
The default comparison operator can be generated
by the compiler since C++20.
2025-07-18 21:23:42 +03:00
Sergei Zimmerman
ad449c0288
libutil: Refactor percentDecode,percentEncode to use Boost.URL
The myriad of hand-rolled URL parsing and validation code
is a constant source of problems. Regexes are not a great way
of writing parsers and there's a history of getting them wrong.
Boost.URL is a good library we can outsource most of the heavy
lifting to.
2025-07-18 21:23:40 +03:00
Sergei Zimmerman
d9053390ce
libutil-test-support: Add HasSubstrIgnoreANSIMatcher
This matcher is useful for checking error messages, which
always contain ANSI escapes.
2025-07-18 21:23:38 +03:00
Sergei Zimmerman
ffc9bfb66d
lib{store,flake}-tests: Add test for spaces in URIs
These cases do not seem to be covered by the test suite at all.
2025-07-18 21:23:35 +03:00
Graham Christensen
e4f62e4608 Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter,
* It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files
* Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose,

Let's rip the bandaid off?

Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
2025-07-18 12:47:27 -04:00
Jörg Thalheim
599c1d78ed
Merge pull request #13496 from k1gen/fix-help-shell-command
Fix `nix help shell` by properly handling command aliases
2025-07-17 19:40:47 +02:00
Jörg Thalheim
4c95086879
Merge pull request #13493 from Mic92/clang-tidy-virtual-methods
Fix virtual method calls during construction
2025-07-17 17:41:18 +02:00
Oleksandr Knyshuk
d678b071d6
Make nix help shell work by handling aliases properly
Previously, `nix help shell` failed with "Nix has no subcommand 'shell'" despite `nix shell --help`
working correctly. This happened because the `shell` command is actually an alias for `env shell`,
and the help system wasn't resolving aliases when looking up documentation.

This patch modifies the `showHelp` function to check for and resolve aliases before generating the
manpage name, ensuring that shorthand commands like `shell` get proper help documentation.

Closes: #13431
2025-07-17 17:26:56 +02:00
Jörg Thalheim
3c0cd73418 Fix uninitialized field in Attr constructor
The default constructor for Attr was not initializing the value pointer,
which could lead to undefined behavior when the uninitialized pointer is
accessed. This was caught by clang-tidy's UninitializedObject check.

This fixes the warning:
  1 uninitialized field at the end of the constructor call
  [clang-analyzer-optin.cplusplus.UninitializedObject]
2025-07-17 17:12:20 +02:00