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

43 commits

Author SHA1 Message Date
Sergei Zimmerman
b2596a7615
libutil: Add custom PeekSort implementation
Unlike std::sort and std::stable_sort, this implementation
does not lead to out-of-bounds memory reads or other undefined
behavior when the predicate is not strict weak ordering.

This makes it possible to use this function in libexpr for
builtins.sort, where an incorrectly implemented comparator
in the user nix code currently can crash and burn the evaluator
by invoking C++ UB.
2025-06-15 16:52:01 +00:00
Sergei Zimmerman
114de63d88
Fix various typos in source code
This only touches code comments, class names, documentation,
enumeration names and tests.
2025-05-25 20:14:11 +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
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
7ccc0d591f add DirectoryIterator to re-throw std::filesystem::filesystem_error
Co-authored-by: Sergei Zimmerman <145775305+xokdvium@users.noreply.github.com>
2025-05-01 11:54:13 +02:00
mergify[bot]
4548dd1abb
Merge pull request #13112 from NaN-git/fix-json-getInteger
bugfix in getInteger(const nlohmann::json &) and add bounds checks
2025-04-30 21:20:49 +00:00
Philipp Otterbein
788be3f964 bugfix in getInteger(const nlohmann::json &) and add bounds checks
improve error messages, too
2025-04-30 01:38:48 +02:00
Sergei Trofimovich
e322b714dc libutil: amend OSC 8 escape stripping for xterm-style separator
Before the change `nix` was stripping warning flags
reported by `gcc-14` too eagerly:

    $ nix build -f. texinfo4
    error: builder for '/nix/store/i9948l91s3df44ip5jlpp6imbrcs646x-texinfo-4.13a.drv' failed with exit code 2;
           last 25 log lines:
           >  1495 | info_tag (mbi_iterator_t iter, int handle, size_t *plen)
           >       |                                            ~~~~~~~~^~~~
           > window.c:1887:39: error: passing argument 4 of 'printed_representation' from incompatible pointer type []
           >  1887 |                                       &replen);
           >       |                                       ^~~~~~~
           >       |                                       |
           >       |                                       int *

After the change the compiler flag remains:

    $ ~/patched.nix build -f. texinfo4
    error: builder for '/nix/store/i9948l91s3df44ip5jlpp6imbrcs646x-texinfo-4.13a.drv' failed with exit code 2;
       last 25 log lines:
       >  1495 | info_tag (mbi_iterator_t iter, int handle, size_t *plen)
       >       |                                            ~~~~~~~~^~~~
       > window.c:1887:39: error: passing argument 4 of 'printed_representation' from incompatible pointer type [-Wincompatible-pointer-types]
       >  1887 |                                       &replen);
       >       |                                       ^~~~~~~
       >       |                                       |
       >       |                                       int *

Note the difference in flag rendering around the warning.

https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda has a
good sumamry of why it happens. Befomre the change `nix` was handling
just one form or URL separator:

    $ printf '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n'

