Commit Graph

13984 Commits

Author SHA1 Message Date
Amaan Qureshi
0d8ca7a888 fetchers: use pathToUrlPath in PathInputScheme::toURL 2026-03-02 12:46:16 -05:00
Amaan Qureshi
9c59f62890 url: handle Windows drive letters in fixGitURL 2026-03-02 12:45:36 -05:00
Amaan Qureshi
f3792cdad5 flakeref: use portable root detection in directory walk loops 2026-03-02 12:45:36 -05:00
Amaan Qureshi
b26f2ca3e6 tests: clear NIX_STORE env in fetchers, expr, and flake test environments 2026-03-02 12:45:36 -05:00
Amaan Qureshi
62d275d7c0 tests: use pathToUrlPath for file:// URL construction in git test 2026-03-02 12:45:36 -05:00
Sergei Zimmerman
116cfbc221 Merge pull request #15373 from NixOS/value-alloc-cache-thread-local
libexpr: Make Boehm allocation cache thread_local
2026-03-02 16:13:13 +00:00
John Ericson
8999af2236 Merge pull request #15375 from NixOS/read-little-endian-bswap-tests
libutil: More efficient `readLittleEndian`
2026-03-02 15:00:14 +00:00
Sergei Zimmerman
9533aef459 libutil: More efficient readLittleEndian
Because unsigned char * can alias anything, the compiler has no choice
but to actually iterate byte-by-byte in readNum and readLittleEndian:

        │      movzbl -0x2f(%rbp),%eax
  12.54 │      movzbl -0x2e(%rbp),%edx
        │      shl    $0x8,%rax
   1.88 │      shl    $0x10,%rdx
        │      or     %rdx,%rax
        │      movzbl -0x30(%rbp),%edx
   5.09 │      or     %rdx,%rax
   2.37 │      movzbl -0x2d(%rbp),%edx
        │      shl    $0x18,%rdx
   3.95 │      or     %rdx,%rax
        │      movzbl -0x2c(%rbp),%edx
        │      shl    $0x20,%rdx
        │      or     %rax,%rdx
   5.59 │      movzbl -0x2b(%rbp),%eax
   3.29 │      shl    $0x28,%rax
        │      or     %rdx,%rax
   7.83 │      movzbl -0x2a(%rbp),%edx
        │      shl    $0x30,%rdx
        │      or     %rax,%rdx
   8.22 │      movzbl -0x29(%rbp),%eax
        │      shl    $0x38,%rax
        │      or     %rdx,%rax
   6.42 │      mov    %rax,%rcx
        │      mov    %rax,-0x60(%rbp)
   1.35 │      shr    $0x20,%rcxA

Which now compiles down to:

   2.20 │      mov  -0x30(%rbp),%rax
   3.12 │      mov  %rax,%rcx
        │      mov  %rax,-0x60(%rbp)
        │      shr  $0x20,%rcx
2026-03-02 15:56:44 +03:00
Eelco Dolstra
ca07011ed2 Use #include <...> for Windows system headers 2026-03-02 13:31:57 +01:00
Sergei Zimmerman
eba81abab9 libexpr: Make Boehm allocation cache thread_local
This seems quite natural to me, since boehm is necessarily a global
resource. I still think that it would be best if we don't make it a
requirement to only have a single instance of EvalState per thread, but
specifically for this use-case thread_local is a perfect fit.
2026-03-02 13:45:58 +03:00
Sergei Zimmerman
088df89457 Merge pull request #15371 from NixOS/sync-base-cond-var-template
libutil: Template SyncBase over `condition_variable` implementation
2026-03-02 09:43:26 +00:00
Sergei Zimmerman
decc061939 libutil: Template SyncBase over condition_variable implementation
This will allow us to use boost::fibers with the SyncBase class.
2026-03-02 00:58:18 +03:00
Brian McKenna
6244e5fcc1 LocalStore: stop creating outdated profiles symlink
This was done in 9799023545 but
accidentally reverted during a merge.
2026-03-02 07:56:50 +11:00
John Ericson
0acd0566e8 Merge pull request #15360 from roberth/fun
Have `fun`: `std::function` without null
2026-02-27 20:42:23 +00:00
Robert Hensing
152d7a9b48 refactor: use fun
- `fun` was used for variable/field names in a number of places.
  These have been replaced by similar or more descriptive names,
  to avoid name shadowing, which is not allowed in the GCC-based build.

- Use in-place construction instead of assignment.

- `FilteringSourceAccessor::checkAccess` had a fallback for when
  `makeNotAllowedError` was null. Since `MakeNotAllowedError` is now
  `fun<>`, we've proven the null branch is dead code and have removed it.

- `src/nix/flake.cc`, `src/nix/search.cc`, `src/nix/ls.cc` are left
  as-is — the self-referential lambdas there cause too much
  reindentation for too little benefit.
2026-02-27 15:58:12 +01:00
Robert Hensing
4f5117f791 feat(libutil): add fun<Sig>, a non-nullable std::function wrapper
Like `ref<T>` guarantees a non-null pointer, `fun<Sig>` guarantees a
non-null callable.

