nix-update icon indicating copy to clipboard operation
nix-update copied to clipboard

Revert version change if nix-prefetch fails - or - dont commit if version doesn't change

Open 06kellyjac opened this issue 4 years ago • 2 comments

If nix-prefetch fails the version bump stays saved in the file Then if you run nix-update --build --commit again it'll just build the "new version" with the old shas and then commit like so: nerdctl: 0.6.1 -> 0.6.1

I've opened the nix-prefetch issue separately:

Some potential solutions would be:

  • Revert the version change if nix-prefetch fails
  • Don't commit a change if "Not updating version, already 0.6.1" (might be nice if it aborted the build too?)

(either or both)


Config ~/.config/nixpkgs/config.nix:

{
  packageOverrides = pkgs: {
    nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
      inherit pkgs;
    };
  };
}

Should be nothing in there that causes issues

Logs:

nix-update --build --commit nerdctl
$ nix eval --json --impure --experimental-features nix-command --expr (with import ./. {};
    let
      pkg = nerdctl;
      raw_version_position = builtins.unsafeGetAttrPos "version" pkg;

      position = if pkg ? isRubyGem then
        raw_version_position
      else
        builtins.unsafeGetAttrPos "src" pkg;
    in {
      name = pkg.name;
      old_version = (builtins.parseDrvName pkg.name).version;
      inherit raw_version_position;
      filename = position.file;
      line = position.line;
      urls = pkg.src.urls or null;
      url = pkg.src.url or null;
      rev = pkg.src.url.rev or null;
      hash = pkg.src.outputHash;
      mod_sha256 = pkg.modSha256 or null;
      vendor_sha256 = pkg.vendorSha256 or null;
      cargo_sha256 = pkg.cargoSha256 or null;
      tests = pkg.passthru.tests or null;
    })
fetch https://github.com/AkihiroSuda/nerdctl/releases.atom
Update 0.6.0 -> 0.6.1 in /home/jk/projects/personal/nixpkgs/pkgs/applications/networking/cluster/nerdctl/default.nix
$ nix-prefetch (import ./. {}).nerdctl
warning: unknown setting 'experimental-features'
warning: unknown setting 'experimental-features'
The package nerdctl-0.6.1 will be fetched as follows:
> fetchFromGitHub {
>   owner = "AkihiroSuda";
>   repo = "nerdctl";
>   rev = "v0.6.1";
>   sha256 = "sha256-QhAN30ge0dbC9dGT1yP4o0VgrcS9+g+r6YJ07ZjPJtg=";
> }

A probably-wrong output hash of zeroes has been used, yet it somehow still succeeded in building.
Please report an issue at: https://github.com/msteen/nix-prefetch/issues
Traceback (most recent call last):
  File "/nix/store/lagdrmaal96m49fh9p012g58mlyvzqa4-nix-update-0.3.2/bin/.nix-update-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/lagdrmaal96m49fh9p012g58mlyvzqa4-nix-update-0.3.2/lib/python3.8/site-packages/nix_update/__init__.py", line 172, in main
    package = update(options)
  File "/nix/store/lagdrmaal96m49fh9p012g58mlyvzqa4-nix-update-0.3.2/lib/python3.8/site-packages/nix_update/update.py", line 139, in update
    update_src_hash(opts, package.filename, package.hash)
  File "/nix/store/lagdrmaal96m49fh9p012g58mlyvzqa4-nix-update-0.3.2/lib/python3.8/site-packages/nix_update/update.py", line 84, in update_src_hash
    target_hash = nix_prefetch([f"(import {opts.import_path} {{}}).{opts.attribute}"])
  File "/nix/store/lagdrmaal96m49fh9p012g58mlyvzqa4-nix-update-0.3.2/lib/python3.8/site-packages/nix_update/update.py", line 76, in nix_prefetch
    res = run(["nix-prefetch"] + cmd, extra_env=extra_env)
  File "/nix/store/lagdrmaal96m49fh9p012g58mlyvzqa4-nix-update-0.3.2/lib/python3.8/site-packages/nix_update/utils.py", line 36, in run
    return subprocess.run(
  File "/nix/store/papbnjfxwrdkmz6xfp7v2q7nxyvgcr5l-python3-3.8.6/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['nix-prefetch', '(import ./. {}).nerdctl']' returned non-zero exit status 1.

# ----------- run again ----------------

nix-update --build --commit nerdctl
$ git -C ./. diff --staged
$ nix eval --json --impure --experimental-features nix-command --expr (with import ./. {};
    let
      pkg = nerdctl;
      raw_version_position = builtins.unsafeGetAttrPos "version" pkg;

      position = if pkg ? isRubyGem then
        raw_version_position
      else
        builtins.unsafeGetAttrPos "src" pkg;
    in {
      name = pkg.name;
      old_version = (builtins.parseDrvName pkg.name).version;
      inherit raw_version_position;
      filename = position.file;
      line = position.line;
      urls = pkg.src.urls or null;
      url = pkg.src.url or null;
      rev = pkg.src.url.rev or null;
      hash = pkg.src.outputHash;
      mod_sha256 = pkg.modSha256 or null;
      vendor_sha256 = pkg.vendorSha256 or null;
      cargo_sha256 = pkg.cargoSha256 or null;
      tests = pkg.passthru.tests or null;
    })
fetch https://github.com/AkihiroSuda/nerdctl/releases.atom
Not updating version, already 0.6.1
$ nix build --experimental-features nix-command -f ./. nerdctl
$ git -C ./. add /home/jk/projects/personal/nixpkgs/pkgs/applications/networking/cluster/nerdctl/default.nix
$ git -C ./. diff --staged
$ git -C ./. commit --verbose --message nerdctl: 0.6.1 -> 0.6.1
[nerdctl 2e91fd64ff8] nerdctl: 0.6.1 -> 0.6.1
 1 file changed, 1 insertion(+), 1 deletion(-)

06kellyjac avatar Feb 24 '21 09:02 06kellyjac