Commit Graph

22959 Commits

Author SHA1 Message Date
John Ericson
a2d1346852 Merge pull request #15333 from NixOS/canon-path-from-filename
Introduce `CanonPath::fromFilename`
2026-02-25 15:59:09 +00:00
John Ericson
7275556d61 Introduce CanonPath::fromFilename
See docs for what it is. Use in DerivationBuilderImpl::writeBuilderFile
and deletePath. Also adds O_DIRECTORY via openDirectory in deletePath.

Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
2026-02-25 13:36:42 +03:00
John Ericson
16f10c1321 Merge pull request #15329 from obsidiansystems/path-review-followup
file-system: drop redundant quotes around `PathFmt` and assert relative paths
2026-02-25 04:43:04 +00:00
Amaan Qureshi
d5dafb35c3 local-fs-store: make toRealPath accept StorePath only 2026-02-24 22:25:28 -05:00
Amaan Qureshi
f4dfbca04d Fix issues from #15313
- file-system: drop redundant quotes around `PathFmt` and assert relative paths
- libutil, libstore: fix mingw cross-compilation breakages
2026-02-24 19:00:25 -05:00
John Ericson
cf1ead7872 Merge pull request #15330 from NixOS/file-system-get-rid-of-fs-to-string
libutil: Get rid of double-quoting and .string() calls in file-system.cc
2026-02-24 22:23:26 +00:00
John Ericson
56735e9d0f Merge pull request #15328 from NixOS/more-hardening-file-system-at-builders
DerivationBuilderImpl: Add more hardening for writeBuilderFile
2026-02-24 21:57:44 +00:00
Sergei Zimmerman
5b9c41f1b7 libutil: Get rid of double-quoting and .string() calls in file-system.cc
Significantly reduces the amount of churny .string() conversions when
we don't need them and gets rid of annoying double-quoting issues once again.
2026-02-25 00:34:11 +03:00
John Ericson
63845dd9b3 Merge pull request #15313 from obsidiansystems/no-path-libutil
libutil: replace string-based Path with std::filesystem::path across core libraries
2026-02-24 18:56:19 +00:00
John Ericson
b84a42f4cc libutil: replace string-based Path with std::filesystem::path across core libraries
This takes the `std::filesystem::path` migration from the CLI layer into the core libraries (libutil, libstore, libexpr, libfetchers, libflake), converting function signatures, settings fields, and locals throughout `file-system.hh`, `archive.hh`, `configuration.hh`, and their implementations. `PathSetting` becomes `Setting<std::filesystem::path>` in `local-overlay-store.hh` and `local-store.hh` with `.get()` calls at use sites, and several `writeFile` overloads collapse now that the `Path`-based wrappers in `file-system.hh` are gone.

Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-02-24 13:05:16 -05:00
John Ericson
003b64476e Merge pull request #15312 from obsidiansystems/convert-more-end-exes
cli: continue converting `Path` to `std::filesystem::path` in CLI commands
2026-02-24 17:24:26 +00:00
John Ericson
1e499e616a Merge pull request #15325 from obsidiansystems/rootless-daemon-nixpkgs
tests/functional/unprivileged-daemon: Use nixpkgs unprivileged support
2026-02-24 16:19:36 +00:00
Sergei Zimmerman
246c3fe8d3 DerivationBuilderImpl: Add more hardening for writeBuilderFile
Adds additional layers of hardening for various file-writing utility
functions in the derivation builder. Bad names in non-structured attrs
case are already checked against `[A-Za-z_][A-Za-z0-9_.-]*` regex, so
this isn't an issue, but adding more hardening is good regardless.
2026-02-24 19:15:19 +03:00
Artemis Tosini
ade94a5c0e tests/functional/unprivileged-daemon: Use nixpkgs unprivileged support
Nixpkgs recently added support for running the daemon as unprivileged.
Instead of duplicating the test setup, use the upstream module.
2026-02-24 10:35:37 -05:00
siddhantCodes
a5a256265f cli: continue converting Path to std::filesystem::path in CLI commands
Follows previous work by converting more string-based `Path` fields and
locals to `std::filesystem::path` across the CLI layer:
`MixOutLinkBase::outLink`, `CmdAddToStore::path`, `CmdBundle::outLink`,
`CmdDevelop` redirects and shell, `nix-build`, `nix-channel`, `nix-env`,
`nix-instantiate`, `nix-store`, and `upgrade-nix`.

Also, change `runProgram` and friends to use `OsString` for argument
lists, since those will be native strings. This allows us to avoid
(potentially lossy) `std::filesystem::path` (wide chars on windows) ->
`std::string` (narrow) -> `OsString` (i.e. `std::wstring` on Windows,
wide again) round trips. For CLIs with no path arguments, there is a
`toOsStrings` function for convenience, however.

Progress on #9205

Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-02-23 15:46:31 -05:00
John Ericson
be7b9a33ed Replace renderUrlPathEnsureLegal with urlPathToPath
We make `urlPathToPath` support relative paths for of Flakes.

