Skip to content

Comments

libexpr: Don't use nix::dirOf in prim_dirOf (fix 2.23 regression)#14515

Merged
Ericson2314 merged 2 commits intomasterfrom
dirOf-dont-call-std-filesystem
Nov 9, 2025
Merged

libexpr: Don't use nix::dirOf in prim_dirOf (fix 2.23 regression)#14515
Ericson2314 merged 2 commits intomasterfrom
dirOf-dont-call-std-filesystem

Conversation

@xokdvium
Copy link
Contributor

@xokdvium xokdvium commented Nov 9, 2025

Motivation

Fixes #14513 and adds tests. A lot of builtins.dirOf behavior on strings is cursed, but there's no changing that now. Best we can do is stay bug-for-bug compatible with prior nix versions. This should get backported as far as possible.

Context

The first commit adds tests but doesn't change the regressed behavior. The second fixes it and updates the test.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@xokdvium xokdvium requested a review from Ericson2314 November 9, 2025 13:18
@xokdvium xokdvium requested a review from edolstra as a code owner November 9, 2025 13:18
@xokdvium xokdvium added backport 2.28-maintenance Automatically creates a PR against the branch backport 2.29-maintenance Automatically creates a PR against the branch backport 2.30-maintenance Automatically creates a PR against the branch backport 2.31-maintenance Automatically creates a PR against the branch backport 2.32-maintenance Automatically creates a PR against the branch labels Nov 9, 2025
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Nov 9, 2025
@xokdvium

This comment was marked as outdated.

@xokdvium xokdvium force-pushed the dirOf-dont-call-std-filesystem branch from ef70c59 to e697509 Compare November 9, 2025 14:32
@xokdvium xokdvium force-pushed the dirOf-dont-call-std-filesystem branch 2 times, most recently from 04d95d5 to a6cf6fe Compare November 9, 2025 15:46
These will change in the next commit to fix the silent regression from 2.23
in the handling of multiple subsequent path separators.
This gets us back to pre-2.23 behavior of this primop.
Done by inlining the code of `nix::dirOf` from 2.2-maintenance.
@xokdvium xokdvium force-pushed the dirOf-dont-call-std-filesystem branch from a6cf6fe to a33fccf Compare November 9, 2025 15:57
@xokdvium xokdvium requested a review from roberth November 9, 2025 15:58
@Ericson2314 Ericson2314 added this pull request to the merge queue Nov 9, 2025
@Ericson2314
Copy link
Member

Should we backport, @xokdvium?

@Ericson2314
Copy link
Member

Also, we might want to add a test for dirOf preserving the string context too, so it is not just the flake regression test suite that happens to catch it.

@xokdvium
Copy link
Contributor Author

xokdvium commented Nov 9, 2025

Should we backport

Since this is a bug that is somewhat recent it seems prudent to backport to all supported versions while we still can.

Merged via the queue into master with commit 6ebaba5 Nov 9, 2025
20 checks passed
@Ericson2314 Ericson2314 deleted the dirOf-dont-call-std-filesystem branch November 9, 2025 17:42
@internal-nix-ci
Copy link

Successfully created backport PR for 2.28-maintenance:

@internal-nix-ci
Copy link

Successfully created backport PR for 2.29-maintenance:

@internal-nix-ci
Copy link

Successfully created backport PR for 2.30-maintenance:

@internal-nix-ci
Copy link

Successfully created backport PR for 2.31-maintenance:

@internal-nix-ci
Copy link

Successfully created backport PR for 2.32-maintenance:

@edolstra
Copy link
Member

Did anybody observe this "regression" in the real world? I'm not sure we should revert to worse behavior if nobody was affected by this... Bug-for-bug compatibility should really only apply if people were actually depending on the buggy behaviour. Since nobody complained in almost a year since 2.23, that's good evidence that nobody was affected by this.

@xokdvium
Copy link
Contributor Author

Since nobody complained in almost a year since 2.23, that's good evidence that nobody was affected by this.

Yes, that does mean that we can fix the behavior in the future, but using std::filesystem was definitely an accident. Because of it e.g. dirOf "///" evaluated to ///. That is trading one incorrect behavior for another and that doesn't help much. Sticking to a "known" bad at least lessens the amount of chaos in the ecosystem.

@Ericson2314
Copy link
Member

I agree with @xokdvium and also that that I would be comfortable changing this intentionally in the future, because I also don't believe in bug-for-bug compat. But yes this was neither intentional, not a clear net-improvement (and using std::filesystem in the wrong way was definitely a clear negative).

@roberth
Copy link
Member

roberth commented Nov 12, 2025

bug-for-bug compat

You have more important things to achieve than risking making a mess of this builtin, when changes like this eventually boomerang back to you.

If you want a clean language, I'd suggest making a new one that's data-model-interoperable through some small interface (JSON + string context + function calls).
Don't waste your time on the builtins.

@edolstra edolstra mentioned this pull request Dec 9, 2025
philiptaron added a commit to philiptaron/nixpkgs that referenced this pull request Jan 8, 2026
## Bug fixes (crashes)