When a callable is nullable, use `std::function` directly — not
`optional<fun<>>`. The two types serve complementary roles:
`fun<Sig>` for non-null, `std::function<Sig>` for nullable.

Construction from callables (lambdas, function pointers) is implicit
since these are inherently non-null. Construction from `std::function`
is explicit, since it may be empty. `fun(nullptr)` is a deleted
overload.

A moved-from `fun<>` violates its non-null invariant, matching the
precedent set by `ref<T>`. Deleting moves was considered but deemed
unnecessary: the goal of this type is to document and enforce an
invariant, not to force non-null at all costs including performance.

`get_fn()` exposes the underlying `std::function` for API that only
exists there, such as `target<>()`.
2026-02-27 15:58:12 +01:00
Sergei Zimmerman
2b5a1a9730 Merge pull request #15349 from roberth/fix-cli-messages
Fix package-related CLI messages
2026-02-27 10:30:04 +00:00
Amaan Qureshi
fc08c86a07 types: remove Path* typedefs
This commit replaces all usages with their underlying types, that being `std::string` for store
paths, `std::filesystem::path` for filesystem paths, `StringSet` for
path sets, and `std::string_view` for non-owning references.
2026-02-27 00:54:28 -05:00
John Ericson
718e4dbc02 Add SysError/WinError constructors that take a HintFmt-producing function
This allows capturing the current value/result of
`errno`/`GetLastError()` before constructing the error message. Useful
when the error message construction itself might clobber the error code
(e.g., calling `descriptorToPath()`).

Usage:
```
throw NativeSysError([&] { return HintFmt("msg %s", foo()); });
```

The error code is captured when the exception is constructed, then the
lambda is called to produce the `HintFmt`.

Also fix the Windows build
2026-02-26 20:15:21 -05:00
John Ericson
c522f58947 Merge pull request #15357 from obsidiansystems/remove-path-setting
Remove path setting
2026-02-26 23:26:03 +00:00
Amaan Qureshi
c165ae939f libstore: introduce StoreDirSetting for store directory 2026-02-26 17:31:53 -05:00
Amaan Qureshi
9ab4740d44 libutil: remove unused OptionalPathSetting 2026-02-26 17:14:44 -05:00
John Ericson
65617395c6 Merge pull request #15345 from obsidiansystems/no-abs-paths-in-eval-2
Create lint for absolute path literals
2026-02-26 22:11:58 +00:00
Sergei Zimmerman
796f5cd724 treewide: Get rid of confusing time(0) and use proper nullptr literal
Use proper nullptr literal for NULL pointer instead of the rather confusing 0
literal.
2026-02-27 00:18:12 +03:00
Sergei Zimmerman
bcf2cd4feb Fix NarInfoDiskCache::queryCacheRaw on 32 bit platforms
Bug has existed for a long time, but was only recently surfaced by
6733f2e5ce. time_t was being implicitly promoted
to unsigned. Apparently time_t is still 32 bit for i686-linux in nixpkgs.

Fixes https://hydra.nixos.org/build/322992746/nixlog/1
2026-02-27 00:16:39 +03:00
John Ericson
ed494f00ca Create lint for absolute path literals
Fixes #8738
2026-02-26 15:06:18 -05:00
Robert Hensing
eda9c014c5 fix(eval): render store path context in user-facing format
forceStringNoCtx error messages leaked internal string context
representation (e.g. '!out!<hash>-name.drv'). Use DerivedPath
syntax instead: '<store-path>^out' for built, plain path for
opaque, and '<drv-path> (deep)' for deep derivation references.
2026-02-26 18:06:51 +01:00
Robert Hensing
1442133f1e fix(get-drvs): correct misleading "CA derivations" error in queryOutPath
The error had nothing to do with content-addressed derivations; it
triggers when a supposed derivation attrset simply lacks an outPath
attribute.
2026-02-26 18:06:51 +01:00
Sergei Zimmerman
224c8182df libstore: Fix pct-encoding issues in store references
When the common pattern for store config constructors is to accept
an arbitrary string it's unclear whether it needs pct-decoding or not.
Prior to c436b7a32a the string passed to
the constructors was a mix of encoded authority and decoded path concatenated
with a `/`. After that commit it accidentally started accepting pct-encoded
result of renderAuthorityAndPath, but only in some code paths. This lead to
file:///tmp/a+b to be created on disk in /tmp/a%2Bb directory. Similar issue
affected the less-known variant with local:///tmp/a+b. Regular store references
that are local paths were not affected.

This patch changes the constructors to accept different types to signify what
is actually needed to let the factory method handle this in a consistent way:

- std::filesystem::path - local binary cache store and local store
- ParsedURL::Authority - for ssh stores
- ParsedURL - for http stores