The mercurial fetching got a bit larger of a rework with this, by taking
advantage of `std::variant`.
2026-02-23 15:41:03 -05:00
John Ericson
5ce241cbfd Merge pull request #15307 from nix-windows/windows-local-shorthand
windows: add a separate local_shorthand_path test
2026-02-23 19:42:48 +00:00
John Ericson
3bfd64c3cd Merge pull request #15323 from obsidiansystems/fix-eio-readline
libutil: treat EIO as EOF in `readLine`
2026-02-23 19:30:19 +00:00
Brian McKenna
3f419cfa4e ParsedURL::path <-> std::filesystem::path, use in StoreReference
This missing URL functionality allow us to properly fix the path
shorthand for local store URLs test case.
2026-02-23 13:32:07 -05:00
Amaan Qureshi
994137dcf7 libutil: treat EIO as EOF in readLine
Reading from a pty master returns `EIO` once the slave side closes, however, `readLine` lets it propagate as an uncaught `SysError`, which causes spurious build failures in gvisor and similar sandboxed environments where pty teardown races differently. This commit catches `EIO` inside the read lambda and maps it to a zero-length read, reusing the existing EOF path.
2026-02-23 13:30:05 -05:00
Sergei Zimmerman
9242d74bc1 Merge pull request #15321 from obsidiansystems/writefull-interrupt-test
tests: add `writeFull` interrupt-handling regression test
2026-02-23 18:29:27 +00:00
Amaan Qureshi
6cddf03b5a tests: add writeFull interrupt-handling regression test
This commit verifies that `writeFull` with `allowInterrupts=false` completes
successfully when the interrupt flag is set. This prevents regressions
like the one fixed by #15255 where `write()` called `checkInterrupt()`
unconditionally.
2026-02-23 12:20:54 -05:00
Bernardo Meurer
afccf1d2d3 Merge pull request #15256 from NixOS/dependabot/github_actions/cachix/install-nix-action-31.9.1
build(deps): bump cachix/install-nix-action from 31.9.0 to 31.9.1
2026-02-23 14:09:16 +00:00
Bernardo Meurer
de16ef8be6 Merge pull request #15257 from NixOS/dependabot/github_actions/korthout/backport-action-4.1.0
build(deps): bump korthout/backport-action from 4.0.1 to 4.1.0
2026-02-23 14:08:51 +00:00
Sergei Zimmerman
7cd7930344 Merge pull request #15319 from xokdvium/fix-interrupts-write-full
libutil: Fix writeFull to respect allowInterrupts
2026-02-23 14:03:30 +00:00
Sergei Zimmerman
658c775f01 libutil: Fix writeFull to respect allowInterrupts
c0e849b696 broke interrupt handling since
writeFull started throwing Interrupted even when allowInterrupts was false.
This would lead to exceptions leaking out when they must not (for example during
progress bar shutdown).
2026-02-23 15:34:18 +03:00
Sergei Zimmerman
b1ad42e6d5 Merge pull request #15242 from obsidiansystems/fix-prefetch-segfault
libstore: guard against empty archive in unpack paths
2026-02-22 19:14:11 +00:00
John Ericson
761139f31c Merge pull request #15314 from obsidiansystems/fix-registry-symlink
registry: fix symlinked flake registry files broken by convert-end-exes
2026-02-21 20:06:31 +00:00
Amaan Qureshi
c6d93828bd registry: fix symlinked flake registry files broken by convert-end-exes
This commit reverts to using `getFSSourceAccessor()` so absolute symlink targets resolve correctly, since `makeFSSourceAccessor(path)` roots the accessor at `path` and can't follow symlinks that escape it.
2026-02-21 12:14:42 -05:00
Sergei Zimmerman
614072adcb Merge pull request #15286 from NixOS/failed-values-v2
Introduce a "failed" value type (v2)
2026-02-21 09:05:15 +00:00
John Ericson
42f6e9933d Merge pull request #15311 from obsidiansystems/convert-end-exes
libutil: return `std::filesystem::path` from XDG directory helpers
2026-02-21 04:22:26 +00:00
siddhantCodes
6808bfab92 libutil: return std::filesystem::path from XDG directory helpers
`getCacheDir`, `getConfigDir`, `getDataDir`, `getStateDir`, and related functions now return `std::filesystem::path` and use `getEnvOs` for native OS string handling, letting callsites replace string concatenation with `operator/` and drop the ad-hoc `namespace nix::fs` alias from six CLI files. `expandTilde` is fixed to strip both `~` and `/` before joining with `operator/` (an absolute right-hand operand silently replaces the left-hand side), and `ExecutablePath` gains `parseAppend` for incremental `PATH` construction.

Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-02-20 22:35:47 -05:00
John Ericson
92942071c7 Merge pull request #15310 from obsidiansystems/pathlocks-wine
`PathLocks` allow to fail on Wine
2026-02-21 03:32:18 +00:00
John Ericson
8899af09c1 Merge pull request #15308 from obsidiansystems/fix-ioport-init
Fix initialization of `ioport` in `Worker` on Windows
2026-02-21 02:48:26 +00:00
John Ericson
6363c1bf00 PathLocks allow to fail on Wine
It needs functionality Wine doesn't implement yet. So let's just have a
wine-only warn-and-keep-going.
2026-02-20 21:45:04 -05:00
John Ericson
5adb6a36b6 Fix initialization of ioport in Worker on Windows 2026-02-20 18:56:00 -05:00
John Ericson
b10cb6596e Merge pull request #15305 from obsidiansystems/file-system-prep
Centralize I/O error handling and make read/write functions portable
2026-02-20 17:31:21 +00:00
John Ericson
c0e849b696 Centralize I/O error handling and make read/write functions portable
- Improve existing `read` and `readOffset` wrappers:
  - Unix: Add `EINTR` retry handling and `checkInterrupt`
  - Windows: Handle `ERROR_BROKEN_PIPE` as EOF, add `checkInterrupt`

