Repository: NixOS/nix (C++)

Issue:
crashed when running nix-buid in nixos/nix docker container
For background, I was reading https://mitchellh.com/writing/nix-with-dockerfiles and following along.

## Describe the bug

I ran the nixos/nix docker container. At the shell, I created a file, and typed a few shell commands; I then saw some output  that said "this is a bug; please file a bug report".

## Steps To Reproduce

I was using Orbstack on MacOS, although that might not be relevant.
- At my Mac's shell, I typed `docker run -it nixos/nix`
- In the container shell, I typed `cat > flake.nix`, and then pasted the contents of the "flake.nix" file at https://mitchellh.com/writing/nix-with-dockerfiles (I'll try to attach the text to this issue, but right now I don't know how to do that)
- In the container shell, I typed `nix build --extra-experimental-features nix-command --extra-experimental-features flakes`
- At that point I saw the following:
```
terminating due to unexpected unrecoverable internal error: Unexpected condition in std::string nix::ParsedURL::renderAuthorityAndPath() const at ../url.cc:356
Nix crashed. This is a bug. Please report this at https://github.com/NixOS/nix/issues with the following information included:

std::terminate() called without exception
Stack trace:
 0# 0x0000000000462744 in nix
 1# 0x0000FFFFBA19110C in /nix/store/wffgswxkp55xi14jy63rjsnfvl2qvmxy-gcc-14.3.0-lib/lib/libstdc++.so.6
 2# std::unexpected() in /nix/store/wffgswxkp55xi14jy63rjsnfvl2qvmxy-gcc-14.3.0-lib/lib/libstdc++.so.6
 3# nix::ExecutablePath::render[abi:cxx11]() const in /nix/store/1a0a8wajkpfz1cqgnzm09hwbr0h6ys8q-nix-util-2.32.0/lib/libnixutil.so.2.32.0
 4# 0x0000FFFFBAE03DD0 in /nix/store/1a0a8wajkpfz1cqgnzm09hwbr0h6ys8q-nix-util-2.32.0/lib/libnixutil.so.2.32.0
 5# nix::ParsedURL::renderAuthorityAndPath[abi:cxx11]() const in /nix/store/1a0a8wajkpfz1cqgnzm09hwbr0h6ys8q-nix-util-2.32.0/lib/libnixutil.so.2.32.0
 6# nix::ParsedURL::to_string[abi:cxx11]() const in /nix/store/1a0a8wajkpfz1cqgnzm09hwbr0h6ys8q-nix-util-2.32.0/lib/libnixutil.so.2.32.0
 7# nix::fetchers::Input::toURLString(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<void>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&) const in /nix/store/2my57fx79a0qh1v6qxh5dnq6paaz2506-nix-fetchers-2.32.0/lib/libnixfetchers.so.2.32.0
 8# nix::FlakeRef::to_string[abi:cxx11]() const in /nix/store/nh29wzm0lbabdrd5yx5vbiw2n4ib04yc-nix-flake-2.32.0/lib/libnixflake.so.2.32.0
 9# 0x0000FFFFBA39DF6C in /nix/store/y195j03sml55cwd08q7s82ylrh6683hd-nix-cmd-2.32.0/lib/libnixcmd.so.2.32.0
10# nix::InstallableFlake::toDerivedPaths() in /nix/store/y195j03sml55cwd08q7s82ylrh6683hd-nix-cmd-2.32.0/lib/libnixcmd.so.2.32.0
11# nix::Installable::build2(nix::ref<nix::Store>, nix::ref<nix::Store>, nix::Realise, std::vector<nix::ref<nix::Installable>, std::allocator<nix::ref<nix::Installable> > > const&, nix::BuildMode) in /nix/store/y195j03sml55cwd08q7s82ylrh6683hd-nix-cmd-2.32.0/lib/libnixcmd.so.2.32.0
12# nix::Installable::build(nix::ref<nix::Store>, nix::ref<nix::Store>, nix::Realise, std::vector<nix::ref<nix::Installable>, std::allocator<nix::ref<nix::Installable> > > const&, nix::BuildMode) in /nix/store/y195j03sml55cwd08q7s82ylrh6683hd-nix-cmd-2.32.0/lib/libnixcmd.so.2.32.0
13# 0x000000000045048C in nix
14# nix::InstallablesCommand::run(nix::ref<nix::Store>, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&) in /nix/store/y195j03sml55cwd08q7s82ylrh6683hd-nix-cmd-2.32.0/lib/libnixcmd.so.2.32.0
15# nix::RawInstallablesCommand::run(nix::ref<nix::Store>) in /nix/store/y195j03sml55cwd08q7s82ylrh6683hd-nix-cmd-2.32.0/lib/libnixcmd.so.2.32.0
16# nix::StoreCommand::run() in /nix/store/y195j03sml55cwd08q7s82ylrh6683hd-nix-cmd-2.32.0/lib/libnixcmd.so.2.32.0
17# 0x00000000004CE494 in nix
18# nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) in /nix/store/8plygijm6v7hsbjca2ky51bs80xr0b0g-nix-main-2.32.0/lib/libnixmain.so.2.32.0
19# 0x0000000000437514 in nix
20# 0x0000FFFFB9EE62B4 in /nix/store/r0pjdp81mmd7dvk5pv1ch75hrbbw60xb-glibc-2.40-66/lib/libc.so.6
21# __libc_start_main in /nix/store/r0pjdp81mmd7dvk5pv1ch75hrbbw60xb-glibc-2.40-66/lib/libc.so.6
22# 0x000000000043BFB0 in nix
```
<!--
  Example:

  1. Clone this repository: ...
  2. Run `nix-... ...`
  3. Observe unexpected behaviour
