Mic92 / nix-update

Swiss-knife for updating nix packages.
MIT License
516 stars 49 forks source link

Failure to run the update when using `--version-regex` and a package without `rev` in the source #297

Open liff opened 2 weeks ago

liff commented 2 weeks ago

It seems that the combination of --version-regex and the absence of rev field in the source causes a failure in the updater.

How to reproduce

Trying to run the updateScript in nixos/nixpkgs#356109 throws an exception:

Can be reproduced by checking out the PR without the last commit:

nixpkgs$ git remote add liff git@github.com:liff/nixpkgs
nixpkgs$ git checkout remotes/liff/gradle/v8.11^1
nixpkgs$ nix-shell maintainers/scripts/update.nix --argstr path gradle
this derivation will be built:
  /nix/store/q5a0j37yksy0xzbq8i33hq9s7c6zyynl-packages.json.drv
building '/nix/store/q5a0j37yksy0xzbq8i33hq9s7c6zyynl-packages.json.drv'...

Going to be running update for following packages:
 - gradle-8.10.2

Press Enter key to continue...

Running update for:
 - gradle-8.10.2: UPDATING ...
 - gradle-8.10.2: ERROR

--- SHOWING ERROR LOG FOR gradle-8.10.2 ----------------------

Traceback (most recent call last):
  File "/nix/store/w0fw2mvq1636hmnd1hsvfbvhvknzcqrc-nix-update-1.6.0/bin/.nix-update-wrapped", line 9, in <module>
    sys.exit(main())
             ^^^^^^
  File "/nix/store/w0fw2mvq1636hmnd1hsvfbvhvknzcqrc-nix-update-1.6.0/lib/python3.12/site-packages/nix_update/__init__.py", line 311, in main
    package = update(options)
              ^^^^^^^^^^^^^^^
  File "/nix/store/w0fw2mvq1636hmnd1hsvfbvhvknzcqrc-nix-update-1.6.0/lib/python3.12/site-packages/nix_update/update.py", line 456, in update
    update_hash = update_version(
                  ^^^^^^^^^^^^^^^
  File "/nix/store/w0fw2mvq1636hmnd1hsvfbvhvknzcqrc-nix-update-1.6.0/lib/python3.12/site-packages/nix_update/update.py", line 429, in update_version
    return replace_version(package)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/w0fw2mvq1636hmnd1hsvfbvhvknzcqrc-nix-update-1.6.0/lib/python3.12/site-packages/nix_update/update.py", line 41, in replace_version
    line = line.replace(package.rev, package.new_version.rev)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: replace() argument 1 must be str, not None

--- SHOWING ERROR LOG FOR gradle-8.10.2 ----------------------
The update script for gradle-8.10.2 failed with exit code 1

Possible fix

Changing the condition here to:

-                if package.new_version.rev:
+                if package.rev and package.new_version.rev:

fixes the problem in my case, but I’m not 100% sure it’s a proper fix.

l0b0 commented 6 days ago

Is this a dupe of #295?