How to install Tor browser on NixOS?

It seems that it is permanently broken on NixOS, and even though I found a small number of online resource on how it may be installed, I’m deliberately omitting them for now because I’m really interested what people do to get it to work… (I was only able to install it once on a temp machines ca. a year and a half back, which probably had to do with the fortuitous alignment of the stars at that time.)

These are all the tor-browser related packages there are:

$ nix-shell -p tor-browser-
tor-browser-bundle      tor-browser-bundle-bin  tor-browser-unwrapped

$ nix-shell -p tor-browser-bundle
error: tor-browser-bundle was removed because it was out of date and inadequately maintained. Please use tor-browser-bundle-bin instead. See #77452.
(use '--show-trace' to show detailed location information)

$ nix-shell -p tor-browser-unwrapped
error: tor-browser-unwrapped was removed because it was out of date and inadequately maintained. Please use tor-browser-bundle-bin instead. See #77452.
(use '--show-trace' to show detailed location information)

$ nix-shell -p tor-browser-bundle-bin
these derivations will be built:
  /nix/store/amkhbi1dnjwq6gry5k7q2sv1ww23nbax-tor-browser-linux64-10.0.9_en-US.tar.xz.drv
  /nix/store/nhki3xslks4na5d176gbhrzldqnxzisd-tor-browser-bundle-bin-10.0.9.drv
building '/nix/store/amkhbi1dnjwq6gry5k7q2sv1ww23nbax-tor-browser-linux64-10.0.9_en-US.tar.xz.drv'...

trying https://dist.torproject.org/torbrowser/10.0.9/tor-browser-linux64-10.0.9_en-US.tar.xz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
curl: (22) The requested URL returned error: 404 Not Found
error: cannot download tor-browser-linux64-10.0.9_en-US.tar.xz from any mirror
builder for '/nix/store/amkhbi1dnjwq6gry5k7q2sv1ww23nbax-tor-browser-linux64-10.0.9_en-US.tar.xz.drv' failed with exit code 1
cannot build derivation '/nix/store/nhki3xslks4na5d176gbhrzldqnxzisd-tor-browser-bundle-bin-10.0.9.drv': 1 dependencies couldn't be built
error: build of '/nix/store/nhki3xslks4na5d176gbhrzldqnxzisd-tor-browser-bundle-bin-10.0.9.drv' failed

Trying nix-env from my cloned and just rebased Nixpkgs repo:

$ nix-env -f . -iA tor-browser-bundle-bin
... lots of lines ...
nix-env: src/libexpr/attr-set.hh:54: void nix::Bindings::push_back(const nix::Attr&): Assertion `size_ < capacity_' failed.
Aborted (core dumped)

Apparently, the nix-env -f my-local-nixpkgs-clone/ -iA tor-browser-bundle-bin didn’t quite fail (not sure how to put this) because the commands nix-shell equivalent worked without copying any more paths into the Nix store, and just immediately dropped me in a shell with tor-browser available:

$ nix-shell -E 'with import my-local-nixpkgs-clone/default.nix {}; runCommand "dummy" { buildInputs = [ tor ~
-browser-bundle-bin ]; } ""'

and running tor-browser starts up without an issue.

TODO(self): This seems like a nix-env issue based on the error message so look into it.

(Credit for the nix-shell line goes to @potong, and taken from @potong 's Stackoverflow thread. Thanks a lot for doing this research!)

I always use nixpkgs-unstable impurely for packages that have frequent updates and would break if pinned - actually for the same reason as you have: Tor browser seemed to be always broken anywhere else.