(Some MinGW build fixes by Amaan Qureshi <git@amaanq.com>)
2026-02-26 16:40:49 +03:00
John Ericson
d9dd677448 Create two wrappers for unlink
See b9ef088e80 for why
`std::filesystem::remove` was no good.
2026-02-25 22:27:59 -05:00
John Ericson
ee955b3206 Merge pull request #15346 from obsidiansystems/return-owned-fd
Return `AutoCloseFD` in open-like functions
2026-02-26 02:09:43 +00:00
John Ericson
89dd96efbf Return AutoCloseFD in open-like functions
This reflects the fact that it is returning a new, "owned" file
descriptor, that it is the caller's responsibility to close.

Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-02-25 20:17:30 -05:00
John Ericson
6481e75283 Merge pull request #15344 from NixOS/no-filesystem-remove
Revert "libstore: replace unlink() with std::filesystem::remove()"
2026-02-26 00:50:16 +00:00
John Ericson
b9ef088e80 Revert "libstore: replace unlink() with std::filesystem::remove()"
This reverts commit b8caabe25f.

`std::filesystem::remove` will actually do a `rmdir` for directories.
Per https://en.cppreference.com/w/cpp/filesystem/remove.html :

> The file or empty directory identified by the path p is deleted as if
> by the POSIX remove. Symlinks are not followed (symlink is removed,
> not its target).

See
https://pubs.opengroup.org/onlinepubs/9699919799/functions/remove.html

This is a behavior change that we can't be sure is fine, so let's revert
for now. We can do an unlink wrapper later to avoid the `.string()`.
2026-02-25 18:59:28 -05:00
John Ericson
02bb3d032d Merge pull request #15336 from NixOS/libcurl-content-encoding
filetransfer: Use libcurl for Content-Encoding/Transfer-Encoding transparent decompression
2026-02-25 23:19:34 +00:00
John Ericson
89a4412673 Merge pull request #15326 from obsidiansystems/no-abs-paths-in-eval
New diagnostics infra
2026-02-25 23:18:21 +00:00
Sergei Zimmerman
06a1511bff Merge pull request #15082 from roberth/issue-15053
repl: support inherit statements and multiple bindings
2026-02-25 23:09:12 +00:00
Sergei Zimmerman
4cf6843acf Merge pull request #15341 from NixOS/fix-flake-regressions
Fix the nix-community/patsh/0.2.1 flake regression test (again)
2026-02-25 22:47:55 +00:00
John Ericson
5184f844bb New diagnostics infra
- Convert `no-url-literals` from experimental feature to `Diagnose`
  setting

  Replace `Xp::NoUrlLiterals` with a new `lint-url-literals` setting
  that accepts `ignore`, `warn`, or `fatal`. This provides more
  flexibility than the binary experimental feature.

- Convert `warn-short-path-literals` to use new lint infra

  We now have `lint-short-path-literals = ignore | warn | fatal`
  instead.

- Convert some of the tests to lang tests

Fix #10048
Progress on #10281
2026-02-25 17:29:56 -05:00
Sergei Zimmerman
fa07d9d055 filetransfer: Use libcurl for Content-Encoding/Transfer-Encoding transparent decompression
Get rid of manual decompression entirely. We can support zstd, br,
deflate (which was broken previously) and gzip/x-gzip encodings via curl
without manual work on our side. This is the same approach that was taken by lix.

Also adds some tests for x-gzip support.
2026-02-26 01:28:46 +03:00
Robert Hensing
ca0f40f29e parseReplBindingsFromBuf: assert non-null result 2026-02-25 23:19:37 +01:00
John Ericson
ae33d09589 Merge pull request #15339 from obsidiansystems/convert-some-more-path
libstore: convert more `Path` to `std::filesystem::path`
2026-02-25 22:15:32 +00:00
Amaan Qureshi
d4b9a81956 libstore: convert more Path to std::filesystem::path
This commit converts local filesystem paths throughout libstore from the
string-based `Path` typedef to `std::filesystem::path`.
2026-02-25 16:26:01 -05:00
Amaan Qureshi
91688d4a34 libstore: use OsStrings for SSH args 2026-02-25 16:25:32 -05:00
Amaan Qureshi
b8caabe25f libstore: replace unlink() with std::filesystem::remove() 2026-02-25 16:25:32 -05:00
Eelco Dolstra
2334977863 Fix the nix-community/patsh/0.2.1 flake regression test (again) 2026-02-25 21:49:30 +01:00
Sergei Zimmerman
c8b02e6ff3 Merge pull request #15335 from dramforever/jsonlogger-no-interrupts
Don't throw Interrupted from JSONLogger::write
2026-02-25 19:03:42 +00:00
dramforever
1210100421 libutil/logging: Use writeFullLogging in JSONLogger::write
Logging should not check for interrupts. Use the new writeFullLogging
function to write JSON output to get similar behavior to SimpleLogger.

This avoids the logger itself throwing Interrupted exceptions in
handleExceptions.
2026-02-26 01:36:54 +08:00
dramforever
473d54ed5f libutil/logging: Generalize writeToStderr into writeFullLogging
Generalize writeToStderr into writeFullLogging, with similar behavior
but taking an arbitrary fd, and reimplement writeToStderr with it as a
convenient wrapper.
2026-02-26 00:51:31 +08:00
John Ericson
937a076844 Merge pull request #15332 from obsidiansystems/windows-libutil-ci
ci: add Windows nix-util-tests job
2026-02-25 16:35:38 +00:00