Swiss-knife for updating nix packages.
Go to file
2024-11-18 21:17:40 +01:00
.github chore(deps): update cachix/install-nix-action action to v30 (#291) 2024-10-05 16:08:22 +02:00
bin create-release: no longer edit git tag messages 2024-11-09 09:07:14 +01:00
nix_update feat: add support for fetchCargoVendor 2024-11-18 17:19:22 +01:00
tests feat: add support for fetchCargoVendor 2024-11-18 17:19:22 +01:00
.envrc modernize formatter 2024-09-30 09:04:06 +02:00
.gitignore Add support for updating buildComposerProject's vendorHash 2024-01-16 11:06:16 +01:00
.mergify.yml mergify: fix branch and checks list 2024-10-01 06:51:01 +02:00
default.nix pytest: add xdist for parallel testing 2024-11-18 15:07:16 +01:00
flake.lock flake.lock: Update 2024-11-18 14:06:18 +01:00
flake.nix modernize formatter 2024-09-30 09:04:06 +02:00
LICENSE.rst make it a proper python/nix package 2020-03-16 10:06:32 +00:00
pyproject.toml bump version 1.7.0 2024-11-18 21:17:40 +01:00
README.md modernize formatter 2024-09-30 09:04:06 +02:00
renovate.json apply treefmt 2023-05-20 09:14:24 +02:00
treefmt.nix fix treefmt eval on riscv64 linux and x86_64 darwin 2024-11-09 08:46:15 +01:00

nix-update

Nix-update updates versions/source hashes of nix packages. It is designed to work with nixpkgs but also other package sets.

Features

  • automatically figure out the latest version of packages from:
    • BitBucket
    • Codeberg
    • crates.io
    • Gitea
    • GitHub
    • GitLab
    • PyPi
    • RubyGems.org
    • Sourcehut
    • Savannah
  • update buildRustPackage's cargoHash/cargoSha256/cargoLock and cargoSetupHook's cargoDeps
  • update buildGoModule's vendorHash/vendorSha256
  • update buildNpmPackage's npmDepsHash and npmConfigHook's npmDeps
  • update buildComposerProject's vendorHash
  • update buildMavenPackage's mvnHash
  • update mixRelease's mixFodDeps
  • update fetchYarnDeps offlineCache output hash
  • update flake outputs (see --flake)
  • generate the following lockfile, Cargo.lock (see --generate-lockfile and --lockfile-metadata-path)
  • build and run the resulting package (see --build, --run or --shell
  • commit updated files (see --commit flag)
  • run update scripts (passthru.updateScript, see --use-update-script flag)
  • run package tests (see --test flag)
  • specify the system to use (see --system flag)

Installation

nix-update is included in nixpkgs.

To run without installing it, use:

$ nix-shell -p nix-update

To install it:

$ nix-env -f '<nixpkgs>' -iA nix-update

To run it from the git repository:

$ nix-build
$ ./result/bin/nix-update

If you have nix flakes enabled you can also do:

$ nix run github:Mic92/nix-update

USAGE

First change to your directory containing the nix expression (Could be a nixpkgs or your own repository). Than run nix-update as follows

$ nix-update attribute [--version version]

If your package is defined in a flake use the --flake flag instead:

$ nix-update attribute --flake [--version version]

nix-update will than try to update either the packages.{currentSystem}.{attribute} or {attribute} output attribute of the given flake. To update a package in legacyPackages, pass the full path to that package including the platform: legacyPackages.{platform}.{attribute}.

This example will fetch the latest github release:

$ nix-update nixpkgs-review

It is also possible to specify the version manually

$ nix-update --version=2.1.1 nixpkgs-review

To update an unstable package to the latest commit of the default branch:

$ nix-update --version=branch nixpkgs-review

To update an unstable package the latest commit from a certain branch:

$ nix-update --version=branch=develop nixpkgs-review

To only update sources hashes without updating the version:

$ nix-update --version=skip nixpkgs-review

To extract version information from versions with prefixes or suffixes, a regex can be used

$ nix-update jq --version-regex 'jq-(.*)'

By default nix-update will locate the file that needs to be patched using the src attribute of a derivation. In some cases this heurestic is wrong. One can override the behavior like that:

$ nix-update hello --override-filename pkgs/applications/misc/hello/default.nix

The nix-update command checks for new releases of a package using the src attribute. However, in some cases a package may use a non-standard release URL that is not supported by nix-update, but still has a repository with release information. For example, the Signal Desktop package in Nixpkgs fetches updates from https://updates.signal.org/, but also publishes release information on its GitHub page. In such cases, use the --url parameter to direct nix-update to the correct repository:

nix-update --url https://github.com/signalapp/Signal-Desktop --override-filename pkgs/applications/networking/instant-messengers/signal-desktop/default.nix   signal-desktop

With the --shell, --build, --test and --run flags the update can be tested. Additionally, the --review flag can be used to initiate a run of nixpkgs-review, which will ensure all dependent packages can be built.

In order to ensure consistent formatting, the --format flag will invoke nixfmt (nixfmt-rfc-style in nixpkgs).

# Also runs nix-build
$ nix-update --build nixpkgs-review
# Also runs nix-build nixpkgs-review.tests
$ nix-update --test nixpkgs-review
# Also runs nix-shell
$ nix-update --shell nixpkgs-review
# Also runs nix run
$ nix-update --run nixpkgs-review
# Run `nixpkgs-review wip` to validate dependent packages
$ nix-update --review nixpkgs-review
# Format file
$ nix-update --format nixpkgs-review

Nix-update also can optionally generate a commit message in the form attribute: old_version -> new_version with the applied version update:

$ nix-update --commit bitcoin-abc
...
[master 53d68a6a5a9] bitcoin-abc: 0.21.1 -> 0.21.2
1 file changed, 2 insertions(+), 2 deletions(-)

By default, nix-update will attempt to update to the next stable version of a package. Alphas, betas, release candidates and similar unstable releases will be ignored. This can be affected by changing the parameter version from its default value stable to unstable.

$ nix-update sbt
Not updating version, already 1.4.6

$ nix-update sbt --version=unstable
Update 1.4.6 -> 1.5.0-M1 in sbt

Nix-update can also run the passthru.updateScript defined by the package.

$ nix-update sbt --use-update-script

Arguments can be passed to nix-shell maintainers/scripts/update.nix like so

$ nix-update sbt --use-update-script --update-script-args "--argstr skip-prompt true"

Development setup

First clone the repo to your preferred location (in the following, we assume ~/ - your home):

$ git clone https://github.com/Mic92/nix-update/ ~/nix-update

Than enter the dev shell:

$ cd ~/nix-update
$ nix develop

Change to the repository that contains the nix files you want to update, i.e. nixpkgs:

$ cd nixpkgs

Now you can run nix-update just by specifying the full path to its executable wrapper:

$ ~/git/nix-update/bin/nix-update --commit hello

TODO

  • create pull requests

Known Bugs

nix-update might not work correctly if a file contain multiple packages as it performs naive search and replace to update version numbers. This might be a problem if:

  • A file contains the same version string for multiple packages.
  • name is used instead of pname and/or ${version} is injected into name.

Related discussions:

  • nixpkgs-update is optimized for mass-updates in nixpkgs while nix-update is better suited for interactive usage that might require user-intervention i.e. fixing the build and testing the result. nix-update is also not limited to nixpkgs.