Skip to content

Conversation

@limouren
Copy link
Contributor

@limouren limouren commented Jul 7, 2025

If derivation's src is from a npm package and if such npm package is scoped (e.g. @org/packagename instead of packagename), wrong URL would be used to fetch latest version and failed.

To reproduce:

> cat test-scoped-npm.nix
{
  pkgs ? import <nixpkgs> { },
}:
{
  claude-code = pkgs.stdenv.mkDerivation rec {
    pname = "claude-code";
    version = "1.0.42";

    src = pkgs.fetchurl {
      url =
"https://registry.npmjs.org/@anthropic-ai/claude-code/-/claude-code-${version}.tgz";
      sha256 = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
    };
  };
}
> ./bin/nix-update --file test-scoped-npm.nix claude-code
# OMITTED
fetch https://registry.npmjs.org/@anthropic-ai/latest
Traceback (most recent call last):
  File "/Users/limouren/nix-update/./bin/nix-update", line 12, in <module>
    main()
    ~~~~^^
  File "/Users/limouren/nix-update/nix_update/__init__.py", line 387, in main
    package = update(options)
  File "/Users/limouren/nix-update/nix_update/update.py", line 604, in update
    update_hash = update_version(
        opts,
    ...<3 lines>...
        opts.version_regex,
    )
  File "/Users/limouren/nix-update/nix_update/update.py", line 460, in update_version
    new_version = fetch_latest_version(
        package.parsed_url,
    ...<4 lines>...
        version_prefix,
    )
  File "/Users/limouren/nix-update/nix_update/version/__init__.py", line 102, in fetch_latest_version
    versions = fetcher(url)
  File "/Users/limouren/nix-update/nix_update/version/npm.py", line 17, in fetch_npm_versions
    resp = urllib.request.urlopen(npm_url)
  File "/nix/store/j1spz18w5a10r9nj4wpkyh0cx730rs4z-python3-3.13.4/lib/python3.13/urllib/request.py", line 189, in urlopen
    return opener.open(url, data, timeout)
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/j1spz18w5a10r9nj4wpkyh0cx730rs4z-python3-3.13.4/lib/python3.13/urllib/request.py", line 495, in open
    response = meth(req, response)
  File "/nix/store/j1spz18w5a10r9nj4wpkyh0cx730rs4z-python3-3.13.4/lib/python3.13/urllib/request.py", line 604, in http_response
    response = self.parent.error(
        'http', request, response, code, msg, hdrs)
  File "/nix/store/j1spz18w5a10r9nj4wpkyh0cx730rs4z-python3-3.13.4/lib/python3.13/urllib/request.py", line 533, in error
    return self._call_chain(*args)
           ~~~~~~~~~~~~~~~~^^^^^^^
  File "/nix/store/j1spz18w5a10r9nj4wpkyh0cx730rs4z-python3-3.13.4/lib/python3.13/urllib/request.py", line 466, in _call_chain
    result = func(*args)
  File "/nix/store/j1spz18w5a10r9nj4wpkyh0cx730rs4z-python3-3.13.4/lib/python3.13/urllib/request.py", line 613, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

Note that the log shows nix-update tries to fetch the URL:

While the correct URL should be:


This PR fixes this and added two test cases to test for URL generation for both scoped and non-scoped packages.

@limouren
Copy link
Contributor Author

limouren commented Jul 7, 2025

@Mic92 The nix-build failure seems to be unrelated to the changes: https://buildbot.thalheim.io/#/builders/293/builds/68

I think the changes are ready for review m(_ _)m

@Mic92
Copy link
Owner

Mic92 commented Jul 7, 2025

https://buildbot.thalheim.io/#/builders/3/builds/69 triggered a rebuild

@Mic92 Mic92 merged commit 1b5bc1e into Mic92:main Jul 7, 2025
3 checks passed
@limouren
Copy link
Contributor Author

limouren commented Jul 7, 2025

That's quick. Thanks a lot!

@limouren limouren deleted the fix-npm-scoped-package branch July 7, 2025 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants