Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize formatter #289

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 0 additions & 21 deletions .github/workflows/nix-fmt-checks.yaml

This file was deleted.

68 changes: 36 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -16,17 +16,18 @@ 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
- 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`
- 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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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`.
Expand All @@ -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.
6 changes: 3 additions & 3 deletions bin/create-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 [email protected]: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
Expand Down
10 changes: 7 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs ? import <nixpkgs> { }
{
pkgs ? import <nixpkgs> { },
}:


pkgs.python311.pkgs.buildPythonApplication {
pname = "nix-update";
version = "1.0.0";
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 37 additions & 26 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
);
}
23 changes: 13 additions & 10 deletions tests/testpkgs/bitbucket.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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=";
};
Expand Down
7 changes: 4 additions & 3 deletions tests/testpkgs/cargo-lock-generate/simple/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ python3Packages
, rustPlatform
, fetchFromGitHub
{
python3Packages,
rustPlatform,
fetchFromGitHub,
}:

python3Packages.buildPythonPackage rec {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ python3Packages
, rustPlatform
, fetchFromGitHub
{
python3Packages,
rustPlatform,
fetchFromGitHub,
}:

python3Packages.buildPythonPackage rec {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ python3Packages
, rustPlatform
, fetchFromGitHub
{
python3Packages,
rustPlatform,
fetchFromGitHub,
}:

python3Packages.buildPythonPackage rec {
Expand Down
Loading