- Add `write` wrapper with same treatment (`EINTR` on Unix, `checkInterrupt`)

- Improve many `windows/file-descriptor.cc` error messages with
  `descriptorToPath`

- Move `readFull`, `readLine`, `writeFull` to common file, using the
  platform wrappers instead of duplicating platform-specific logic.
  These ones don't need any `EINTR` or interrupt checking either. They
  only have `EGAIN` checking as Unix-specific code, but this is a temp
  hack to be removed per #12688, so its fine that it goes in the
  platform-agnostic file for now.

- Add `retryOnBlock` helper to abstract `EAGAIN`/`EWOULDBLOCK` poll-and-retry
  logic (Unix only, needed for buildhook workaround #12688)

- Simplify `FdSource::readUnbuffered` to just call `nix::read`

- Remove now-dead `EINTR` handling from `drainFD` and `copyFdRange`

- `writeErr` better impl on Windows
2026-02-20 11:39:05 -05:00
John Ericson
2470b7981a Merge pull request #15277 from puffnfresh/windows/remove-profiles-symlink
LocalStore: stop creating outdated profiles symlink
2026-02-20 05:52:49 +00:00
John Ericson
5c1939e315 Merge pull request #15301 from obsidiansystems/file-system-prep
Misc file system fixes, especially for windows
2026-02-20 01:28:58 +00:00
Brian McKenna
9799023545 LocalStore: stop creating outdated profiles symlink
The gcroots/profiles link became outdated in
aeb810b01e when the GC code started
reading directly from /profiles, and gcroots/profiles was even
partially deleted in that commit.
2026-02-20 11:48:13 +11:00
John Ericson
ae4e229c9f Change writeFile(AutoCloseFD &, ...) to take a Descriptor
The new signature is:
  writeFile(Descriptor fd, std::string_view s, FsSync sync = FsSync::No, const Path * origPath = nullptr)

This uses `descriptorToPath` if `origPath` is not provided.
2026-02-19 19:30:55 -05:00
Amaan Qureshi
b63f5d1914 libutil: refactor AutoCloseFD::fsync into standalone syncDescriptor
`AutoCloseFD::fsync()` contained platform-specific logic behind CPP
guards. This extracts it into a free function `syncDescriptor(Descriptor)`
with separate Unix and Windows implementations, and makes
`AutoCloseFD::fsync()` an inline wrapper that delegates to it. The
Windows implementation uses `FlushFileBuffers` (returns `BOOL`, true on
success) while Unix uses `::fsync` (or `F_FULLFSYNC` on macOS), so
splitting them avoids conflating the two calling conventions.
2026-02-19 19:23:49 -05:00
John Ericson
31d87afc5a openFileEnsureBeneathNoSymlinks now returns AutoCloseFD
This indicates that they are returning an owned handle (i.e. the caller
 should --- and will, thanks to RAII --- close it).

 `ntOpenAt` and friends (internal) also use `AutoCloseFD` for the same
 reason.
2026-02-19 19:08:31 -05:00
John Ericson
204618c9d8 Misc unit test improvements 2026-02-19 17:26:38 -05:00
John Ericson
f0d90d3bdb Create two more FSSourceAccessorTests
Make sure we're testing non-directory roots.
2026-02-19 17:25:54 -05:00
John Ericson
0730dcb4a8 Skip chmodIfNeeded test on Windows
It doesn't do anything on Windows, it appears.
2026-02-19 17:21:46 -05:00
John Ericson
9b363e1e5c libutil-tests: Use FS_ROOT macros consistently in file-system tests
Add FS_ROOT_NO_TRAILING_SLASH macro and update isInDir and isDirOrInDir tests to use FS_ROOT and FS_SEP macros for cross-platform compatibility.
2026-02-19 17:21:12 -05:00
John Ericson
3df67a8347 Merge pull request #15298 from dramforever/parse-derivation-empty-special-msg
Add special error message for empty derivation file
2026-02-19 20:12:38 +00:00
Robert Hensing
dd4b73a44d Add rl-next/c-api-recoverable-errors 2026-02-19 14:23:05 +03:00