nix
                                
                                 nix copied to clipboard
                                
                                    nix copied to clipboard
                            
                            
                            
                        nix should fails with the HTTP error when using flakes URLs
Describe the bug
When using a flake URL that doesn't exist (because we can make mistakes), nix should report the proper HTTP error instead of erroring about not finding the attribute in the flake, which is misleading.
Steps To Reproduce
$ nix run nix -- profile install github:Idont/exist/a0df6cd6e199df4a78c833c273781ea92fa62cfb#keepassxc
error: flake 'github:Idont/exist/a0df6cd6e199df4a78c833c273781ea92fa62cfb' does not provide attribute 'packages.x86_64-linux.keepassxc', 'legacyPackages.x86_64-linux.keepassxc' or 'keepassxc'
Expected behavior
$ nix run nix -- profile install github:Idont/exist/a0df6cd6e199df4a78c833c273781ea92fa62cfb#keepassxc
error: HTTP error 404 when fetching https://api.github.com/repos/github/Idont/exist/tarball/a0df6cd6e199df4a78c833c273781ea92fa62cfb
$ nix run nix -- --version
nix (Nix) 2.12.0pre20220920_9dadb54
I didn't check the code, but looking at the logs (with enough -vs), there's a line about
using cache entry '{"rev":"a0df6cd6e199df4a78c833c273781ea92fa62cfb","type":"git-tarball"}' -> '{"lastModified":1663229557,"rev":"a0df6cd6e199df4a78c833c273781ea92fa62cfb"}', '/nix/store/0a1wz9a9izzsizwn9w24y5v8sslkmc1m-source'
The cache key just indicates the commit hash, so I guess it's just no taking the repo into account (as long as this commit hash has been fetched locally from another repo that has it).
In that case, the hash belongs to nixos-hardware (which indeed doesn't have packages.keepassxc nor any of the others shorthands)
This is with a pretty clean store.
$ nix run nix -- profile install github:Idont/exist/a0df6cd6e199df4a78c833c273781ea92fa62cfb#keepassxc
error: unable to download 'https://api.github.com/repos/Idont/exist/tarball/a0df6cd6e199df4a78c833c273781ea92fa62cfb': HTTP error 404
       response body:
       {
         "message": "Not Found",
         "documentation_url": "https://docs.github.com/rest/reference/repos#download-a-repository-archive"
       }
(use '--show-trace' to show detailed location information)
$ nix run nix -- --version
nix (Nix) 2.12.0pre20220921_f704c27
Could there be a way to improve this error message though? Perhaps it can tell us that it failed with a cached item. I don't believe it's currently clear it didn't even try to reach the internet. Perhaps print out the entire store path it's trying to use as a reference? That´d at least make it clear something is already on your system.
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/tweag-nix-dev-update-36/22120/1