- Fix segfaults from `toView()` when compiled with newer nixpkgs (NixOS/nix#14154)
- Fix use-after-move in `DerivationGoal::repairClosure` and `SampleStack` (NixOS/nix#14086)
- Fix assertion failure on partially valid derivation outputs (NixOS/nix#14137)
- Fix `RestrictedStore::addDependency` recursion causing crashes (NixOS/nix#14729)
- Fix crash on flakerefs containing newlines (NixOS/nix#14450)

## Bug fixes (functionality)

- Fix fakeSSH check breaking SSH copies with `user@host` format (NixOS/nix#14150)
- Fix `builtins.dirOf` regression from Nix 2.23 (NixOS/nix#14515)
- Restore missing `isAllowed` check in `ChrootLinuxDerivationBuilder` (NixOS/nix#14531)
- Fix curl with c-ares failing to resolve DNS in sandbox on macOS (NixOS/nix#14792)
- Fix tarball percent decoding for `file://` URIs (NixOS/nix#14729)
- `exportReferencesGraph`: Handle heterogeneous arrays (NixOS/nix#13861)
- Fix filesystem ops in store optimization (NixOS/nix#14676)

## Bug fixes (output)

- Fix double-quoting of paths in logs (NixOS/nix#14210)
- Include path in world-writable error messages (NixOS/nix#14785)

## Improvements

- Better git refnames validation (NixOS/nix#14253)
- Use pure/restricted eval for help pages (NixOS/nix#14156)
- Improve store-reference compatibility with IPv6 ZoneId literals (NixOS/nix#14134)
- Correct `build-dir` error in manual (NixOS/nix#14745)

## Build system

- Add mdbook 0.5 support (NixOS/nix#14690)
- Drop legacy Apple SDK pattern (NixOS/nix#13976)

https://github.com/NixOS/nix/releases/tag/2.31.3
philiptaron added a commit to philiptaron/nixpkgs that referenced this pull request Jan 8, 2026
Changelog of fixes:

## Bug fixes (crashes)

- Fix segfaults from `toView()` when compiled with newer nixpkgs (NixOS/nix#14154)
- Fix use-after-move in `DerivationGoal::repairClosure` and `SampleStack` (NixOS/nix#14086)
- Fix assertion failure on partially valid derivation outputs (NixOS/nix#14137)
- Fix `RestrictedStore::addDependency` recursion causing crashes (NixOS/nix#14729)
- Fix crash on flakerefs containing newlines (NixOS/nix#14450)

## Bug fixes (functionality)

- Fix fakeSSH check breaking SSH copies with `user@host` format (NixOS/nix#14150)
- Fix `builtins.dirOf` regression from Nix 2.23 (NixOS/nix#14515)
- Restore missing `isAllowed` check in `ChrootLinuxDerivationBuilder` (NixOS/nix#14531)
- Fix curl with c-ares failing to resolve DNS in sandbox on macOS (NixOS/nix#14792)
- Fix tarball percent decoding for `file://` URIs (NixOS/nix#14729)
- `exportReferencesGraph`: Handle heterogeneous arrays (NixOS/nix#13861)
- Fix filesystem ops in store optimization (NixOS/nix#14676)

## Bug fixes (output)

- Fix double-quoting of paths in logs (NixOS/nix#14210)
- Include path in world-writable error messages (NixOS/nix#14785)

## Improvements

- Better git refnames validation (NixOS/nix#14253)
- Use pure/restricted eval for help pages (NixOS/nix#14156)
- Improve store-reference compatibility with IPv6 ZoneId literals (NixOS/nix#14134)
- Correct `build-dir` error in manual (NixOS/nix#14745)

## Build system

- Add mdbook 0.5 support (NixOS/nix#14690)
- Drop legacy Apple SDK pattern (NixOS/nix#13976)

https://github.com/NixOS/nix/releases/tag/2.31.3
philiptaron added a commit to philiptaron/nixpkgs that referenced this pull request Jan 15, 2026
Changelog of fixes:

## Bug fixes (crashes)

- Fix segfaults from `toView()` when compiled with newer nixpkgs (NixOS/nix#14154)
- Fix use-after-move in `DerivationGoal::repairClosure` and `SampleStack` (NixOS/nix#14086)
- Fix assertion failure on partially valid derivation outputs (NixOS/nix#14137)
- Fix `RestrictedStore::addDependency` recursion causing crashes (NixOS/nix#14729)
- Fix crash on flakerefs containing newlines (NixOS/nix#14450)

## Bug fixes (functionality)

- Fix fakeSSH check breaking SSH copies with `user@host` format (NixOS/nix#14150)
- Fix `builtins.dirOf` regression from Nix 2.23 (NixOS/nix#14515)
- Restore missing `isAllowed` check in `ChrootLinuxDerivationBuilder` (NixOS/nix#14531)
- Fix curl with c-ares failing to resolve DNS in sandbox on macOS (NixOS/nix#14792)
- Fix tarball percent decoding for `file://` URIs (NixOS/nix#14729)
- `exportReferencesGraph`: Handle heterogeneous arrays (NixOS/nix#13861)
- Fix filesystem ops in store optimization (NixOS/nix#14676)

## Bug fixes (output)

- Fix double-quoting of paths in logs (NixOS/nix#14210)
- Include path in world-writable error messages (NixOS/nix#14785)

## Improvements

- Better git refnames validation (NixOS/nix#14253)
- Use pure/restricted eval for help pages (NixOS/nix#14156)
- Improve store-reference compatibility with IPv6 ZoneId literals (NixOS/nix#14134)
- Correct `build-dir` error in manual (NixOS/nix#14745)

## Build system

- Add mdbook 0.5 support (NixOS/nix#14690)
- Drop legacy Apple SDK pattern (NixOS/nix#13976)

https://github.com/NixOS/nix/releases/tag/2.31.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.28-maintenance Automatically creates a PR against the branch backport 2.29-maintenance Automatically creates a PR against the branch backport 2.30-maintenance Automatically creates a PR against the branch backport 2.31-maintenance Automatically creates a PR against the branch backport 2.32-maintenance Automatically creates a PR against the branch with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dirOf "regression" in 2.23

4 participants