-->

## Expected behavior

I expected, or at least hoped for, a message to the effect of "I build your little flask app for you in `result`

## Metadata

<!-- Please insert the output of running `nix-env --version` below this line -->
`nix-env (Nix) 2.32.0`

## Checklist

<!-- make sure this issue is not redundant or obsolete -->

- [ ] checked [latest Nix manual] \([source])
Nope.  I don't know enough about nix to make any sense of the manual.  I'm reporting this bug only because your software told me to.

- [X] checked [open bug issues and pull requests] for possible duplicates


[latest Nix manual]: https://nix.dev/manual/nix/development/
[source]: https://github.com/NixOS/nix/tree/master/doc/manual/source
[open bug issues and pull requests]: https://github.com/NixOS/nix/labels/bug

---

Add :+1: to [issues you find important](https://github.com/NixOS/nix/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc).



Discussion: @offby1 so there's a couple of issue I think. It looks like you have put the `flake.nix` file in the root directory. This will definitely not work. 2.32.0 hits an internal assertion when trying to report an error. 2.31.x reports:

```
error:
       … while fetching the input 'path:/'

       error: file '/dev/console' has an unsupported type
```

Flakes currently have to copy everything to the store and the root directory definitely cannot be copied to the store. We should probably add a better diagnostic for this.

The assertion failure is an unfortunate SNAFU of mine and will be fixed.



Fix (patch):
diff --git a/src/libutil/url.cc b/src/libutil/url.cc
index 1c7fd3f0fe3..a50de094441 100644
--- a/src/libutil/url.cc
+++ b/src/libutil/url.cc
@@ -350,7 +350,7 @@ std::string ParsedURL::renderAuthorityAndPath() const
            must either be empty or begin with a slash ("/") character. */
         assert(path.empty() || path.front().empty());
         res += authority->to_string();
-    } else if (std::ranges::equal(std::views::take(path, 2), std::views::repeat("", 2))) {
+    } else if (std::ranges::equal(std::views::take(path, 3), std::views::repeat("", 3))) {
         /* If a URI does not contain an authority component, then the path cannot begin
            with two slash characters ("//") */
         unreachable();