Now it also handled another for (used by gcc-14`):

    printf '\e]8;;http://example.com\aThis is a link\e]8;;\a\n'

While at it fixed accumulation of trailing escape `\e\\` symbol.
2025-04-29 16:12:18 +01:00
Sergei Zimmerman
9fff868e39
libutil: Add missing format arguments to UsageError ctor
Once again found by an automated migration to `std::format`.
I've tested that boost::format works fine with `std::string_view`
arguments.
2025-04-25 13:35:16 +03:00
Eelco Dolstra
a9b6213221 Don't build MonitorFdHup on Windows
https://hydra.nixos.org/build/295398462
2025-04-23 19:51:13 +02:00
Eelco Dolstra
340fa00d52 Fix/run monitorfdhup test 2025-04-07 17:09:42 +02:00
Jörg Thalheim
681d7f7e57 Fix -Wsign-compare errors 2025-04-03 09:48:53 +02:00
Eelco Dolstra
0f723769b7 Fix -Wdangling-reference 2025-04-02 20:51:45 +00:00
John Ericson
cc24766fa6 Expose the nix component in header include paths
For example, instead of doing

    #include "nix/store-config.hh"
    #include "nix/derived-path.hh"

Now do

    #include "nix/store/config.hh"
    #include "nix/store/derived-path.hh"

This was originally planned in the issue, and also recent requested by
Eelco.

Most of the change is purely mechanical. There is just one small
additional issue. See how, in the example above, we took this
opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`.
Well, there was already a `nix/util/config.{cc,hh}`. Even though there
is not a public configuration header for libutil (which also would be
called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any
such confusion, we renamed that to `nix/util/configuration.{cc,hh}`.

Finally, note that the libflake headers already did this, so we didn't
need to do anything to them. We wouldn't want to mistakenly get
`nix/flake/flake/flake.hh`!

Progress on #7876
2025-04-01 11:40:42 -04:00
John Ericson
c204e307ac Cleanup config headers
There are two big changes:

1. Public and private config is now separated. Configuration variables
   that are only used internally do not go in a header which is
   installed.

   (Additionally, libutil has a unix-specific private config header,
   which should only be used in unix-specific code. This keeps things a
   bit more organized, in a purely private implementation-internal way.)

2. Secondly, there is no more `-include`. There are very few config
   items that need to be publically exposed, so now it is feasible to
   just make the headers that need them just including the (public)
   configuration header.

And there are also a few more small cleanups on top of those:

- The configuration files have better names.

- The few CPP variables that remain exposed in the public headers are
  now also renamed to always start with `NIX_`. This ensures they should
  not conflict with variables defined elsewhere.

- We now always use `#if` and not `#ifdef`/`#ifndef` for our
  configuration variables, which helps avoid bugs by requiring that
  variables must be defined in all cases.
2025-03-31 23:28:36 -04:00
John Ericson
f3e1c47f47 Separate headers from source files
The short answer for why we need to do this is so we can consistently do
`#include "nix/..."`. Without this change, there are ways to still make
that work, but they are hacky, and they have downsides such as making it
harder to make sure headers from the wrong Nix library (e..g.
`libnixexpr` headers in `libnixutil`) aren't being used.

The C API alraedy used `nix_api_*`, so its headers are *not* put in
subdirectories accordingly.

Progress on #7876

We resisted doing this for a while because it would be annoying to not
have the header source file pairs close by / easy to change file
path/name from one to the other. But I am ameliorating that with
symlinks in the next commit.
2025-03-31 12:20:25 -04:00
John Ericson
c36a9b8e1b
Merge pull request #12773 from roberth/config-h-low-hanging-fruit
Unexpose config headers (low hanging fruit only)
2025-03-28 12:43:28 -04:00
Robert Hensing
b86a76044e Unexpose config headers (low hanging fruit only)
- Some headers were completely redundant and have been removed.
- Other headers have been turned private.
- Unnecessary meson.build code has been removed.
- libutil-tests now has a private config header, where previously
  it had none. This removes the need to expose a package version
  macro publicly.
2025-03-28 15:17:54 +00:00
Robert Hensing
f3dbaa3f54 nix-util: Add concatMapStrings 2025-03-25 06:12:19 +00: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
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
Sergei Zimmerman
82f337de10 {libutil,libstore}: Factor out chmodIfNeeded
Using std::filesystem::path directly because we need .c_str()
anyway to interact with chmod. Path/string views don't have to be
null-terminated.
2025-03-05 02:43:11 +03:00
Robert Hensing
3556f6bf4c Write just ./.version on all components
This way it's easier to get right. See previous commit.
2025-02-18 11:41:35 +01:00
silvanshade
1f56ea4c72
Add BLAKE3 hashing algorithm
This uses the single-threaded C-based routines from libblake3.

This is not optimal performance-wise but should be a good starting point
for nix compatibility with BLAKE3 hashing until a more performant
implementation based on the multi-threaded BLAKE3 routines
(written in Rust) can be developed.
2025-02-05 17:49:15 -07:00
Robert Hensing
96e550efc5 Format .nix files
... with nixfmt (rfc style)
2025-01-24 17:04:02 +01:00
Robert Hensing
cab347b4eb refactor: Move ld=gold rule to mesonBuildLayer 2025-01-15 20:01:00 +01:00
Eelco Dolstra
4077aa43a8 ParsedURL: Remove base field 2025-01-07 14:52:00 +01:00
Eelco Dolstra
f705ce7f9a ParsedURL: Remove url field
This prevents a 'url' field that is out of sync with the other
fields. You can use to_string() to get the full URL.
2025-01-07 14:46:03 +01:00
Jörg Thalheim
5a5a86949a makeParentCanonical: test case where parent is empty 2025-01-07 05:42:04 +00:00
Connor Baker
359a0840e2 packaging: use optimization level 3 and LTO by default 2025-01-01 21:59:37 -08:00
Philipp Otterbein
92e30955b9 try to calculate character width 2024-12-28 12:01:32 +01:00
Eli Kogan-Wang
366611391e Implement shellSplitString for proper handling of NIX_SSHOPTS with spaces and quotes 2024-12-14 15:54:16 +00:00
Robert Hensing
d0b4db924a rename: build-utils-meson -> nix-meson-build-support
Fix a footgun. In my case, I had a couple of build ("output")
directories sitting around.

    rm -rf build-*

Was confused for a bit why a meson.build file was missing.

Probably also helps with autocompletion.

I tried meson-build-support first, but I had to add something like
a nix- prefix, in order to make meson happy. They've reserved the
meson- prefix.
2024-12-09 16:54:42 +01:00
Sergei Zimmerman
fafaec5ac3 fix(treewide): remove unnecessary copying in range for loops
This gets rid of unnecessary copies in range-based-for loops and
local variables, when they are used solely as `const &`.

Also added a fixme comment about a suspicious move out of const,
which might not be intended.
2024-11-26 00:06:29 +03:00
Sergei Zimmerman
756758d968 chore: get rid of dead code and unused variables where appropriate
Looks like some cruft has been left over from previous refactorings.
This removes dead variables, which should not have side effects in their
constructors. In cases where the variable initialization has a purpose
[[maybe_unused]] is inserted to silence compiler warnings.
2024-11-22 18:05:53 +03:00
Eelco Dolstra
965ca18db8 Merge build-utils-meson/{diagnostics,threads} into build-utils-meson/common
This reduces the amount of boilerplate. More importantly, it provides
a place to add compiler flags (such as -O3) without having to add it
to every subproject (and the risk of forgetting to include it).
2024-11-21 20:34:54 +01:00
Jack Wilsdon
1301f8434d Filter OSC 8 correctly
This allows Nix to use lowdown 1.2.0 which outputs OSC-8 links.
2024-11-13 00:49:46 +00:00
Eelco Dolstra
f29e7867a9 Revert "Merge pull request #11826 from DeterminateSystems/revert-11804"
This reverts commit aeffdeffc8, reversing
changes made to 723fdeb4f1.
2024-11-11 15:21:34 +01:00
Eelco Dolstra
67d231c046 Revert "Merge pull request #11804 from obsidiansystems/remove-old-make"
This reverts commit 619eeb658a, reversing
changes made to 1af94bf471.
2024-11-07 13:46:37 +01:00
John Ericson
e70c9bb06a Remove old build system 2024-11-06 16:09:18 -05:00
Sergei Zimmerman
2e7466a4e0 fix(libutil-tests/nix_api_util): get rid of unnecessary memory leaks 2024-11-06 10:55:39 +03:00
Brian McKenna
9dca7aeece Set Windows API version in Meson 2024-11-05 23:36:08 +11:00
John Ericson
e65510da56 Move unit tests to the location Meson expects them to be
Everything that is a separate subproject should live in the subprojects
directory.

Progress on #2503

This reverts commit 451f8a8c19.
2024-10-17 15:42:16 -04:00