Nixpkgs/Create and debug packages: Difference between revisions

imported>Tobias.bora
imported>Benediktbroich
Add the more modern nixpkgs-review as alternative to nox, add "good practices" Formatting with alejandra, add "good practices" tests with nixpkgs-hammering (Some things i picked up during my first pr)
Line 380: Line 380:
== Testing Package Updates with Nox ==
== Testing Package Updates with Nox ==


If you are updating a package's version, you can use nox to make sure all packages that depend on the updated package still compile correctly.
If you are updating a package's version, you can use [https://github.com/madjar/nox nox] to make sure all packages that depend on the updated package still compile correctly.


First make sure it is available in your shell:
First make sure it is available in your shell:
Line 396: Line 396:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
nox-review pr 5341
nox-review pr 5341
</syntaxhighlight>
== Testing Package Updates with nixpkgs-review ==
You can also use [https://github.com/Mic92/nixpkgs-review nixpkgs-review] to compile, review and merge packages and its dependencies. It claims to be faster than nox and provides a nix-shell where you can test the package.
First make sure it is available in your shell:
<syntaxhighlight lang="bash">
nix-shell -p nixpkgs-review
</syntaxhighlight>
You can run nixpkgs-review against uncommitted/staged changes in a cloned nixpkgs repository:
<syntaxhighlight lang="bash">
cd ~/git/nixpkgs
nixpkgs-review wip [--staged]
</syntaxhighlight>
It is also possible to review a specified commit:
<syntaxhighlight lang="bash">
cd ~/git/nixpkgs
nixpkgs-review rev HEAD
</syntaxhighlight>
If you have already committed your changes and created a pull request, you can use the pr command:
<syntaxhighlight lang="bash">
cd ~/git/nixpkgs
nixpkgs-review pr 5341
</syntaxhighlight>
You can post the build result, approve/merge or read the comments of a pull request inside the provided nix-shell:
<syntaxhighlight lang="bash">
# inside the provided shell
nixpkgs-review post-result
nixpkgs-review approve
nixpkgs-review merge
nixpkgs-review comments
</syntaxhighlight>
If the pr provides a new package you can start it inside the nix-shell using its package name:
<syntaxhighlight lang="bash">
# inside the provided shell
packagename
</syntaxhighlight>
== Formatting Packages with alejandra ==
It is "good practice" to format packages in a way that following changed will create as minimal diffs as possible. The formatter [https://github.com/kamadorueda/alejandra alejandra] can be used for that. The configuration can be found [https://github.com/kamadorueda/alejandra#features here]. You can read the explanation of the formatting choices [https://github.com/kamadorueda/alejandra/blob/main/STYLE.md here].
== Testing Packages with nixpkgs-hammering ==
You can test some "good practices" in a package with [https://github.com/jtojnar/nixpkgs-hammering nixpkgs-hammering]. But before applying the recommendations you should read the given [https://github.com/jtojnar/nixpkgs-hammering/tree/main/explanations explanations].
<syntaxhighlight lang="bash">
cd ~/git/nixpkgs
nix run -f https://github.com/jtojnar/nixpkgs-hammering/archive/master.tar.gz -c nixpkgs-hammer packagename # if you are using stable nix
nix run github:jtojnar/nixpkgs-hammering packagename # if you are using nix flake
</syntaxhighlight>
</syntaxhighlight>