diff --git a/.envrc b/.envrc index 4aa9dd8..1bebd0f 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1,4 @@ +# shellcheck shell=bash if ! has nix_direnv_version || ! nix_direnv_version 2.2.0; then source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.0/direnvrc" "sha256-5EwyKnkJNQeXrRkYbwwRBcXbibosCJqyIUuz9Xq+LRc=" fi diff --git a/.github/workflows/nix-fmt-checks.yaml b/.github/workflows/nix-fmt-checks.yaml deleted file mode 100644 index af11b5c..0000000 --- a/.github/workflows/nix-fmt-checks.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Nix formatter checks - -on: - pull_request: - push: - branches: - - master - - staging # for bors - - trying # for bors -jobs: - format-check: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install Nix - uses: cachix/install-nix-action@v29 - - - name: Run nix formatter tool - run: nix fmt -- --fail-on-change diff --git a/README.md b/README.md index c1f8343..6cf61f0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # nix-update -Nix-update updates versions/source hashes of nix packages. It is -designed to work with nixpkgs but also other package sets. +Nix-update updates versions/source hashes of nix packages. It is designed to +work with nixpkgs but also other package sets. ## Features @@ -16,7 +16,8 @@ designed to work with nixpkgs but also other package sets. - RubyGems.org - Sourcehut - Savannah -- update buildRustPackage's cargoHash/cargoSha256/cargoLock and cargoSetupHook's cargoDeps +- 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 @@ -24,9 +25,9 @@ designed to work with nixpkgs but also other package sets. - 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` +- 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) @@ -63,8 +64,8 @@ $ 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 +First change to your directory containing the nix expression (Could be a nixpkgs +or your own repository). Than run `nix-update` as follows ```console $ nix-update attribute [--version version] @@ -111,15 +112,16 @@ 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 +To extract version information from versions with prefixes or suffixes, a regex +can be used ```console $ 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: +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: ```console $ nix-update hello --override-filename pkgs/applications/misc/hello/default.nix @@ -138,11 +140,12 @@ nix-update --url https://github.com/signalapp/Signal-Desktop --override-filename ``` 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](https://github.com/Mic92/nixpkgs-review), which will ensure all +tested. Additionally, the `--review` flag can be used to initiate a run of +[nixpkgs-review](https://github.com/Mic92/nixpkgs-review), which will ensure all dependent packages can be built. -In order to ensure consistent formatting, the `--format` flag will invoke [nixfmt](https://github.com/NixOS/nixfmt) (`nixfmt-rfc-style` in nixpkgs). +In order to ensure consistent formatting, the `--format` flag will invoke +[nixfmt](https://github.com/NixOS/nixfmt) (`nixfmt-rfc-style` in nixpkgs). ```console # Also runs nix-build @@ -160,8 +163,7 @@ $ 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: +`attribute: old_version -> new_version` with the applied version update: ```console $ nix-update --commit bitcoin-abc @@ -170,10 +172,10 @@ $ nix-update --commit bitcoin-abc 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`. +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`. ```console $ nix-update sbt @@ -197,7 +199,8 @@ $ nix-update sbt --use-update-script --update-script-args "--argstr skip-prompt ## Development setup -First clone the repo to your preferred location (in the following, we assume `~/` - your home): +First clone the repo to your preferred location (in the following, we assume +`~/` - your home): ```console $ git clone https://github.com/Mic92/nix-update/ ~/nix-update @@ -210,13 +213,15 @@ $ cd ~/nix-update $ nix develop ``` -Change to the repository that contains the nix files you want to update, i.e. nixpkgs: +Change to the repository that contains the nix files you want to update, i.e. +nixpkgs: ```console $ cd nixpkgs ``` -Now you can run `nix-update` just by specifying the full path to its executable wrapper: +Now you can run `nix-update` just by specifying the full path to its executable +wrapper: ```console $ ~/git/nix-update/bin/nix-update --commit hello @@ -228,9 +233,9 @@ $ ~/git/nix-update/bin/nix-update --commit hello ## 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: +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`. @@ -242,8 +247,7 @@ Related discussions: ## Related projects: -- [nixpkgs-update](https://github.com/ryantm/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. +- [nixpkgs-update](https://github.com/ryantm/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. diff --git a/bin/create-release.sh b/bin/create-release.sh index cc2efce..7d5536f 100755 --- a/bin/create-release.sh +++ b/bin/create-release.sh @@ -6,7 +6,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" cd "$SCRIPT_DIR/.." version=${1:-} -if [[ -z "$version" ]]; then +if [[ -z $version ]]; then echo "USAGE: $0 version" >&2 exit 1 fi @@ -18,13 +18,13 @@ fi # ensure we are up-to-date uncommitted_changes=$(git diff --compact-summary) -if [[ -n "$uncommitted_changes" ]]; then +if [[ -n $uncommitted_changes ]]; then echo -e "There are uncommitted changes, exiting:\n${uncommitted_changes}" >&2 exit 1 fi git pull git@github.com:Mic92/nix-update master unpushed_commits=$(git log --format=oneline origin/master..master) -if [[ "$unpushed_commits" != "" ]]; then +if [[ $unpushed_commits != "" ]]; then echo -e "\nThere are unpushed changes, exiting:\n$unpushed_commits" >&2 exit 1 fi diff --git a/default.nix b/default.nix index ea3f7d7..9ffc0c3 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,7 @@ -{ pkgs ? import { } +{ + pkgs ? import { }, }: - pkgs.python311.pkgs.buildPythonApplication { pname = "nix-update"; version = "1.0.0"; @@ -21,7 +21,11 @@ pkgs.python311.pkgs.buildPythonApplication { makeWrapperArgs = [ "--prefix PATH" ":" - (pkgs.lib.makeBinPath [ pkgs.nixVersions.stable or pkgs.nix_2_4 pkgs.nixpkgs-review pkgs.nix-prefetch-git ]) + (pkgs.lib.makeBinPath [ + pkgs.nixVersions.stable or pkgs.nix_2_4 + pkgs.nixpkgs-review + pkgs.nix-prefetch-git + ]) ]; shellHook = '' # workaround because `python setup.py develop` breaks for me diff --git a/flake.lock b/flake.lock index 5e12936..d88499a 100644 --- a/flake.lock +++ b/flake.lock @@ -22,11 +22,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1727429674, - "narHash": "sha256-2/wcpn7a8xEx/c1/ih1DHTyVLOUME7xLRfi0mOBT35s=", + "lastModified": 1727617520, + "narHash": "sha256-uNfh3aMyCekMpjtL/PZtl2Hz/YqNuUpCBEzVxt1QYck=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e0f477a570df7375172a08ddb9199c90853c63f0", + "rev": "7eee17a8a5868ecf596bbb8c8beb527253ea8f4d", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index ecedf50..f1d629c 100644 --- a/flake.nix +++ b/flake.nix @@ -10,34 +10,45 @@ treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = inputs @ { flake-parts, ... }: - flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }: { - imports = [ ./treefmt.nix ]; - systems = [ - "aarch64-linux" - "x86_64-linux" - "riscv64-linux" + outputs = + inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } ( + { lib, ... }: + { + imports = [ ./treefmt.nix ]; + systems = [ + "aarch64-linux" + "x86_64-linux" + "riscv64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - perSystem = { config, pkgs, self', ... }: { - packages.nix-update = pkgs.callPackage ./. { }; - packages.default = config.packages.nix-update; + "x86_64-darwin" + "aarch64-darwin" + ]; + perSystem = + { + config, + pkgs, + self', + ... + }: + { + packages.nix-update = pkgs.callPackage ./. { }; + packages.default = config.packages.nix-update; - devShells.default = pkgs.mkShell { - inputsFrom = [ config.packages.default ]; + devShells.default = pkgs.mkShell { + inputsFrom = [ config.packages.default ]; - # Make tests use our pinned Nixpkgs - env.NIX_PATH = "nixpkgs=${pkgs.path}"; - }; + # Make tests use our pinned Nixpkgs + env.NIX_PATH = "nixpkgs=${pkgs.path}"; + }; - checks = - let - packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self'.packages; - devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self'.devShells; - in - packages // devShells; - }; - }); + checks = + let + packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self'.packages; + devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self'.devShells; + in + packages // devShells; + }; + } + ); } diff --git a/tests/testpkgs/bitbucket.nix b/tests/testpkgs/bitbucket.nix index 3333479..e3c0ffe 100644 --- a/tests/testpkgs/bitbucket.nix +++ b/tests/testpkgs/bitbucket.nix @@ -1,4 +1,8 @@ -{ stdenv, fetchFromBitbucket, isSnapshot }: +{ + stdenv, + fetchFromBitbucket, + isSnapshot, +}: let # Why this package? No reason, I just found a small package that uses tags @@ -8,20 +12,19 @@ let # As of 2024-04-23, latest version is 9.0.1, so we will be testing that it # finds a version greater than 9.0.0. The rev from 2021-03-02 is an untagged # commit. - version = - if (isSnapshot) - then "0.16-unstable-2022-10-01" - else "9.0.0"; - rev = - if (isSnapshot) - then "55b1b849a57341a303ae47eb67c7ecf8c283b7f8" - else "v9.0.0"; + version = if (isSnapshot) then "0.16-unstable-2022-10-01" else "9.0.0"; + rev = if (isSnapshot) then "55b1b849a57341a303ae47eb67c7ecf8c283b7f8" else "v9.0.0"; in stdenv.mkDerivation rec { pname = repo; inherit version; src = fetchFromBitbucket { - inherit owner repo version rev; + inherit + owner + repo + version + rev + ; # dont care about hash hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; }; diff --git a/tests/testpkgs/cargo-lock-generate/simple/default.nix b/tests/testpkgs/cargo-lock-generate/simple/default.nix index c0729f0..b1b668f 100644 --- a/tests/testpkgs/cargo-lock-generate/simple/default.nix +++ b/tests/testpkgs/cargo-lock-generate/simple/default.nix @@ -1,6 +1,7 @@ -{ python3Packages -, rustPlatform -, fetchFromGitHub +{ + python3Packages, + rustPlatform, + fetchFromGitHub, }: python3Packages.buildPythonPackage rec { diff --git a/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path-outside-workspace/default.nix b/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path-outside-workspace/default.nix index f63def8..cda51ca 100644 --- a/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path-outside-workspace/default.nix +++ b/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path-outside-workspace/default.nix @@ -1,6 +1,7 @@ -{ python3Packages -, rustPlatform -, fetchFromGitHub +{ + python3Packages, + rustPlatform, + fetchFromGitHub, }: python3Packages.buildPythonPackage rec { diff --git a/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path/default.nix b/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path/default.nix index b601016..1931817 100644 --- a/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path/default.nix +++ b/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path/default.nix @@ -1,6 +1,7 @@ -{ python3Packages -, rustPlatform -, fetchFromGitHub +{ + python3Packages, + rustPlatform, + fetchFromGitHub, }: python3Packages.buildPythonPackage rec { diff --git a/tests/testpkgs/composer-old.nix b/tests/testpkgs/composer-old.nix index 1643872..593f278 100644 --- a/tests/testpkgs/composer-old.nix +++ b/tests/testpkgs/composer-old.nix @@ -1,5 +1,6 @@ -{ fetchFromGitHub -, php +{ + fetchFromGitHub, + php, }: php.buildComposerProject (finalAttrs: { diff --git a/tests/testpkgs/composer.nix b/tests/testpkgs/composer.nix index 672fbfe..98cfc74 100644 --- a/tests/testpkgs/composer.nix +++ b/tests/testpkgs/composer.nix @@ -1,6 +1,4 @@ -{ fetchFromGitHub -, php -}: +{ fetchFromGitHub, php }: php.buildComposerProject2 (finalAttrs: { pname = "phpunit"; diff --git a/tests/testpkgs/crate.nix b/tests/testpkgs/crate.nix index f0ee56e..d2de3f1 100644 --- a/tests/testpkgs/crate.nix +++ b/tests/testpkgs/crate.nix @@ -1,4 +1,8 @@ -{ rustPlatform, fetchCrate, hello }: +{ + rustPlatform, + fetchCrate, + hello, +}: rustPlatform.buildRustPackage rec { pname = "fd-find"; diff --git a/tests/testpkgs/default.nix b/tests/testpkgs/default.nix index 3580d54..f3fa54c 100644 --- a/tests/testpkgs/default.nix +++ b/tests/testpkgs/default.nix @@ -1,11 +1,17 @@ -{ pkgs ? import { } }: +{ + pkgs ? import { }, +}: { bitbucket = pkgs.callPackage ./bitbucket.nix { isSnapshot = false; }; bitbucket-snapshot = pkgs.callPackage ./bitbucket.nix { isSnapshot = true; }; cargoLock.expand = pkgs.callPackage ./cargo-lock-expand { }; cargoLock.generate.simple = pkgs.callPackage ./cargo-lock-generate/simple { }; - cargoLock.generate.with-lockfile-metadata-path = pkgs.callPackage ./cargo-lock-generate/with-lockfile-metadata-path { }; - cargoLock.generate.with-lockfile-metadata-path-outside-workspace = pkgs.callPackage ./cargo-lock-generate/with-lockfile-metadata-path-outside-workspace { }; + cargoLock.generate.with-lockfile-metadata-path = + pkgs.callPackage ./cargo-lock-generate/with-lockfile-metadata-path + { }; + cargoLock.generate.with-lockfile-metadata-path-outside-workspace = + pkgs.callPackage ./cargo-lock-generate/with-lockfile-metadata-path-outside-workspace + { }; cargoLock.update = pkgs.callPackage ./cargo-lock-update { }; composer = pkgs.callPackage ./composer.nix { }; composer-old = pkgs.callPackage ./composer-old.nix { }; diff --git a/tests/testpkgs/flake.nix b/tests/testpkgs/flake.nix index 50e33be..3097c45 100644 --- a/tests/testpkgs/flake.nix +++ b/tests/testpkgs/flake.nix @@ -1,7 +1,9 @@ { - outputs = { self, nixpkgs }: { - packages = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: { - crate = nixpkgs.legacyPackages.${system}.callPackage (self + "/crate.nix") { }; - }); - }; + outputs = + { self, nixpkgs }: + { + packages = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: { + crate = nixpkgs.legacyPackages.${system}.callPackage (self + "/crate.nix") { }; + }); + }; } diff --git a/tests/testpkgs/npm.nix b/tests/testpkgs/npm.nix index d5628b6..fb65ba9 100644 --- a/tests/testpkgs/npm.nix +++ b/tests/testpkgs/npm.nix @@ -1,6 +1,4 @@ -{ fetchFromGitHub -, buildNpmPackage -}: +{ fetchFromGitHub, buildNpmPackage }: buildNpmPackage rec { pname = "jellyfin-web"; diff --git a/tests/testpkgs/pnpm.nix b/tests/testpkgs/pnpm.nix index 1a31737..8ee397e 100644 --- a/tests/testpkgs/pnpm.nix +++ b/tests/testpkgs/pnpm.nix @@ -1,6 +1,7 @@ -{ fetchFromGitHub -, pnpm_9 -, stdenv +{ + fetchFromGitHub, + pnpm_9, + stdenv, }: stdenv.mkDerivation rec { diff --git a/tests/testpkgs/pypi.nix b/tests/testpkgs/pypi.nix index a8f81de..0fd831f 100644 --- a/tests/testpkgs/pypi.nix +++ b/tests/testpkgs/pypi.nix @@ -1,4 +1,10 @@ -{ buildPythonPackage, fetchPypi, twisted, mock, pytestCheckHook }: +{ + buildPythonPackage, + fetchPypi, + twisted, + mock, + pytestCheckHook, +}: buildPythonPackage rec { pname = "python-mpd2"; diff --git a/tests/testpkgs/savanna.nix b/tests/testpkgs/savanna.nix index 63dc9a9..be0dcbb 100644 --- a/tests/testpkgs/savanna.nix +++ b/tests/testpkgs/savanna.nix @@ -1,4 +1,8 @@ -{ stdenv, fetchurl, gamin }: +{ + stdenv, + fetchurl, + gamin, +}: stdenv.mkDerivation rec { pname = "fileschanged"; diff --git a/tests/testpkgs/sourcehut.nix b/tests/testpkgs/sourcehut.nix index d3c6238..2495145 100644 --- a/tests/testpkgs/sourcehut.nix +++ b/tests/testpkgs/sourcehut.nix @@ -1,4 +1,12 @@ -{ buildGoModule, fetchFromSourcehut, lib, jq, installShellFiles, makeWrapper, scdoc }: +{ + buildGoModule, + fetchFromSourcehut, + lib, + jq, + installShellFiles, + makeWrapper, + scdoc, +}: buildGoModule rec { pname = "ijq"; @@ -13,9 +21,17 @@ buildGoModule rec { vendorHash = "sha256-7UuQXnQdlUMC0ZIgHydQ5bZMB5XrE7dhx5+1NI+zFkM="; - nativeBuildInputs = [ installShellFiles makeWrapper scdoc ]; + nativeBuildInputs = [ + installShellFiles + makeWrapper + scdoc + ]; - ldflags = [ "-s" "-w" "-X main.Version=${version}" ]; + ldflags = [ + "-s" + "-w" + "-X main.Version=${version}" + ]; postBuild = '' scdoc < ijq.1.scd > ijq.1 diff --git a/treefmt.nix b/treefmt.nix index e5b57ee..a6f5ab9 100644 --- a/treefmt.nix +++ b/treefmt.nix @@ -1,46 +1,28 @@ -{ lib, inputs, ... }: { - imports = [ - inputs.treefmt-nix.flakeModule - ]; +{ inputs, ... }: +{ + imports = [ inputs.treefmt-nix.flakeModule ]; - perSystem = { pkgs, ... }: { - treefmt = { - # Used to find the project root - projectRootFile = "flake.lock"; + perSystem = + { pkgs, ... }: + { + treefmt = { + # Used to find the project root + projectRootFile = "flake.lock"; - programs.prettier.enable = true; - programs.mypy.enable = true; + programs.deno.enable = + pkgs.lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.deno && !pkgs.deno.meta.broken; + programs.mypy.enable = true; - settings.formatter = { - nix = { - command = "sh"; - options = [ - "-eucx" - '' - # First deadnix - ${lib.getExe pkgs.deadnix} --edit "$@" - # Then nixpkgs-fmt - ${lib.getExe pkgs.nixpkgs-fmt} "$@" - '' - "--" - ]; - includes = [ "*.nix" ]; - excludes = [ "nix/sources.nix" ]; - }; + programs.yamlfmt.enable = true; - python = { - command = "sh"; - options = [ - "-eucx" - '' - ${lib.getExe pkgs.ruff} check "$@" - ${lib.getExe pkgs.ruff} format "$@" - '' - "--" # this argument is ignored by bash - ]; - includes = [ "*.py" ]; - }; + programs.nixfmt.enable = pkgs.lib.meta.availableOn pkgs.stdenv.buildPlatform pkgs.nixfmt-rfc-style.compiler; + programs.deadnix.enable = true; + programs.ruff.format = true; + programs.ruff.check = true; + + programs.shellcheck.enable = pkgs.lib.meta.availableOn pkgs.stdenv.buildPlatform pkgs.shellcheck.compiler; + programs.shfmt.enable = true; + settings.formatter.shfmt.includes = [ "*.envrc" ]; }; }; - }; }