From be26d79f464e8d656ad3cc49e085d35dbf758724 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 21 Jul 2023 19:19:31 +0200 Subject: [PATCH 01/42] doc/contributing: Remove unreferenced legacy diagram Not used anymore after b3fa79bb8965f7d3353daf99b137170314899a53 --- doc/contributing/staging-workflow.dot | 16 ---- doc/contributing/staging-workflow.svg | 102 -------------------------- 2 files changed, 118 deletions(-) delete mode 100644 doc/contributing/staging-workflow.dot delete mode 100644 doc/contributing/staging-workflow.svg diff --git a/doc/contributing/staging-workflow.dot b/doc/contributing/staging-workflow.dot deleted file mode 100644 index faca7a1cad4c..000000000000 --- a/doc/contributing/staging-workflow.dot +++ /dev/null @@ -1,16 +0,0 @@ -digraph { - "small changes" [shape=none] - "mass-rebuilds and other large changes" [shape=none] - "critical security fixes" [shape=none] - "broken staging-next fixes" [shape=none] - - "small changes" -> master - "mass-rebuilds and other large changes" -> staging - "critical security fixes" -> master - "broken staging-next fixes" -> "staging-next" - - "staging-next" -> master [color="#E85EB0"] [label="stabilization ends"] [fontcolor="#E85EB0"] - "staging" -> "staging-next" [color="#E85EB0"] [label="stabilization starts"] [fontcolor="#E85EB0"] - - master -> "staging-next" -> staging [color="#5F5EE8"] [label="every six hours (GitHub Action)"] [fontcolor="#5F5EE8"] -} diff --git a/doc/contributing/staging-workflow.svg b/doc/contributing/staging-workflow.svg deleted file mode 100644 index 1a174a78830e..000000000000 --- a/doc/contributing/staging-workflow.svg +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - -small changes -small changes - - - -master - -master - - - -small changes->master - - - - - -mass-rebuilds and other large changes -mass-rebuilds and other large changes - - - -staging - -staging - - - -mass-rebuilds and other large changes->staging - - - - - -critical security fixes -critical security fixes - - - -critical security fixes->master - - - - - -broken staging-next fixes -broken staging-next fixes - - - -staging-next - -staging-next - - - -broken staging-next fixes->staging-next - - - - - -master->staging-next - - -every six hours (GitHub Action) - - - -staging->staging-next - - -stabilization starts - - - -staging-next->master - - -stabilization ends - - - -staging-next->staging - - -every six hours (GitHub Action) - - - From d70091c3ad51b3fa25cd495e0f5e286d1ee5bac9 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 25 Jul 2023 16:56:42 +0200 Subject: [PATCH 02/42] Create unified markdown files for contributing docs --- CONTRIBUTING-new.md | 1 + doc/README.md | 3 +-- maintainers/README.md | 1 + nixos/{README => README.md} | 2 +- pkgs/README.md | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 CONTRIBUTING-new.md create mode 100644 maintainers/README.md rename nixos/{README => README.md} (92%) create mode 100644 pkgs/README.md diff --git a/CONTRIBUTING-new.md b/CONTRIBUTING-new.md new file mode 100644 index 000000000000..cbcab9ee1db7 --- /dev/null +++ b/CONTRIBUTING-new.md @@ -0,0 +1 @@ +# Contributing to Nixpkgs diff --git a/doc/README.md b/doc/README.md index 5395d7ca8f61..eea797403808 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1,5 +1,4 @@ - -# Nixpkgs/doc +# Contributing to the Nixpkgs manual This directory houses the sources files for the Nixpkgs manual. diff --git a/maintainers/README.md b/maintainers/README.md new file mode 100644 index 000000000000..8438533da143 --- /dev/null +++ b/maintainers/README.md @@ -0,0 +1 @@ +# Nixpkgs Maintainers diff --git a/nixos/README b/nixos/README.md similarity index 92% rename from nixos/README rename to nixos/README.md index ce4dd1988d2d..260209e94ee7 100644 --- a/nixos/README +++ b/nixos/README.md @@ -1,4 +1,4 @@ -*** NixOS *** +# NixOS NixOS is a Linux distribution based on the purely functional package management system Nix. More information can be found at diff --git a/pkgs/README.md b/pkgs/README.md new file mode 100644 index 000000000000..88180a953103 --- /dev/null +++ b/pkgs/README.md @@ -0,0 +1 @@ +# Contributing to Nixpkgs packages From b98abe51adcbde4a643a10845a2ace3cc57da4aa Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 25 Jul 2023 17:20:41 +0200 Subject: [PATCH 03/42] README.md: Rough move to new contribution doc files No content was changed, new titles are wrapped with () to signal that they will need to be decided on in a future commit. --- CONTRIBUTING-new.md | 23 +++++++++++++++++++++++ README.md | 21 +-------------------- maintainers/README.md | 6 ++++++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/CONTRIBUTING-new.md b/CONTRIBUTING-new.md index cbcab9ee1db7..41b3e73cb1fb 100644 --- a/CONTRIBUTING-new.md +++ b/CONTRIBUTING-new.md @@ -1 +1,24 @@ # Contributing to Nixpkgs + +## (Proposing a change) + +When pull requests are made, our tooling automation bot, +[OfBorg](https://github.com/NixOS/ofborg) will perform various checks +to help ensure expression quality. + +## (Merging a pull request) + +The *Nixpkgs committers* are people who have been given +permission to merge. + +## (Flow of changes) + +Most contributions are based on and merged into these branches: + +* `master` is the main branch where all small contributions go +* `staging` is branched from master, changes that have a big impact on + Hydra builds go to this branch +* `staging-next` is branched from staging and only fixes to stabilize + and security fixes with a big impact on Hydra builds should be + contributed to this branch. This branch is merged into master when + deemed of sufficiently high quality diff --git a/README.md b/README.md index d840e2a8c503..7284d39a4c13 100644 --- a/README.md +++ b/README.md @@ -70,26 +70,7 @@ Linux distribution. The [GitHub Insights](https://github.com/NixOS/nixpkgs/pulse page gives a sense of the project activity. Community contributions are always welcome through GitHub Issues and -Pull Requests. When pull requests are made, our tooling automation bot, -[OfBorg](https://github.com/NixOS/ofborg) will perform various checks -to help ensure expression quality. - -The *Nixpkgs maintainers* are people who have assigned themselves to -maintain specific individual packages. We encourage people who care -about a package to assign themselves as a maintainer. When a pull -request is made against a package, OfBorg will notify the appropriate -maintainer(s). The *Nixpkgs committers* are people who have been given -permission to merge. - -Most contributions are based on and merged into these branches: - -* `master` is the main branch where all small contributions go -* `staging` is branched from master, changes that have a big impact on - Hydra builds go to this branch -* `staging-next` is branched from staging and only fixes to stabilize - and security fixes with a big impact on Hydra builds should be - contributed to this branch. This branch is merged into master when - deemed of sufficiently high quality +Pull Requests. For more information about contributing to the project, please visit the [contributing page](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). diff --git a/maintainers/README.md b/maintainers/README.md index 8438533da143..3914586e5b61 100644 --- a/maintainers/README.md +++ b/maintainers/README.md @@ -1 +1,7 @@ # Nixpkgs Maintainers + +The *Nixpkgs maintainers* are people who have assigned themselves to +maintain specific individual packages. We encourage people who care +about a package to assign themselves as a maintainer. When a pull +request is made against a package, OfBorg will notify the appropriate +maintainer(s). From b7c525806e892ece8c4dec3b4b9cbc6e835d5a0b Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 25 Jul 2023 17:28:58 +0200 Subject: [PATCH 04/42] CONTRIBUTING.md: Rough move to new contribution doc files No content was changed, new titles are wrapped with () to signal that they will need to be decided on in a future commit. --- CONTRIBUTING-new.md | 140 +++++++++++++++++++++++++++++++++++++- CONTRIBUTING.md | 159 -------------------------------------------- pkgs/README.md | 26 ++++++++ 3 files changed, 165 insertions(+), 160 deletions(-) diff --git a/CONTRIBUTING-new.md b/CONTRIBUTING-new.md index 41b3e73cb1fb..492bd6e82643 100644 --- a/CONTRIBUTING-new.md +++ b/CONTRIBUTING-new.md @@ -1,11 +1,149 @@ # Contributing to Nixpkgs -## (Proposing a change) +## (Proposing a change) | Submitting changes + +Note: contributing implies licensing those contributions +under the terms of [COPYING](COPYING), which is an MIT-like license. + +* Format the commit messages in the following way: + + ``` + (pkg-name | nixos/): (from -> to | init at version | refactor | etc) + + (Motivation for change. Link to release notes. Additional information.) + ``` + + For consistency, there should not be a period at the end of the commit message's summary line (the first line of the commit message). + + Examples: + + * nginx: init at 2.0.1 + * firefox: 54.0.1 -> 55.0 + https://www.mozilla.org/en-US/firefox/55.0/releasenotes/ + * nixos/hydra: add bazBaz option + + Dual baz behavior is needed to do foo. + * nixos/nginx: refactor config generation + + The old config generation system used impure shell scripts and could break in specific circumstances (see #1234). + + +### Writing good commit messages + +In addition to writing properly formatted commit messages, it's important to include relevant information so other developers can later understand *why* a change was made. While this information usually can be found by digging code, mailing list/Discourse archives, pull request discussions or upstream changes, it may require a lot of work. + +Package version upgrades usually allow for simpler commit messages, including attribute name, old and new version, as well as a reference to the relevant release notes/changelog. Every once in a while a package upgrade requires more extensive changes, and that subsequently warrants a more verbose message. + +Pull requests should not be squash merged in order to keep complete commit messages and GPG signatures intact and must not be when the change doesn't make sense as a single commit. +This means that, when addressing review comments in order to keep the pull request in an always mergeable status, you will sometimes need to rewrite your branch's history and then force-push it with `git push --force-with-lease`. +Useful git commands that can help a lot with this are `git commit --patch --amend` and `git rebase --interactive`. For more details consult the git man pages or online resources like [git-rebase.io](https://git-rebase.io/) or [The Pro Git Book](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). + +### (Creating a pull request) When pull requests are made, our tooling automation bot, [OfBorg](https://github.com/NixOS/ofborg) will perform various checks to help ensure expression quality. +#### Rebasing between branches (i.e. from master to staging) + +From time to time, changes between branches must be rebased, for example, if the +number of new rebuilds they would cause is too large for the target branch. When +rebasing, care must be taken to include only the intended changes, otherwise +many CODEOWNERS will be inadvertently requested for review. To achieve this, +rebasing should not be performed directly on the target branch, but on the merge +base between the current and target branch. As an additional precautionary measure, +you should temporarily mark the PR as draft for the duration of the operation. +This reduces the probability of mass-pinging people. (OfBorg might still +request a couple of persons for reviews though.) + +In the following example, we assume that the current branch, called `feature`, +is based on `master`, and we rebase it onto the merge base between +`master` and `staging` so that the PR can eventually be retargeted to +`staging` without causing a mess. The example uses `upstream` as the remote for `NixOS/nixpkgs.git` +while `origin` is the remote you are pushing to. + + +```console +# Rebase your commits onto the common merge base +git rebase --onto upstream/staging... upstream/master +# Force push your changes +git push origin feature --force-with-lease +``` + +The syntax `upstream/staging...` is equivalent to `upstream/staging...HEAD` and +stands for the merge base between `upstream/staging` and `HEAD` (hence between +`upstream/staging` and `upstream/master`). + +Then change the base branch in the GitHub PR using the *Edit* button in the upper +right corner, and switch from `master` to `staging`. *After* the PR has been +retargeted it might be necessary to do a final rebase onto the target branch, to +resolve any outstanding merge conflicts. + +```console +# Rebase onto target branch +git rebase upstream/staging +# Review and fixup possible conflicts +git status +# Force push your changes +git push origin feature --force-with-lease +``` + +##### Something went wrong and a lot of people were pinged + +It happens. Remember to be kind, especially to new contributors. +There is no way back, so the pull request should be closed and locked +(if possible). The changes should be re-submitted in a new PR, in which the people +originally involved in the conversation need to manually be pinged again. +No further discussion should happen on the original PR, as a lot of people +are now subscribed to it. + +The following message (or a version thereof) might be left when closing to +describe the situation, since closing and locking without any explanation +is kind of rude: + +```markdown +It looks like you accidentally mass-pinged a bunch of people, which are now subscribed +and getting notifications for everything in this pull request. Unfortunately, they +cannot be automatically unsubscribed from the issue (removing review request does not +unsubscribe), therefore development cannot continue in this pull request anymore. + +Please open a new pull request with your changes, link back to this one and ping the +people actually involved in here over there. + +In order to avoid this in the future, there are instructions for how to properly +rebase between branches in our [contribution guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#rebasing-between-branches-ie-from-master-to-staging). +Setting your pull request to draft prior to rebasing is strongly recommended. +In draft status, you can preview the list of people that are about to be requested +for review, which allows you to sidestep this issue. +This is not a bulletproof method though, as OfBorg still does review requests even on draft PRs. +``` + +### Backporting changes + +Follow these steps to backport a change into a release branch in compliance with the [commit policy](https://nixos.org/nixpkgs/manual/#submitting-changes-stable-release-branches). + +You can add a label such as `backport release-23.05` to a PR, so that merging it will +automatically create a backport (via [a GitHub Action](.github/workflows/backport.yml)). +This also works for pull requests that have already been merged, and might take a couple of minutes to trigger. + +You can also create the backport manually: + +1. Take note of the commits in which the change was introduced into `master` branch. +2. Check out the target _release branch_, e.g. `release-23.05`. Do not use a _channel branch_ like `nixos-23.05` or `nixpkgs-23.05-darwin`. +3. Create a branch for your change, e.g. `git checkout -b backport`. +4. When the reason to backport is not obvious from the original commit message, use `git cherry-pick -xe ` and add a reason. Otherwise use `git cherry-pick -x `. That's fine for minor version updates that only include security and bug fixes, commits that fixes an otherwise broken package or similar. Please also ensure the commits exists on the master branch; in the case of squashed or rebased merges, the commit hash will change and the new commits can be found in the merge message at the bottom of the master pull request. +5. Push to GitHub and open a backport pull request. Make sure to select the release branch (e.g. `release-23.05`) as the target branch of the pull request, and link to the pull request in which the original change was committed to `master`. The pull request title should be the commit title with the release version as prefix, e.g. `[23.05]`. +6. When the backport pull request is merged and you have the necessary privileges you can also replace the label `9.needs: port to stable` with `8.has: port to stable` on the original pull request. This way maintainers can keep track of missing backports easier. + +#### Criteria for Backporting changes + +Anything that does not cause user or downstream dependency regressions can be backported. This includes: +- New Packages / Modules +- Security / Patch updates +- Version updates which include new functionality (but no breaking changes) +- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) +- Security critical applications (E.g. `firefox`) + ## (Merging a pull request) The *Nixpkgs committers* are people who have been given diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0734db52129f..95d23e3f7ed1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,8 +1,5 @@ # How to contribute -Note: contributing implies licensing those contributions -under the terms of [COPYING](COPYING), which is an MIT-like license. - ## Opening issues * Make sure you have a [GitHub account](https://github.com/signup/free) @@ -15,162 +12,6 @@ Read the ["Submitting changes"](https://nixos.org/nixpkgs/manual/#chap-submittin Below is a short excerpt of some points in there: -* Format the commit messages in the following way: - - ``` - (pkg-name | nixos/): (from -> to | init at version | refactor | etc) - - (Motivation for change. Link to release notes. Additional information.) - ``` - - For consistency, there should not be a period at the end of the commit message's summary line (the first line of the commit message). - - Examples: - - * nginx: init at 2.0.1 - * firefox: 54.0.1 -> 55.0 - https://www.mozilla.org/en-US/firefox/55.0/releasenotes/ - * nixos/hydra: add bazBaz option - - Dual baz behavior is needed to do foo. - * nixos/nginx: refactor config generation - - The old config generation system used impure shell scripts and could break in specific circumstances (see #1234). - -* `meta.description` must: - * Be short, just one sentence. - * Be capitalized. - * Not start with the package name. - * More generally, it should not refer to the package name. - * Not end with a period (or any punctuation for that matter). - * Aim to inform while avoiding subjective language. -* `meta.license` must be set and fit the upstream license. - * If there is no upstream license, `meta.license` should default to `lib.licenses.unfree`. - * If in doubt, try to contact the upstream developers for clarification. -* `meta.mainProgram` must be set when appropriate. -* `meta.maintainers` should be set. - -See the nixpkgs manual for more details on [standard meta-attributes](https://nixos.org/nixpkgs/manual/#sec-standard-meta-attributes). - -## Writing good commit messages - -In addition to writing properly formatted commit messages, it's important to include relevant information so other developers can later understand *why* a change was made. While this information usually can be found by digging code, mailing list/Discourse archives, pull request discussions or upstream changes, it may require a lot of work. - -Package version upgrades usually allow for simpler commit messages, including attribute name, old and new version, as well as a reference to the relevant release notes/changelog. Every once in a while a package upgrade requires more extensive changes, and that subsequently warrants a more verbose message. - -Pull requests should not be squash merged in order to keep complete commit messages and GPG signatures intact and must not be when the change doesn't make sense as a single commit. -This means that, when addressing review comments in order to keep the pull request in an always mergeable status, you will sometimes need to rewrite your branch's history and then force-push it with `git push --force-with-lease`. -Useful git commands that can help a lot with this are `git commit --patch --amend` and `git rebase --interactive`. For more details consult the git man pages or online resources like [git-rebase.io](https://git-rebase.io/) or [The Pro Git Book](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). - -## Testing changes - -To run the main types of tests locally: - -- Run package-internal tests with `nix-build --attr pkgs.PACKAGE.passthru.tests` -- Run [NixOS tests](https://nixos.org/manual/nixos/unstable/#sec-nixos-tests) with `nix-build --attr nixosTest.NAME`, where `NAME` is the name of the test listed in `nixos/tests/all-tests.nix` -- Run [global package tests](https://nixos.org/manual/nixpkgs/unstable/#sec-package-tests) with `nix-build --attr tests.PACKAGE`, where `PACKAGE` is the name of the test listed in `pkgs/test/default.nix` -- See `lib/tests/NAME.nix` for instructions on running specific library tests - -## Rebasing between branches (i.e. from master to staging) - -From time to time, changes between branches must be rebased, for example, if the -number of new rebuilds they would cause is too large for the target branch. When -rebasing, care must be taken to include only the intended changes, otherwise -many CODEOWNERS will be inadvertently requested for review. To achieve this, -rebasing should not be performed directly on the target branch, but on the merge -base between the current and target branch. As an additional precautionary measure, -you should temporarily mark the PR as draft for the duration of the operation. -This reduces the probability of mass-pinging people. (OfBorg might still -request a couple of persons for reviews though.) - -In the following example, we assume that the current branch, called `feature`, -is based on `master`, and we rebase it onto the merge base between -`master` and `staging` so that the PR can eventually be retargeted to -`staging` without causing a mess. The example uses `upstream` as the remote for `NixOS/nixpkgs.git` -while `origin` is the remote you are pushing to. - - -```console -# Rebase your commits onto the common merge base -git rebase --onto upstream/staging... upstream/master -# Force push your changes -git push origin feature --force-with-lease -``` - -The syntax `upstream/staging...` is equivalent to `upstream/staging...HEAD` and -stands for the merge base between `upstream/staging` and `HEAD` (hence between -`upstream/staging` and `upstream/master`). - -Then change the base branch in the GitHub PR using the *Edit* button in the upper -right corner, and switch from `master` to `staging`. *After* the PR has been -retargeted it might be necessary to do a final rebase onto the target branch, to -resolve any outstanding merge conflicts. - -```console -# Rebase onto target branch -git rebase upstream/staging -# Review and fixup possible conflicts -git status -# Force push your changes -git push origin feature --force-with-lease -``` - -### Something went wrong and a lot of people were pinged - -It happens. Remember to be kind, especially to new contributors. -There is no way back, so the pull request should be closed and locked -(if possible). The changes should be re-submitted in a new PR, in which the people -originally involved in the conversation need to manually be pinged again. -No further discussion should happen on the original PR, as a lot of people -are now subscribed to it. - -The following message (or a version thereof) might be left when closing to -describe the situation, since closing and locking without any explanation -is kind of rude: - -```markdown -It looks like you accidentally mass-pinged a bunch of people, which are now subscribed -and getting notifications for everything in this pull request. Unfortunately, they -cannot be automatically unsubscribed from the issue (removing review request does not -unsubscribe), therefore development cannot continue in this pull request anymore. - -Please open a new pull request with your changes, link back to this one and ping the -people actually involved in here over there. - -In order to avoid this in the future, there are instructions for how to properly -rebase between branches in our [contribution guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#rebasing-between-branches-ie-from-master-to-staging). -Setting your pull request to draft prior to rebasing is strongly recommended. -In draft status, you can preview the list of people that are about to be requested -for review, which allows you to sidestep this issue. -This is not a bulletproof method though, as OfBorg still does review requests even on draft PRs. -``` - -## Backporting changes - -Follow these steps to backport a change into a release branch in compliance with the [commit policy](https://nixos.org/nixpkgs/manual/#submitting-changes-stable-release-branches). - -You can add a label such as `backport release-23.05` to a PR, so that merging it will -automatically create a backport (via [a GitHub Action](.github/workflows/backport.yml)). -This also works for pull requests that have already been merged, and might take a couple of minutes to trigger. - -You can also create the backport manually: - -1. Take note of the commits in which the change was introduced into `master` branch. -2. Check out the target _release branch_, e.g. `release-23.05`. Do not use a _channel branch_ like `nixos-23.05` or `nixpkgs-23.05-darwin`. -3. Create a branch for your change, e.g. `git checkout -b backport`. -4. When the reason to backport is not obvious from the original commit message, use `git cherry-pick -xe ` and add a reason. Otherwise use `git cherry-pick -x `. That's fine for minor version updates that only include security and bug fixes, commits that fixes an otherwise broken package or similar. Please also ensure the commits exists on the master branch; in the case of squashed or rebased merges, the commit hash will change and the new commits can be found in the merge message at the bottom of the master pull request. -5. Push to GitHub and open a backport pull request. Make sure to select the release branch (e.g. `release-23.05`) as the target branch of the pull request, and link to the pull request in which the original change was committed to `master`. The pull request title should be the commit title with the release version as prefix, e.g. `[23.05]`. -6. When the backport pull request is merged and you have the necessary privileges you can also replace the label `9.needs: port to stable` with `8.has: port to stable` on the original pull request. This way maintainers can keep track of missing backports easier. - -## Criteria for Backporting changes - -Anything that does not cause user or downstream dependency regressions can be backported. This includes: -- New Packages / Modules -- Security / Patch updates -- Version updates which include new functionality (but no breaking changes) -- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) -- Security critical applications (E.g. `firefox`) - ## Reviewing contributions See the nixpkgs manual for more details on how to [Review contributions](https://nixos.org/nixpkgs/manual/#chap-reviewing-contributions). diff --git a/pkgs/README.md b/pkgs/README.md index 88180a953103..ab7bf29a1a62 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -1 +1,27 @@ # Contributing to Nixpkgs packages + +## (Conventions) + +* `meta.description` must: + * Be short, just one sentence. + * Be capitalized. + * Not start with the package name. + * More generally, it should not refer to the package name. + * Not end with a period (or any punctuation for that matter). + * Aim to inform while avoiding subjective language. +* `meta.license` must be set and fit the upstream license. + * If there is no upstream license, `meta.license` should default to `lib.licenses.unfree`. + * If in doubt, try to contact the upstream developers for clarification. +* `meta.mainProgram` must be set when appropriate. +* `meta.maintainers` should be set. + +See the nixpkgs manual for more details on [standard meta-attributes](https://nixos.org/nixpkgs/manual/#sec-standard-meta-attributes). + +## Testing changes + +To run the main types of tests locally: + +- Run package-internal tests with `nix-build --attr pkgs.PACKAGE.passthru.tests` +- Run [NixOS tests](https://nixos.org/manual/nixos/unstable/#sec-nixos-tests) with `nix-build --attr nixosTest.NAME`, where `NAME` is the name of the test listed in `nixos/tests/all-tests.nix` +- Run [global package tests](https://nixos.org/manual/nixpkgs/unstable/#sec-package-tests) with `nix-build --attr tests.PACKAGE`, where `PACKAGE` is the name of the test listed in `pkgs/test/default.nix` +- See `lib/tests/NAME.nix` for instructions on running specific library tests From 1e1cd398d44942f054531ac806ff370a09129c1a Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 25 Jul 2023 17:48:35 +0200 Subject: [PATCH 05/42] doc/coding-conventions: Rough move to new contribution doc files No content was changed, new titles are wrapped with () to signal that they will need to be decided on in a future commit. Section in the manual have been preserved with a simple redirect to GitHub, the proper anchors should be filled out in a future commit once the new section names are decided. --- CONTRIBUTING-new.md | 205 ++++++ .../coding-conventions.chapter.md | 664 +----------------- pkgs/README.md | 494 ++++++++++++- 3 files changed, 715 insertions(+), 648 deletions(-) diff --git a/CONTRIBUTING-new.md b/CONTRIBUTING-new.md index 492bd6e82643..46b08333a71d 100644 --- a/CONTRIBUTING-new.md +++ b/CONTRIBUTING-new.md @@ -160,3 +160,208 @@ Most contributions are based on and merged into these branches: and security fixes with a big impact on Hydra builds should be contributed to this branch. This branch is merged into master when deemed of sufficiently high quality + +## Coding conventions {#chap-conventions} + +### File naming and organisation {#sec-organisation} + +Names of files and directories should be in lowercase, with dashes between words — not in camel case. For instance, it should be `all-packages.nix`, not `allPackages.nix` or `AllPackages.nix`. + +### Syntax {#sec-syntax} + +- Use 2 spaces of indentation per indentation level in Nix expressions, 4 spaces in shell scripts. + +- Do not use tab characters, i.e. configure your editor to use soft tabs. For instance, use `(setq-default indent-tabs-mode nil)` in Emacs. Everybody has different tab settings so it’s asking for trouble. + +- Use `lowerCamelCase` for variable names, not `UpperCamelCase`. Note, this rule does not apply to package attribute names, which instead follow the rules in [](#sec-package-naming). + +- Function calls with attribute set arguments are written as + + ```nix + foo { + arg = ...; + } + ``` + + not + + ```nix + foo + { + arg = ...; + } + ``` + + Also fine is + + ```nix + foo { arg = ...; } + ``` + + if it's a short call. + +- In attribute sets or lists that span multiple lines, the attribute names or list elements should be aligned: + + ```nix + # A long list. + list = [ + elem1 + elem2 + elem3 + ]; + + # A long attribute set. + attrs = { + attr1 = short_expr; + attr2 = + if true then big_expr else big_expr; + }; + + # Combined + listOfAttrs = [ + { + attr1 = 3; + attr2 = "fff"; + } + { + attr1 = 5; + attr2 = "ggg"; + } + ]; + ``` + +- Short lists or attribute sets can be written on one line: + + ```nix + # A short list. + list = [ elem1 elem2 elem3 ]; + + # A short set. + attrs = { x = 1280; y = 1024; }; + ``` + +- Breaking in the middle of a function argument can give hard-to-read code, like + + ```nix + someFunction { x = 1280; + y = 1024; } otherArg + yetAnotherArg + ``` + + (especially if the argument is very large, spanning multiple lines). + + Better: + + ```nix + someFunction + { x = 1280; y = 1024; } + otherArg + yetAnotherArg + ``` + + or + + ```nix + let res = { x = 1280; y = 1024; }; + in someFunction res otherArg yetAnotherArg + ``` + +- The bodies of functions, asserts, and withs are not indented to prevent a lot of superfluous indentation levels, i.e. + + ```nix + { arg1, arg2 }: + assert system == "i686-linux"; + stdenv.mkDerivation { ... + ``` + + not + + ```nix + { arg1, arg2 }: + assert system == "i686-linux"; + stdenv.mkDerivation { ... + ``` + +- Function formal arguments are written as: + + ```nix + { arg1, arg2, arg3 }: + ``` + + but if they don't fit on one line they're written as: + + ```nix + { arg1, arg2, arg3 + , arg4, ... + , # Some comment... + argN + }: + ``` + +- Functions should list their expected arguments as precisely as possible. That is, write + + ```nix + { stdenv, fetchurl, perl }: ... + ``` + + instead of + + ```nix + args: with args; ... + ``` + + or + + ```nix + { stdenv, fetchurl, perl, ... }: ... + ``` + + For functions that are truly generic in the number of arguments (such as wrappers around `mkDerivation`) that have some required arguments, you should write them using an `@`-pattern: + + ```nix + { stdenv, doCoverageAnalysis ? false, ... } @ args: + + stdenv.mkDerivation (args // { + ... if doCoverageAnalysis then "bla" else "" ... + }) + ``` + + instead of + + ```nix + args: + + args.stdenv.mkDerivation (args // { + ... if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else "" ... + }) + ``` + +- Unnecessary string conversions should be avoided. Do + + ```nix + rev = version; + ``` + + instead of + + ```nix + rev = "${version}"; + ``` + +- Building lists conditionally _should_ be done with `lib.optional(s)` instead of using `if cond then [ ... ] else null` or `if cond then [ ... ] else [ ]`. + + ```nix + buildInputs = lib.optional stdenv.isDarwin iconv; + ``` + + instead of + + ```nix + buildInputs = if stdenv.isDarwin then [ iconv ] else null; + ``` + + As an exception, an explicit conditional expression with null can be used when fixing a important bug without triggering a mass rebuild. + If this is done a follow up pull request _should_ be created to change the code to `lib.optional(s)`. + +- Arguments should be listed in the order they are used, with the exception of `lib`, which always goes first. + diff --git a/doc/contributing/coding-conventions.chapter.md b/doc/contributing/coding-conventions.chapter.md index eb9932d48b68..3afa6140c6cd 100644 --- a/doc/contributing/coding-conventions.chapter.md +++ b/doc/contributing/coding-conventions.chapter.md @@ -1,693 +1,63 @@ # Coding conventions {#chap-conventions} +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). + ## Syntax {#sec-syntax} -- Use 2 spaces of indentation per indentation level in Nix expressions, 4 spaces in shell scripts. - -- Do not use tab characters, i.e. configure your editor to use soft tabs. For instance, use `(setq-default indent-tabs-mode nil)` in Emacs. Everybody has different tab settings so it’s asking for trouble. - -- Use `lowerCamelCase` for variable names, not `UpperCamelCase`. Note, this rule does not apply to package attribute names, which instead follow the rules in [](#sec-package-naming). - -- Function calls with attribute set arguments are written as - - ```nix - foo { - arg = ...; - } - ``` - - not - - ```nix - foo - { - arg = ...; - } - ``` - - Also fine is - - ```nix - foo { arg = ...; } - ``` - - if it's a short call. - -- In attribute sets or lists that span multiple lines, the attribute names or list elements should be aligned: - - ```nix - # A long list. - list = [ - elem1 - elem2 - elem3 - ]; - - # A long attribute set. - attrs = { - attr1 = short_expr; - attr2 = - if true then big_expr else big_expr; - }; - - # Combined - listOfAttrs = [ - { - attr1 = 3; - attr2 = "fff"; - } - { - attr1 = 5; - attr2 = "ggg"; - } - ]; - ``` - -- Short lists or attribute sets can be written on one line: - - ```nix - # A short list. - list = [ elem1 elem2 elem3 ]; - - # A short set. - attrs = { x = 1280; y = 1024; }; - ``` - -- Breaking in the middle of a function argument can give hard-to-read code, like - - ```nix - someFunction { x = 1280; - y = 1024; } otherArg - yetAnotherArg - ``` - - (especially if the argument is very large, spanning multiple lines). - - Better: - - ```nix - someFunction - { x = 1280; y = 1024; } - otherArg - yetAnotherArg - ``` - - or - - ```nix - let res = { x = 1280; y = 1024; }; - in someFunction res otherArg yetAnotherArg - ``` - -- The bodies of functions, asserts, and withs are not indented to prevent a lot of superfluous indentation levels, i.e. - - ```nix - { arg1, arg2 }: - assert system == "i686-linux"; - stdenv.mkDerivation { ... - ``` - - not - - ```nix - { arg1, arg2 }: - assert system == "i686-linux"; - stdenv.mkDerivation { ... - ``` - -- Function formal arguments are written as: - - ```nix - { arg1, arg2, arg3 }: - ``` - - but if they don't fit on one line they're written as: - - ```nix - { arg1, arg2, arg3 - , arg4, ... - , # Some comment... - argN - }: - ``` - -- Functions should list their expected arguments as precisely as possible. That is, write - - ```nix - { stdenv, fetchurl, perl }: ... - ``` - - instead of - - ```nix - args: with args; ... - ``` - - or - - ```nix - { stdenv, fetchurl, perl, ... }: ... - ``` - - For functions that are truly generic in the number of arguments (such as wrappers around `mkDerivation`) that have some required arguments, you should write them using an `@`-pattern: - - ```nix - { stdenv, doCoverageAnalysis ? false, ... } @ args: - - stdenv.mkDerivation (args // { - ... if doCoverageAnalysis then "bla" else "" ... - }) - ``` - - instead of - - ```nix - args: - - args.stdenv.mkDerivation (args // { - ... if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else "" ... - }) - ``` - -- Unnecessary string conversions should be avoided. Do - - ```nix - rev = version; - ``` - - instead of - - ```nix - rev = "${version}"; - ``` - -- Building lists conditionally _should_ be done with `lib.optional(s)` instead of using `if cond then [ ... ] else null` or `if cond then [ ... ] else [ ]`. - - ```nix - buildInputs = lib.optional stdenv.isDarwin iconv; - ``` - - instead of - - ```nix - buildInputs = if stdenv.isDarwin then [ iconv ] else null; - ``` - - As an exception, an explicit conditional expression with null can be used when fixing a important bug without triggering a mass rebuild. - If this is done a follow up pull request _should_ be created to change the code to `lib.optional(s)`. - -- Arguments should be listed in the order they are used, with the exception of `lib`, which always goes first. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ## Package naming {#sec-package-naming} -The key words _must_, _must not_, _required_, _shall_, _shall not_, _should_, _should not_, _recommended_, _may_, and _optional_ in this section are to be interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119). Only _emphasized_ words are to be interpreted in this way. - -In Nixpkgs, there are generally three different names associated with a package: - -- The `pname` attribute of the derivation. This is what most users see, in particular when using `nix-env`. - -- The variable name used for the instantiated package in `all-packages.nix`, and when passing it as a dependency to other functions. Typically this is called the _package attribute name_. This is what Nix expression authors see. It can also be used when installing using `nix-env -iA`. - -- The filename for (the directory containing) the Nix expression. - -Most of the time, these are the same. For instance, the package `e2fsprogs` has a `pname` attribute `"e2fsprogs"`, is bound to the variable name `e2fsprogs` in `all-packages.nix`, and the Nix expression is in `pkgs/os-specific/linux/e2fsprogs/default.nix`. - -There are a few naming guidelines: - -- The `pname` attribute _should_ be identical to the upstream package name. - -- The `pname` and the `version` attribute _must not_ contain uppercase letters — e.g., `"mplayer" instead of `"MPlayer"`. - -- The `version` attribute _must_ start with a digit e.g`"0.3.1rc2". - -- If a package is a commit from a repository without a version assigned, then the `version` attribute _should_ be the latest upstream version preceding that commit, followed by `-unstable-` and the date of the (fetched) commit. The date _must_ be in `"YYYY-MM-DD"` format. - -Example: Given a project had its latest releases `2.2` in November 2021, and `3.0` in January 2022, a commit authored on March 15, 2022 for an upcoming bugfix release `2.2.1` would have `version = "2.2-unstable-2022-03-15"`. - -- Dashes in the package `pname` _should_ be preserved in new variable names, rather than converted to underscores or camel cased — e.g., `http-parser` instead of `http_parser` or `httpParser`. The hyphenated style is preferred in all three package names. - -- If there are multiple versions of a package, this _should_ be reflected in the variable names in `all-packages.nix`, e.g. `json-c_0_9` and `json-c_0_11`. If there is an obvious “default” version, make an attribute like `json-c = json-c_0_9;`. See also [](#sec-versioning) +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ## File naming and organisation {#sec-organisation} -Names of files and directories should be in lowercase, with dashes between words — not in camel case. For instance, it should be `all-packages.nix`, not `allPackages.nix` or `AllPackages.nix`. - -### Hierarchy {#sec-hierarchy} - -Each package should be stored in its own directory somewhere in the `pkgs/` tree, i.e. in `pkgs/category/subcategory/.../pkgname`. Below are some rules for picking the right category for a package. Many packages fall under several categories; what matters is the _primary_ purpose of a package. For example, the `libxml2` package builds both a library and some tools; but it’s a library foremost, so it goes under `pkgs/development/libraries`. - -When in doubt, consider refactoring the `pkgs/` tree, e.g. creating new categories or splitting up an existing category. - -**If it’s used to support _software development_:** - -- **If it’s a _library_ used by other packages:** - - - `development/libraries` (e.g. `libxml2`) - -- **If it’s a _compiler_:** - - - `development/compilers` (e.g. `gcc`) - -- **If it’s an _interpreter_:** - - - `development/interpreters` (e.g. `guile`) - -- **If it’s a (set of) development _tool(s)_:** - - - **If it’s a _parser generator_ (including lexers):** - - - `development/tools/parsing` (e.g. `bison`, `flex`) - - - **If it’s a _build manager_:** - - - `development/tools/build-managers` (e.g. `gnumake`) - - - **If it’s a _language server_:** - - - `development/tools/language-servers` (e.g. `ccls` or `rnix-lsp`) - - - **Else:** - - - `development/tools/misc` (e.g. `binutils`) - -- **Else:** - - - `development/misc` - -**If it’s a (set of) _tool(s)_:** - -(A tool is a relatively small program, especially one intended to be used non-interactively.) - -- **If it’s for _networking_:** - - - `tools/networking` (e.g. `wget`) - -- **If it’s for _text processing_:** - - - `tools/text` (e.g. `diffutils`) - -- **If it’s a _system utility_, i.e., something related or essential to the operation of a system:** - - - `tools/system` (e.g. `cron`) - -- **If it’s an _archiver_ (which may include a compression function):** - - - `tools/archivers` (e.g. `zip`, `tar`) - -- **If it’s a _compression_ program:** - - - `tools/compression` (e.g. `gzip`, `bzip2`) - -- **If it’s a _security_-related program:** - - - `tools/security` (e.g. `nmap`, `gnupg`) - -- **Else:** - - - `tools/misc` - -**If it’s a _shell_:** - -- `shells` (e.g. `bash`) - -**If it’s a _server_:** - -- **If it’s a web server:** - - - `servers/http` (e.g. `apache-httpd`) - -- **If it’s an implementation of the X Windowing System:** - - - `servers/x11` (e.g. `xorg` — this includes the client libraries and programs) - -- **Else:** - - - `servers/misc` - -**If it’s a _desktop environment_:** - -- `desktops` (e.g. `kde`, `gnome`, `enlightenment`) - -**If it’s a _window manager_:** - -- `applications/window-managers` (e.g. `awesome`, `stumpwm`) - -**If it’s an _application_:** - -A (typically large) program with a distinct user interface, primarily used interactively. - -- **If it’s a _version management system_:** - - - `applications/version-management` (e.g. `subversion`) - -- **If it’s a _terminal emulator_:** - - - `applications/terminal-emulators` (e.g. `alacritty` or `rxvt` or `termite`) - -- **If it’s a _file manager_:** - - - `applications/file-managers` (e.g. `mc` or `ranger` or `pcmanfm`) - -- **If it’s for _video playback / editing_:** - - - `applications/video` (e.g. `vlc`) - -- **If it’s for _graphics viewing / editing_:** - - - `applications/graphics` (e.g. `gimp`) - -- **If it’s for _networking_:** - - - **If it’s a _mailreader_:** - - - `applications/networking/mailreaders` (e.g. `thunderbird`) - - - **If it’s a _newsreader_:** - - - `applications/networking/newsreaders` (e.g. `pan`) - - - **If it’s a _web browser_:** - - - `applications/networking/browsers` (e.g. `firefox`) - - - **Else:** - - - `applications/networking/misc` - -- **Else:** - - - `applications/misc` - -**If it’s _data_ (i.e., does not have a straight-forward executable semantics):** - -- **If it’s a _font_:** - - - `data/fonts` - -- **If it’s an _icon theme_:** - - - `data/icons` - -- **If it’s related to _SGML/XML processing_:** - - - **If it’s an _XML DTD_:** - - - `data/sgml+xml/schemas/xml-dtd` (e.g. `docbook`) - - - **If it’s an _XSLT stylesheet_:** - - (Okay, these are executable...) - - - `data/sgml+xml/stylesheets/xslt` (e.g. `docbook-xsl`) - -- **If it’s a _theme_ for a _desktop environment_, a _window manager_ or a _display manager_:** - - - `data/themes` - -**If it’s a _game_:** - -- `games` - -**Else:** - -- `misc` +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ### Versioning {#sec-versioning} -Because every version of a package in Nixpkgs creates a potential maintenance burden, old versions of a package should not be kept unless there is a good reason to do so. For instance, Nixpkgs contains several versions of GCC because other packages don’t build with the latest version of GCC. Other examples are having both the latest stable and latest pre-release version of a package, or to keep several major releases of an application that differ significantly in functionality. - -If there is only one version of a package, its Nix expression should be named `e2fsprogs/default.nix`. If there are multiple versions, this should be reflected in the filename, e.g. `e2fsprogs/1.41.8.nix` and `e2fsprogs/1.41.9.nix`. The version in the filename should leave out unnecessary detail. For instance, if we keep the latest Firefox 2.0.x and 3.5.x versions in Nixpkgs, they should be named `firefox/2.0.nix` and `firefox/3.5.nix`, respectively (which, at a given point, might contain versions `2.0.0.20` and `3.5.4`). If a version requires many auxiliary files, you can use a subdirectory for each version, e.g. `firefox/2.0/default.nix` and `firefox/3.5/default.nix`. - -All versions of a package _must_ be included in `all-packages.nix` to make sure that they evaluate correctly. +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ## Fetching Sources {#sec-sources} -There are multiple ways to fetch a package source in nixpkgs. The general guideline is that you should package reproducible sources with a high degree of availability. Right now there is only one fetcher which has mirroring support and that is `fetchurl`. Note that you should also prefer protocols which have a corresponding proxy environment variable. - -You can find many source fetch helpers in `pkgs/build-support/fetch*`. - -In the file `pkgs/top-level/all-packages.nix` you can find fetch helpers, these have names on the form `fetchFrom*`. The intention of these are to provide snapshot fetches but using the same api as some of the version controlled fetchers from `pkgs/build-support/`. As an example going from bad to good: - -- Bad: Uses `git://` which won't be proxied. - - ```nix - src = fetchgit { - url = "git@github.com:NixOS/nix.git" - url = "git://github.com/NixOS/nix.git"; - rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae"; - hash = "sha256-7D4m+saJjbSFP5hOwpQq2FGR2rr+psQMTcyb1ZvtXsQ="; - } - ``` - -- Better: This is ok, but an archive fetch will still be faster. - - ```nix - src = fetchgit { - url = "https://github.com/NixOS/nix.git"; - rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae"; - hash = "sha256-7D4m+saJjbSFP5hOwpQq2FGR2rr+psQMTcyb1ZvtXsQ="; - } - ``` - -- Best: Fetches a snapshot archive and you get the rev you want. - - ```nix - src = fetchFromGitHub { - owner = "NixOS"; - repo = "nix"; - rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae"; - hash = "sha256-7D4m+saJjbSFP5hOwpQq2FGR2rr+psQMTcyb1ZvtXsQ="; - } - ``` - -When fetching from GitHub, commits must always be referenced by their full commit hash. This is because GitHub shares commit hashes among all forks and returns `404 Not Found` when a short commit hash is ambiguous. It already happens for some short, 6-character commit hashes in `nixpkgs`. -It is a practical vector for a denial-of-service attack by pushing large amounts of auto generated commits into forks and was already [demonstrated against GitHub Actions Beta](https://blog.teddykatz.com/2019/11/12/github-actions-dos.html). - -Find the value to put as `hash` by running `nix-shell -p nix-prefetch-github --run "nix-prefetch-github --rev 1f795f9f44607cc5bec70d1300150bfefcef2aae NixOS nix"`. +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ## Obtaining source hash {#sec-source-hashes} -Preferred source hash type is sha256. There are several ways to get it. - -1. Prefetch URL (with `nix-prefetch-XXX URL`, where `XXX` is one of `url`, `git`, `hg`, `cvs`, `bzr`, `svn`). Hash is printed to stdout. - -2. Prefetch by package source (with `nix-prefetch-url '' -A PACKAGE.src`, where `PACKAGE` is package attribute name). Hash is printed to stdout. - - This works well when you've upgraded existing package version and want to find out new hash, but is useless if package can't be accessed by attribute or package has multiple sources (`.srcs`, architecture-dependent sources, etc). - -3. Upstream provided hash: use it when upstream provides `sha256` or `sha512` (when upstream provides `md5`, don't use it, compute `sha256` instead). - - A little nuance is that `nix-prefetch-*` tools produce hash encoded with `base32`, but upstream usually provides hexadecimal (`base16`) encoding. Fetchers understand both formats. Nixpkgs does not standardize on any one format. - - You can convert between formats with nix-hash, for example: - - ```ShellSession - $ nix-hash --type sha256 --to-base32 HASH - ``` - -4. Extracting hash from local source tarball can be done with `sha256sum`. Use `nix-prefetch-url file:///path/to/tarball` if you want base32 hash. - -5. Fake hash: set the hash to one of - - - `""` - - `lib.fakeHash` - - `lib.fakeSha256` - - `lib.fakeSha512` - - in the package expression, attempt build and extract correct hash from error messages. - - ::: {.warning} - You must use one of these four fake hashes and not some arbitrarily-chosen hash. - - See [](#sec-source-hashes-security). - ::: - - This is last resort method when reconstructing source URL is non-trivial and `nix-prefetch-url -A` isn’t applicable (for example, [one of `kodi` dependencies](https://github.com/NixOS/nixpkgs/blob/d2ab091dd308b99e4912b805a5eb088dd536adb9/pkgs/applications/video/kodi/default.nix#L73)). The easiest way then would be replace hash with a fake one and rebuild. Nix build will fail and error message will contain desired hash. - +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ### Obtaining hashes securely {#sec-source-hashes-security} -Let's say Man-in-the-Middle (MITM) sits close to your network. Then instead of fetching source you can fetch malware, and instead of source hash you get hash of malware. Here are security considerations for this scenario: - -- `http://` URLs are not secure to prefetch hash from; - -- hashes from upstream (in method 3) should be obtained via secure protocol; - -- `https://` URLs are secure in methods 1, 2, 3; - -- `https://` URLs are secure in method 5 *only if* you use one of the listed fake hashes. If you use any other hash, `fetchurl` will pass `--insecure` to `curl` and may then degrade to HTTP in case of TLS certificate expiration. +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ## Patches {#sec-patches} -Patches available online should be retrieved using `fetchpatch`. - -```nix -patches = [ - (fetchpatch { - name = "fix-check-for-using-shared-freetype-lib.patch"; - url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=8f5d285"; - hash = "sha256-uRcxaCjd+WAuGrXOmGfFeu79cUILwkRdBu48mwcBE7g="; - }) -]; -``` - -Otherwise, you can add a `.patch` file to the `nixpkgs` repository. In the interest of keeping our maintenance burden to a minimum, only patches that are unique to `nixpkgs` should be added in this way. - -If a patch is available online but does not cleanly apply, it can be modified in some fixed ways by using additional optional arguments for `fetchpatch`. Check [](#fetchpatch) for details. - -```nix -patches = [ ./0001-changes.patch ]; -``` - -If you do need to do create this sort of patch file, one way to do so is with git: - -1. Move to the root directory of the source code you're patching. - - ```ShellSession - $ cd the/program/source - ``` - -2. If a git repository is not already present, create one and stage all of the source files. - - ```ShellSession - $ git init - $ git add . - ``` - -3. Edit some files to make whatever changes need to be included in the patch. - -4. Use git to create a diff, and pipe the output to a patch file: - - ```ShellSession - $ git diff -a > nixpkgs/pkgs/the/package/0001-changes.patch - ``` +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ## Package tests {#sec-package-tests} -Tests are important to ensure quality and make reviews and automatic updates easy. - -The following types of tests exists: - -* [NixOS **module tests**](https://nixos.org/manual/nixos/stable/#sec-nixos-tests), which spawn one or more NixOS VMs. They exercise both NixOS modules and the packaged programs used within them. For example, a NixOS module test can start a web server VM running the `nginx` module, and a client VM running `curl` or a graphical `firefox`, and test that they can talk to each other and display the correct content. -* Nix **package tests** are a lightweight alternative to NixOS module tests. They should be used to create simple integration tests for packages, but cannot test NixOS services, and some programs with graphical user interfaces may also be difficult to test with them. -* The **`checkPhase` of a package**, which should execute the unit tests that are included in the source code of a package. - -Here in the nixpkgs manual we describe mostly _package tests_; for _module tests_ head over to the corresponding [section in the NixOS manual](https://nixos.org/manual/nixos/stable/#sec-nixos-tests). +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ### Writing inline package tests {#ssec-inline-package-tests-writing} -For very simple tests, they can be written inline: - -```nix -{ …, yq-go }: - -buildGoModule rec { - … - - passthru.tests = { - simple = runCommand "${pname}-test" {} '' - echo "test: 1" | ${yq-go}/bin/yq eval -j > $out - [ "$(cat $out | tr -d $'\n ')" = '{"test":1}' ] - ''; - }; -} -``` +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ### Writing larger package tests {#ssec-package-tests-writing} -This is an example using the `phoronix-test-suite` package with the current best practices. - -Add the tests in `passthru.tests` to the package definition like this: - -```nix -{ stdenv, lib, fetchurl, callPackage }: - -stdenv.mkDerivation { - … - - passthru.tests = { - simple-execution = callPackage ./tests.nix { }; - }; - - meta = { … }; -} -``` - -Create `tests.nix` in the package directory: - -```nix -{ runCommand, phoronix-test-suite }: - -let - inherit (phoronix-test-suite) pname version; -in - -runCommand "${pname}-tests" { meta.timeout = 60; } - '' - # automatic initial setup to prevent interactive questions - ${phoronix-test-suite}/bin/phoronix-test-suite enterprise-setup >/dev/null - # get version of installed program and compare with package version - if [[ `${phoronix-test-suite}/bin/phoronix-test-suite version` != *"${version}"* ]]; then - echo "Error: program version does not match package version" - exit 1 - fi - # run dummy command - ${phoronix-test-suite}/bin/phoronix-test-suite dummy_module.dummy-command >/dev/null - # needed for Nix to register the command as successful - touch $out - '' -``` +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ### Running package tests {#ssec-package-tests-running} -You can run these tests with: - -```ShellSession -$ cd path/to/nixpkgs -$ nix-build -A phoronix-test-suite.tests -``` +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ### Examples of package tests {#ssec-package-tests-examples} -Here are examples of package tests: - -- [Jasmin compile test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/jasmin/test-assemble-hello-world/default.nix) -- [Lobster compile test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/lobster/test-can-run-hello-world.nix) -- [Spacy annotation test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/spacy/annotation-test/default.nix) -- [Libtorch test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/science/math/libtorch/test/default.nix) -- [Multiple tests for nanopb](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/nanopb/default.nix) +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ### Linking NixOS module tests to a package {#ssec-nixos-tests-linking} -Like [package tests](#ssec-package-tests-writing) as shown above, [NixOS module tests](https://nixos.org/manual/nixos/stable/#sec-nixos-tests) can also be linked to a package, so that the tests can be easily run when changing the related package. - -For example, assuming we're packaging `nginx`, we can link its module test via `passthru.tests`: - -```nix -{ stdenv, lib, nixosTests }: - -stdenv.mkDerivation { - ... - - passthru.tests = { - nginx = nixosTests.nginx; - }; - - ... -} -``` +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ### Import From Derivation {#ssec-import-from-derivation} -Import From Derivation (IFD) is disallowed in Nixpkgs for performance reasons: -[Hydra] evaluates the entire package set, and sequential builds during evaluation would increase evaluation times to become impractical. - -[Hydra]: https://github.com/NixOS/hydra - -Import From Derivation can be worked around in some cases by committing generated intermediate files to version control and reading those instead. - - - -See also [NixOS Wiki: Import From Derivation]. - -[NixOS Wiki: Import From Derivation]: https://nixos.wiki/wiki/Import_From_Derivation +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). diff --git a/pkgs/README.md b/pkgs/README.md index ab7bf29a1a62..2ef5ac3614a9 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -1,7 +1,227 @@ # Contributing to Nixpkgs packages +## Hierarchy {#sec-hierarchy} + +Each package should be stored in its own directory somewhere in the `pkgs/` tree, i.e. in `pkgs/category/subcategory/.../pkgname`. Below are some rules for picking the right category for a package. Many packages fall under several categories; what matters is the _primary_ purpose of a package. For example, the `libxml2` package builds both a library and some tools; but it’s a library foremost, so it goes under `pkgs/development/libraries`. + +When in doubt, consider refactoring the `pkgs/` tree, e.g. creating new categories or splitting up an existing category. + +**If it’s used to support _software development_:** + +- **If it’s a _library_ used by other packages:** + + - `development/libraries` (e.g. `libxml2`) + +- **If it’s a _compiler_:** + + - `development/compilers` (e.g. `gcc`) + +- **If it’s an _interpreter_:** + + - `development/interpreters` (e.g. `guile`) + +- **If it’s a (set of) development _tool(s)_:** + + - **If it’s a _parser generator_ (including lexers):** + + - `development/tools/parsing` (e.g. `bison`, `flex`) + + - **If it’s a _build manager_:** + + - `development/tools/build-managers` (e.g. `gnumake`) + + - **If it’s a _language server_:** + + - `development/tools/language-servers` (e.g. `ccls` or `rnix-lsp`) + + - **Else:** + + - `development/tools/misc` (e.g. `binutils`) + +- **Else:** + + - `development/misc` + +**If it’s a (set of) _tool(s)_:** + +(A tool is a relatively small program, especially one intended to be used non-interactively.) + +- **If it’s for _networking_:** + + - `tools/networking` (e.g. `wget`) + +- **If it’s for _text processing_:** + + - `tools/text` (e.g. `diffutils`) + +- **If it’s a _system utility_, i.e., something related or essential to the operation of a system:** + + - `tools/system` (e.g. `cron`) + +- **If it’s an _archiver_ (which may include a compression function):** + + - `tools/archivers` (e.g. `zip`, `tar`) + +- **If it’s a _compression_ program:** + + - `tools/compression` (e.g. `gzip`, `bzip2`) + +- **If it’s a _security_-related program:** + + - `tools/security` (e.g. `nmap`, `gnupg`) + +- **Else:** + + - `tools/misc` + +**If it’s a _shell_:** + +- `shells` (e.g. `bash`) + +**If it’s a _server_:** + +- **If it’s a web server:** + + - `servers/http` (e.g. `apache-httpd`) + +- **If it’s an implementation of the X Windowing System:** + + - `servers/x11` (e.g. `xorg` — this includes the client libraries and programs) + +- **Else:** + + - `servers/misc` + +**If it’s a _desktop environment_:** + +- `desktops` (e.g. `kde`, `gnome`, `enlightenment`) + +**If it’s a _window manager_:** + +- `applications/window-managers` (e.g. `awesome`, `stumpwm`) + +**If it’s an _application_:** + +A (typically large) program with a distinct user interface, primarily used interactively. + +- **If it’s a _version management system_:** + + - `applications/version-management` (e.g. `subversion`) + +- **If it’s a _terminal emulator_:** + + - `applications/terminal-emulators` (e.g. `alacritty` or `rxvt` or `termite`) + +- **If it’s a _file manager_:** + + - `applications/file-managers` (e.g. `mc` or `ranger` or `pcmanfm`) + +- **If it’s for _video playback / editing_:** + + - `applications/video` (e.g. `vlc`) + +- **If it’s for _graphics viewing / editing_:** + + - `applications/graphics` (e.g. `gimp`) + +- **If it’s for _networking_:** + + - **If it’s a _mailreader_:** + + - `applications/networking/mailreaders` (e.g. `thunderbird`) + + - **If it’s a _newsreader_:** + + - `applications/networking/newsreaders` (e.g. `pan`) + + - **If it’s a _web browser_:** + + - `applications/networking/browsers` (e.g. `firefox`) + + - **Else:** + + - `applications/networking/misc` + +- **Else:** + + - `applications/misc` + +**If it’s _data_ (i.e., does not have a straight-forward executable semantics):** + +- **If it’s a _font_:** + + - `data/fonts` + +- **If it’s an _icon theme_:** + + - `data/icons` + +- **If it’s related to _SGML/XML processing_:** + + - **If it’s an _XML DTD_:** + + - `data/sgml+xml/schemas/xml-dtd` (e.g. `docbook`) + + - **If it’s an _XSLT stylesheet_:** + + (Okay, these are executable...) + + - `data/sgml+xml/stylesheets/xslt` (e.g. `docbook-xsl`) + +- **If it’s a _theme_ for a _desktop environment_, a _window manager_ or a _display manager_:** + + - `data/themes` + +**If it’s a _game_:** + +- `games` + +**Else:** + +- `misc` + ## (Conventions) +### Package naming {#sec-package-naming} + +The key words _must_, _must not_, _required_, _shall_, _shall not_, _should_, _should not_, _recommended_, _may_, and _optional_ in this section are to be interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119). Only _emphasized_ words are to be interpreted in this way. + +In Nixpkgs, there are generally three different names associated with a package: + +- The `pname` attribute of the derivation. This is what most users see, in particular when using `nix-env`. + +- The variable name used for the instantiated package in `all-packages.nix`, and when passing it as a dependency to other functions. Typically this is called the _package attribute name_. This is what Nix expression authors see. It can also be used when installing using `nix-env -iA`. + +- The filename for (the directory containing) the Nix expression. + +Most of the time, these are the same. For instance, the package `e2fsprogs` has a `pname` attribute `"e2fsprogs"`, is bound to the variable name `e2fsprogs` in `all-packages.nix`, and the Nix expression is in `pkgs/os-specific/linux/e2fsprogs/default.nix`. + +There are a few naming guidelines: + +- The `pname` attribute _should_ be identical to the upstream package name. + +- The `pname` and the `version` attribute _must not_ contain uppercase letters — e.g., `"mplayer" instead of `"MPlayer"`. + +- The `version` attribute _must_ start with a digit e.g`"0.3.1rc2". + +- If a package is a commit from a repository without a version assigned, then the `version` attribute _should_ be the latest upstream version preceding that commit, followed by `-unstable-` and the date of the (fetched) commit. The date _must_ be in `"YYYY-MM-DD"` format. + +Example: Given a project had its latest releases `2.2` in November 2021, and `3.0` in January 2022, a commit authored on March 15, 2022 for an upcoming bugfix release `2.2.1` would have `version = "2.2-unstable-2022-03-15"`. + +- Dashes in the package `pname` _should_ be preserved in new variable names, rather than converted to underscores or camel cased — e.g., `http-parser` instead of `http_parser` or `httpParser`. The hyphenated style is preferred in all three package names. + +- If there are multiple versions of a package, this _should_ be reflected in the variable names in `all-packages.nix`, e.g. `json-c_0_9` and `json-c_0_11`. If there is an obvious “default” version, make an attribute like `json-c = json-c_0_9;`. See also [](#sec-versioning) + +### Versioning {#sec-versioning} + +Because every version of a package in Nixpkgs creates a potential maintenance burden, old versions of a package should not be kept unless there is a good reason to do so. For instance, Nixpkgs contains several versions of GCC because other packages don’t build with the latest version of GCC. Other examples are having both the latest stable and latest pre-release version of a package, or to keep several major releases of an application that differ significantly in functionality. + +If there is only one version of a package, its Nix expression should be named `e2fsprogs/default.nix`. If there are multiple versions, this should be reflected in the filename, e.g. `e2fsprogs/1.41.8.nix` and `e2fsprogs/1.41.9.nix`. The version in the filename should leave out unnecessary detail. For instance, if we keep the latest Firefox 2.0.x and 3.5.x versions in Nixpkgs, they should be named `firefox/2.0.nix` and `firefox/3.5.nix`, respectively (which, at a given point, might contain versions `2.0.0.20` and `3.5.4`). If a version requires many auxiliary files, you can use a subdirectory for each version, e.g. `firefox/2.0/default.nix` and `firefox/3.5/default.nix`. + +All versions of a package _must_ be included in `all-packages.nix` to make sure that they evaluate correctly. + +### (Meta attributes) + * `meta.description` must: * Be short, just one sentence. * Be capitalized. @@ -17,7 +237,166 @@ See the nixpkgs manual for more details on [standard meta-attributes](https://nixos.org/nixpkgs/manual/#sec-standard-meta-attributes). -## Testing changes +### Import From Derivation {#ssec-import-from-derivation} + +Import From Derivation (IFD) is disallowed in Nixpkgs for performance reasons: +[Hydra] evaluates the entire package set, and sequential builds during evaluation would increase evaluation times to become impractical. + +[Hydra]: https://github.com/NixOS/hydra + +Import From Derivation can be worked around in some cases by committing generated intermediate files to version control and reading those instead. + + + +See also [NixOS Wiki: Import From Derivation]. + +[NixOS Wiki: Import From Derivation]: https://nixos.wiki/wiki/Import_From_Derivation + +## (Sources) + +### Fetching Sources {#sec-sources} + +There are multiple ways to fetch a package source in nixpkgs. The general guideline is that you should package reproducible sources with a high degree of availability. Right now there is only one fetcher which has mirroring support and that is `fetchurl`. Note that you should also prefer protocols which have a corresponding proxy environment variable. + +You can find many source fetch helpers in `pkgs/build-support/fetch*`. + +In the file `pkgs/top-level/all-packages.nix` you can find fetch helpers, these have names on the form `fetchFrom*`. The intention of these are to provide snapshot fetches but using the same api as some of the version controlled fetchers from `pkgs/build-support/`. As an example going from bad to good: + +- Bad: Uses `git://` which won't be proxied. + + ```nix + src = fetchgit { + url = "git@github.com:NixOS/nix.git" + url = "git://github.com/NixOS/nix.git"; + rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae"; + hash = "sha256-7D4m+saJjbSFP5hOwpQq2FGR2rr+psQMTcyb1ZvtXsQ="; + } + ``` + +- Better: This is ok, but an archive fetch will still be faster. + + ```nix + src = fetchgit { + url = "https://github.com/NixOS/nix.git"; + rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae"; + hash = "sha256-7D4m+saJjbSFP5hOwpQq2FGR2rr+psQMTcyb1ZvtXsQ="; + } + ``` + +- Best: Fetches a snapshot archive and you get the rev you want. + + ```nix + src = fetchFromGitHub { + owner = "NixOS"; + repo = "nix"; + rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae"; + hash = "sha256-7D4m+saJjbSFP5hOwpQq2FGR2rr+psQMTcyb1ZvtXsQ="; + } + ``` + +When fetching from GitHub, commits must always be referenced by their full commit hash. This is because GitHub shares commit hashes among all forks and returns `404 Not Found` when a short commit hash is ambiguous. It already happens for some short, 6-character commit hashes in `nixpkgs`. +It is a practical vector for a denial-of-service attack by pushing large amounts of auto generated commits into forks and was already [demonstrated against GitHub Actions Beta](https://blog.teddykatz.com/2019/11/12/github-actions-dos.html). + +Find the value to put as `hash` by running `nix-shell -p nix-prefetch-github --run "nix-prefetch-github --rev 1f795f9f44607cc5bec70d1300150bfefcef2aae NixOS nix"`. + +#### Obtaining source hash {#sec-source-hashes} + +Preferred source hash type is sha256. There are several ways to get it. + +1. Prefetch URL (with `nix-prefetch-XXX URL`, where `XXX` is one of `url`, `git`, `hg`, `cvs`, `bzr`, `svn`). Hash is printed to stdout. + +2. Prefetch by package source (with `nix-prefetch-url '' -A PACKAGE.src`, where `PACKAGE` is package attribute name). Hash is printed to stdout. + + This works well when you've upgraded existing package version and want to find out new hash, but is useless if package can't be accessed by attribute or package has multiple sources (`.srcs`, architecture-dependent sources, etc). + +3. Upstream provided hash: use it when upstream provides `sha256` or `sha512` (when upstream provides `md5`, don't use it, compute `sha256` instead). + + A little nuance is that `nix-prefetch-*` tools produce hash encoded with `base32`, but upstream usually provides hexadecimal (`base16`) encoding. Fetchers understand both formats. Nixpkgs does not standardize on any one format. + + You can convert between formats with nix-hash, for example: + + ```ShellSession + $ nix-hash --type sha256 --to-base32 HASH + ``` + +4. Extracting hash from local source tarball can be done with `sha256sum`. Use `nix-prefetch-url file:///path/to/tarball` if you want base32 hash. + +5. Fake hash: set the hash to one of + + - `""` + - `lib.fakeHash` + - `lib.fakeSha256` + - `lib.fakeSha512` + + in the package expression, attempt build and extract correct hash from error messages. + + ::: {.warning} + You must use one of these four fake hashes and not some arbitrarily-chosen hash. + + See [](#sec-source-hashes-security). + ::: + + This is last resort method when reconstructing source URL is non-trivial and `nix-prefetch-url -A` isn’t applicable (for example, [one of `kodi` dependencies](https://github.com/NixOS/nixpkgs/blob/d2ab091dd308b99e4912b805a5eb088dd536adb9/pkgs/applications/video/kodi/default.nix#L73)). The easiest way then would be replace hash with a fake one and rebuild. Nix build will fail and error message will contain desired hash. + + +#### Obtaining hashes securely {#sec-source-hashes-security} + +Let's say Man-in-the-Middle (MITM) sits close to your network. Then instead of fetching source you can fetch malware, and instead of source hash you get hash of malware. Here are security considerations for this scenario: + +- `http://` URLs are not secure to prefetch hash from; + +- hashes from upstream (in method 3) should be obtained via secure protocol; + +- `https://` URLs are secure in methods 1, 2, 3; + +- `https://` URLs are secure in method 5 *only if* you use one of the listed fake hashes. If you use any other hash, `fetchurl` will pass `--insecure` to `curl` and may then degrade to HTTP in case of TLS certificate expiration. + +### Patches {#sec-patches} + +Patches available online should be retrieved using `fetchpatch`. + +```nix +patches = [ + (fetchpatch { + name = "fix-check-for-using-shared-freetype-lib.patch"; + url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=8f5d285"; + hash = "sha256-uRcxaCjd+WAuGrXOmGfFeu79cUILwkRdBu48mwcBE7g="; + }) +]; +``` + +Otherwise, you can add a `.patch` file to the `nixpkgs` repository. In the interest of keeping our maintenance burden to a minimum, only patches that are unique to `nixpkgs` should be added in this way. + +If a patch is available online but does not cleanly apply, it can be modified in some fixed ways by using additional optional arguments for `fetchpatch`. Check [](#fetchpatch) for details. + +```nix +patches = [ ./0001-changes.patch ]; +``` + +If you do need to do create this sort of patch file, one way to do so is with git: + +1. Move to the root directory of the source code you're patching. + + ```ShellSession + $ cd the/program/source + ``` + +2. If a git repository is not already present, create one and stage all of the source files. + + ```ShellSession + $ git init + $ git add . + ``` + +3. Edit some files to make whatever changes need to be included in the patch. + +4. Use git to create a diff, and pipe the output to a patch file: + + ```ShellSession + $ git diff -a > nixpkgs/pkgs/the/package/0001-changes.patch + ``` + +## Testing changes | Package tests {#sec-package-tests} To run the main types of tests locally: @@ -25,3 +404,116 @@ To run the main types of tests locally: - Run [NixOS tests](https://nixos.org/manual/nixos/unstable/#sec-nixos-tests) with `nix-build --attr nixosTest.NAME`, where `NAME` is the name of the test listed in `nixos/tests/all-tests.nix` - Run [global package tests](https://nixos.org/manual/nixpkgs/unstable/#sec-package-tests) with `nix-build --attr tests.PACKAGE`, where `PACKAGE` is the name of the test listed in `pkgs/test/default.nix` - See `lib/tests/NAME.nix` for instructions on running specific library tests + +Tests are important to ensure quality and make reviews and automatic updates easy. + +The following types of tests exists: + +* [NixOS **module tests**](https://nixos.org/manual/nixos/stable/#sec-nixos-tests), which spawn one or more NixOS VMs. They exercise both NixOS modules and the packaged programs used within them. For example, a NixOS module test can start a web server VM running the `nginx` module, and a client VM running `curl` or a graphical `firefox`, and test that they can talk to each other and display the correct content. +* Nix **package tests** are a lightweight alternative to NixOS module tests. They should be used to create simple integration tests for packages, but cannot test NixOS services, and some programs with graphical user interfaces may also be difficult to test with them. +* The **`checkPhase` of a package**, which should execute the unit tests that are included in the source code of a package. + +Here in the nixpkgs manual we describe mostly _package tests_; for _module tests_ head over to the corresponding [section in the NixOS manual](https://nixos.org/manual/nixos/stable/#sec-nixos-tests). + +### Writing inline package tests {#ssec-inline-package-tests-writing} + +For very simple tests, they can be written inline: + +```nix +{ …, yq-go }: + +buildGoModule rec { + … + + passthru.tests = { + simple = runCommand "${pname}-test" {} '' + echo "test: 1" | ${yq-go}/bin/yq eval -j > $out + [ "$(cat $out | tr -d $'\n ')" = '{"test":1}' ] + ''; + }; +} +``` + +### Writing larger package tests {#ssec-package-tests-writing} + +This is an example using the `phoronix-test-suite` package with the current best practices. + +Add the tests in `passthru.tests` to the package definition like this: + +```nix +{ stdenv, lib, fetchurl, callPackage }: + +stdenv.mkDerivation { + … + + passthru.tests = { + simple-execution = callPackage ./tests.nix { }; + }; + + meta = { … }; +} +``` + +Create `tests.nix` in the package directory: + +```nix +{ runCommand, phoronix-test-suite }: + +let + inherit (phoronix-test-suite) pname version; +in + +runCommand "${pname}-tests" { meta.timeout = 60; } + '' + # automatic initial setup to prevent interactive questions + ${phoronix-test-suite}/bin/phoronix-test-suite enterprise-setup >/dev/null + # get version of installed program and compare with package version + if [[ `${phoronix-test-suite}/bin/phoronix-test-suite version` != *"${version}"* ]]; then + echo "Error: program version does not match package version" + exit 1 + fi + # run dummy command + ${phoronix-test-suite}/bin/phoronix-test-suite dummy_module.dummy-command >/dev/null + # needed for Nix to register the command as successful + touch $out + '' +``` + +### Running package tests {#ssec-package-tests-running} + +You can run these tests with: + +```ShellSession +$ cd path/to/nixpkgs +$ nix-build -A phoronix-test-suite.tests +``` + +### Examples of package tests {#ssec-package-tests-examples} + +Here are examples of package tests: + +- [Jasmin compile test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/jasmin/test-assemble-hello-world/default.nix) +- [Lobster compile test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/lobster/test-can-run-hello-world.nix) +- [Spacy annotation test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/spacy/annotation-test/default.nix) +- [Libtorch test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/science/math/libtorch/test/default.nix) +- [Multiple tests for nanopb](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/nanopb/default.nix) + +### Linking NixOS module tests to a package {#ssec-nixos-tests-linking} + +Like [package tests](#ssec-package-tests-writing) as shown above, [NixOS module tests](https://nixos.org/manual/nixos/stable/#sec-nixos-tests) can also be linked to a package, so that the tests can be easily run when changing the related package. + +For example, assuming we're packaging `nginx`, we can link its module test via `passthru.tests`: + +```nix +{ stdenv, lib, nixosTests }: + +stdenv.mkDerivation { + ... + + passthru.tests = { + nginx = nixosTests.nginx; + }; + + ... +} +``` From 74b17a515f8fb8cb59e54bf21e7be4861e239009 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 25 Jul 2023 17:51:38 +0200 Subject: [PATCH 06/42] doc/contributing-to-documentation: Rough move to new contribution doc files Section in the manual have been preserved with a simple redirect to GitHub, the proper anchors should be filled out in a future commit once the new section names are decided. --- doc/README.md | 116 ++++++++++++++++++ .../contributing-to-documentation.chapter.md | 110 +---------------- 2 files changed, 119 insertions(+), 107 deletions(-) diff --git a/doc/README.md b/doc/README.md index eea797403808..19b61233bc28 100644 --- a/doc/README.md +++ b/doc/README.md @@ -9,3 +9,119 @@ You can find the [rendered documentation for Nixpkgs `unstable` on nixos.org](ht If you want to contribute to the documentation, [here's how to do it](https://nixos.org/manual/nixpkgs/unstable/#chap-contributing). If you're only getting started with Nix, go to [nixos.org/learn](https://nixos.org/learn). + +## Contributing to this documentation {#chap-contributing} + +The sources of the Nixpkgs manual are in the [doc](https://github.com/NixOS/nixpkgs/tree/master/doc) subdirectory of the Nixpkgs repository. + +You can quickly check your edits with `nix-build`: + +```ShellSession +$ cd /path/to/nixpkgs +$ nix-build doc +``` + +If the build succeeds, the manual will be in `./result/share/doc/nixpkgs/manual.html`. + +### devmode {#sec-contributing-devmode} + +The shell in the manual source directory makes available a command, `devmode`. +It is a daemon, that: +1. watches the manual's source for changes and when they occur — rebuilds +2. HTTP serves the manual, injecting a script that triggers reload on changes +3. opens the manual in the default browser + +### Syntax {#sec-contributing-markup} + +As per [RFC 0072](https://github.com/NixOS/rfcs/pull/72), all new documentation content should be written in [CommonMark](https://commonmark.org/) Markdown dialect. + +Additional syntax extensions are available, all of which can be used in NixOS option documentation. The following extensions are currently used: + +- []{#ssec-contributing-markup-tables} + Tables, using the [GitHub-flavored Markdown syntax](https://github.github.com/gfm/#tables-extension-). + +- []{#ssec-contributing-markup-anchors} + Explicitly defined **anchors** on headings, to allow linking to sections. These should be always used, to ensure the anchors can be linked even when the heading text changes, and to prevent conflicts between [automatically assigned identifiers](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/auto_identifiers.md). + + It uses the widely compatible [header attributes](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/attributes.md) syntax: + + ```markdown + ## Syntax {#sec-contributing-markup} + ``` + + ::: {.note} + NixOS option documentation does not support headings in general. + ::: + +- []{#ssec-contributing-markup-anchors-inline} + **Inline anchors**, which allow linking arbitrary place in the text (e.g. individual list items, sentences…). + + They are defined using a hybrid of the link syntax with the attributes syntax known from headings, called [bracketed spans](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/bracketed_spans.md): + + ```markdown + - []{#ssec-gnome-hooks-glib} `glib` setup hook will populate `GSETTINGS_SCHEMAS_PATH` and then `wrapGAppsHook` will prepend it to `XDG_DATA_DIRS`. + ``` + +- []{#ssec-contributing-markup-automatic-links} + If you **omit a link text** for a link pointing to a section, the text will be substituted automatically. For example, `[](#chap-contributing)` will result in [](#chap-contributing). + + This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/using/syntax.html#targets-and-cross-referencing). + +- []{#ssec-contributing-markup-inline-roles} + If you want to link to a man page, you can use `` {manpage}`nix.conf(5)` ``, which will turn into {manpage}`nix.conf(5)`. The references will turn into links when a mapping exists in {file}`doc/manpage-urls.json`. + + A few markups for other kinds of literals are also available: + + - `` {command}`rm -rfi` `` turns into {command}`rm -rfi` + - `` {env}`XDG_DATA_DIRS` `` turns into {env}`XDG_DATA_DIRS` + - `` {file}`/etc/passwd` `` turns into {file}`/etc/passwd` + - `` {option}`networking.useDHCP` `` turns into {option}`networking.useDHCP` + - `` {var}`/etc/passwd` `` turns into {var}`/etc/passwd` + + These literal kinds are used mostly in NixOS option documentation. + + This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html#roles-an-in-line-extension-point). Though, the feature originates from [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-manpage) with slightly different syntax. + +- []{#ssec-contributing-markup-admonitions} + **Admonitions**, set off from the text to bring attention to something. + + It uses pandoc’s [fenced `div`s syntax](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md): + + ```markdown + ::: {.warning} + This is a warning + ::: + ``` + + which renders as + + > ::: {.warning} + > This is a warning. + > ::: + + The following are supported: + + - [`caution`](https://tdg.docbook.org/tdg/5.0/caution.html) + - [`important`](https://tdg.docbook.org/tdg/5.0/important.html) + - [`note`](https://tdg.docbook.org/tdg/5.0/note.html) + - [`tip`](https://tdg.docbook.org/tdg/5.0/tip.html) + - [`warning`](https://tdg.docbook.org/tdg/5.0/warning.html) + +- []{#ssec-contributing-markup-definition-lists} + [**Definition lists**](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/definition_lists.md), for defining a group of terms: + + ```markdown + pear + : green or yellow bulbous fruit + + watermelon + : green fruit with red flesh + ``` + + which renders as + + > pear + > : green or yellow bulbous fruit + > + > watermelon + > : green fruit with red flesh diff --git a/doc/contributing/contributing-to-documentation.chapter.md b/doc/contributing/contributing-to-documentation.chapter.md index 09cc3160df3c..777858b901c3 100644 --- a/doc/contributing/contributing-to-documentation.chapter.md +++ b/doc/contributing/contributing-to-documentation.chapter.md @@ -1,115 +1,11 @@ # Contributing to Nixpkgs documentation {#chap-contributing} -The sources of the Nixpkgs manual are in the [doc](https://github.com/NixOS/nixpkgs/tree/master/doc) subdirectory of the Nixpkgs repository. - -You can quickly check your edits with `nix-build`: - -```ShellSession -$ cd /path/to/nixpkgs -$ nix-build doc -``` - -If the build succeeds, the manual will be in `./result/share/doc/nixpkgs/manual.html`. +This section has been moved to [doc/README.md](https://github.com/NixOS/nixpkgs/blob/master/doc/README.md). ## devmode {#sec-contributing-devmode} -The shell in the manual source directory makes available a command, `devmode`. -It is a daemon, that: -1. watches the manual's source for changes and when they occur — rebuilds -2. HTTP serves the manual, injecting a script that triggers reload on changes -3. opens the manual in the default browser +This section has been moved to [doc/README.md](https://github.com/NixOS/nixpkgs/blob/master/doc/README.md). ## Syntax {#sec-contributing-markup} -As per [RFC 0072](https://github.com/NixOS/rfcs/pull/72), all new documentation content should be written in [CommonMark](https://commonmark.org/) Markdown dialect. - -Additional syntax extensions are available, all of which can be used in NixOS option documentation. The following extensions are currently used: - -- []{#ssec-contributing-markup-tables} - Tables, using the [GitHub-flavored Markdown syntax](https://github.github.com/gfm/#tables-extension-). - -- []{#ssec-contributing-markup-anchors} - Explicitly defined **anchors** on headings, to allow linking to sections. These should be always used, to ensure the anchors can be linked even when the heading text changes, and to prevent conflicts between [automatically assigned identifiers](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/auto_identifiers.md). - - It uses the widely compatible [header attributes](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/attributes.md) syntax: - - ```markdown - ## Syntax {#sec-contributing-markup} - ``` - - ::: {.note} - NixOS option documentation does not support headings in general. - ::: - -- []{#ssec-contributing-markup-anchors-inline} - **Inline anchors**, which allow linking arbitrary place in the text (e.g. individual list items, sentences…). - - They are defined using a hybrid of the link syntax with the attributes syntax known from headings, called [bracketed spans](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/bracketed_spans.md): - - ```markdown - - []{#ssec-gnome-hooks-glib} `glib` setup hook will populate `GSETTINGS_SCHEMAS_PATH` and then `wrapGAppsHook` will prepend it to `XDG_DATA_DIRS`. - ``` - -- []{#ssec-contributing-markup-automatic-links} - If you **omit a link text** for a link pointing to a section, the text will be substituted automatically. For example, `[](#chap-contributing)` will result in [](#chap-contributing). - - This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/using/syntax.html#targets-and-cross-referencing). - -- []{#ssec-contributing-markup-inline-roles} - If you want to link to a man page, you can use `` {manpage}`nix.conf(5)` ``, which will turn into {manpage}`nix.conf(5)`. The references will turn into links when a mapping exists in {file}`doc/manpage-urls.json`. - - A few markups for other kinds of literals are also available: - - - `` {command}`rm -rfi` `` turns into {command}`rm -rfi` - - `` {env}`XDG_DATA_DIRS` `` turns into {env}`XDG_DATA_DIRS` - - `` {file}`/etc/passwd` `` turns into {file}`/etc/passwd` - - `` {option}`networking.useDHCP` `` turns into {option}`networking.useDHCP` - - `` {var}`/etc/passwd` `` turns into {var}`/etc/passwd` - - These literal kinds are used mostly in NixOS option documentation. - - This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html#roles-an-in-line-extension-point). Though, the feature originates from [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-manpage) with slightly different syntax. - -- []{#ssec-contributing-markup-admonitions} - **Admonitions**, set off from the text to bring attention to something. - - It uses pandoc’s [fenced `div`s syntax](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md): - - ```markdown - ::: {.warning} - This is a warning - ::: - ``` - - which renders as - - > ::: {.warning} - > This is a warning. - > ::: - - The following are supported: - - - [`caution`](https://tdg.docbook.org/tdg/5.0/caution.html) - - [`important`](https://tdg.docbook.org/tdg/5.0/important.html) - - [`note`](https://tdg.docbook.org/tdg/5.0/note.html) - - [`tip`](https://tdg.docbook.org/tdg/5.0/tip.html) - - [`warning`](https://tdg.docbook.org/tdg/5.0/warning.html) - -- []{#ssec-contributing-markup-definition-lists} - [**Definition lists**](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/definition_lists.md), for defining a group of terms: - - ```markdown - pear - : green or yellow bulbous fruit - - watermelon - : green fruit with red flesh - ``` - - which renders as - - > pear - > : green or yellow bulbous fruit - > - > watermelon - > : green fruit with red flesh +This section has been moved to [doc/README.md](https://github.com/NixOS/nixpkgs/blob/master/doc/README.md). From 90bf25d0377046e006d41971795e04d7530e22c1 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 25 Jul 2023 17:55:09 +0200 Subject: [PATCH 07/42] doc/quick-start: Rough move to new contribution doc files Section in the manual have been preserved with a simple redirect to GitHub, the proper anchors should be filled out in a future commit once the new section names are decided. --- doc/contributing/quick-start.chapter.md | 76 +----------------------- pkgs/README.md | 78 +++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 75 deletions(-) diff --git a/doc/contributing/quick-start.chapter.md b/doc/contributing/quick-start.chapter.md index e6bb5f2b0b60..e482de7bc7b0 100644 --- a/doc/contributing/quick-start.chapter.md +++ b/doc/contributing/quick-start.chapter.md @@ -1,77 +1,3 @@ # Quick Start to Adding a Package {#chap-quick-start} -To add a package to Nixpkgs: - -1. Checkout the Nixpkgs source tree: - - ```ShellSession - $ git clone https://github.com/NixOS/nixpkgs - $ cd nixpkgs - ``` - -2. Find a good place in the Nixpkgs tree to add the Nix expression for your package. For instance, a library package typically goes into `pkgs/development/libraries/pkgname`, while a web browser goes into `pkgs/applications/networking/browsers/pkgname`. See [](#sec-organisation) for some hints on the tree organisation. Create a directory for your package, e.g. - - ```ShellSession - $ mkdir pkgs/development/libraries/libfoo - ``` - -3. In the package directory, create a Nix expression — a piece of code that describes how to build the package. In this case, it should be a _function_ that is called with the package dependencies as arguments, and returns a build of the package in the Nix store. The expression should usually be called `default.nix`. - - ```ShellSession - $ emacs pkgs/development/libraries/libfoo/default.nix - $ git add pkgs/development/libraries/libfoo/default.nix - ``` - - You can have a look at the existing Nix expressions under `pkgs/` to see how it’s done. Here are some good ones: - - - GNU Hello: [`pkgs/applications/misc/hello/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/hello/default.nix). Trivial package, which specifies some `meta` attributes which is good practice. - - - GNU cpio: [`pkgs/tools/archivers/cpio/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/archivers/cpio/default.nix). Also a simple package. The generic builder in `stdenv` does everything for you. It has no dependencies beyond `stdenv`. - - - GNU Multiple Precision arithmetic library (GMP): [`pkgs/development/libraries/gmp/5.1.x.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/gmp/5.1.x.nix). Also done by the generic builder, but has a dependency on `m4`. - - - Pan, a GTK-based newsreader: [`pkgs/applications/networking/newsreaders/pan/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix). Has an optional dependency on `gtkspell`, which is only built if `spellCheck` is `true`. - - - Apache HTTPD: [`pkgs/servers/http/apache-httpd/2.4.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/http/apache-httpd/2.4.nix). A bunch of optional features, variable substitutions in the configure flags, a post-install hook, and miscellaneous hackery. - - - buildMozillaMach: [`pkgs/applications/networking/browser/firefox/common.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/browsers/firefox/common.nix). A reusable build function for Firefox, Thunderbird and Librewolf. - - - JDiskReport, a Java utility: [`pkgs/tools/misc/jdiskreport/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/jdiskreport/default.nix). Nixpkgs doesn’t have a decent `stdenv` for Java yet so this is pretty ad-hoc. - - - XML::Simple, a Perl module: [`pkgs/top-level/perl-packages.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/perl-packages.nix) (search for the `XMLSimple` attribute). Most Perl modules are so simple to build that they are defined directly in `perl-packages.nix`; no need to make a separate file for them. - - - Adobe Reader: [`pkgs/applications/misc/adobe-reader/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/default.nix). Shows how binary-only packages can be supported. In particular the [builder](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/builder.sh) uses `patchelf` to set the RUNPATH and ELF interpreter of the executables so that the right libraries are found at runtime. - - Some notes: - - - All [`meta`](#chap-meta) attributes are optional, but it’s still a good idea to provide at least the `description`, `homepage` and [`license`](#sec-meta-license). - - - You can use `nix-prefetch-url url` to get the SHA-256 hash of source distributions. There are similar commands as `nix-prefetch-git` and `nix-prefetch-hg` available in `nix-prefetch-scripts` package. - - - A list of schemes for `mirror://` URLs can be found in [`pkgs/build-support/fetchurl/mirrors.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/fetchurl/mirrors.nix). - - The exact syntax and semantics of the Nix expression language, including the built-in function, are described in the Nix manual in the [chapter on writing Nix expressions](https://hydra.nixos.org/job/nix/trunk/tarball/latest/download-by-type/doc/manual/#chap-writing-nix-expressions). - -4. Add a call to the function defined in the previous step to [`pkgs/top-level/all-packages.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix) with some descriptive name for the variable, e.g. `libfoo`. - - ```ShellSession - $ emacs pkgs/top-level/all-packages.nix - ``` - - The attributes in that file are sorted by category (like “Development / Libraries”) that more-or-less correspond to the directory structure of Nixpkgs, and then by attribute name. - -5. To test whether the package builds, run the following command from the root of the nixpkgs source tree: - - ```ShellSession - $ nix-build -A libfoo - ``` - - where `libfoo` should be the variable name defined in the previous step. You may want to add the flag `-K` to keep the temporary build directory in case something fails. If the build succeeds, a symlink `./result` to the package in the Nix store is created. - -6. If you want to install the package into your profile (optional), do - - ```ShellSession - $ nix-env -f . -iA libfoo - ``` - -7. Optionally commit the new package and open a pull request [to nixpkgs](https://github.com/NixOS/nixpkgs/pulls), or use [the Patches category](https://discourse.nixos.org/t/about-the-patches-category/477) on Discourse for sending a patch without a GitHub account. +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). diff --git a/pkgs/README.md b/pkgs/README.md index 2ef5ac3614a9..3f607564c3c6 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -1,5 +1,83 @@ # Contributing to Nixpkgs packages +## Quick Start to Adding a Package {#chap-quick-start} + +To add a package to Nixpkgs: + +1. Checkout the Nixpkgs source tree: + + ```ShellSession + $ git clone https://github.com/NixOS/nixpkgs + $ cd nixpkgs + ``` + +2. Find a good place in the Nixpkgs tree to add the Nix expression for your package. For instance, a library package typically goes into `pkgs/development/libraries/pkgname`, while a web browser goes into `pkgs/applications/networking/browsers/pkgname`. See [](#sec-organisation) for some hints on the tree organisation. Create a directory for your package, e.g. + + ```ShellSession + $ mkdir pkgs/development/libraries/libfoo + ``` + +3. In the package directory, create a Nix expression — a piece of code that describes how to build the package. In this case, it should be a _function_ that is called with the package dependencies as arguments, and returns a build of the package in the Nix store. The expression should usually be called `default.nix`. + + ```ShellSession + $ emacs pkgs/development/libraries/libfoo/default.nix + $ git add pkgs/development/libraries/libfoo/default.nix + ``` + + You can have a look at the existing Nix expressions under `pkgs/` to see how it’s done. Here are some good ones: + + - GNU Hello: [`pkgs/applications/misc/hello/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/hello/default.nix). Trivial package, which specifies some `meta` attributes which is good practice. + + - GNU cpio: [`pkgs/tools/archivers/cpio/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/archivers/cpio/default.nix). Also a simple package. The generic builder in `stdenv` does everything for you. It has no dependencies beyond `stdenv`. + + - GNU Multiple Precision arithmetic library (GMP): [`pkgs/development/libraries/gmp/5.1.x.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/gmp/5.1.x.nix). Also done by the generic builder, but has a dependency on `m4`. + + - Pan, a GTK-based newsreader: [`pkgs/applications/networking/newsreaders/pan/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix). Has an optional dependency on `gtkspell`, which is only built if `spellCheck` is `true`. + + - Apache HTTPD: [`pkgs/servers/http/apache-httpd/2.4.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/http/apache-httpd/2.4.nix). A bunch of optional features, variable substitutions in the configure flags, a post-install hook, and miscellaneous hackery. + + - buildMozillaMach: [`pkgs/applications/networking/browser/firefox/common.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/browsers/firefox/common.nix). A reusable build function for Firefox, Thunderbird and Librewolf. + + - JDiskReport, a Java utility: [`pkgs/tools/misc/jdiskreport/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/jdiskreport/default.nix). Nixpkgs doesn’t have a decent `stdenv` for Java yet so this is pretty ad-hoc. + + - XML::Simple, a Perl module: [`pkgs/top-level/perl-packages.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/perl-packages.nix) (search for the `XMLSimple` attribute). Most Perl modules are so simple to build that they are defined directly in `perl-packages.nix`; no need to make a separate file for them. + + - Adobe Reader: [`pkgs/applications/misc/adobe-reader/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/default.nix). Shows how binary-only packages can be supported. In particular the [builder](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/builder.sh) uses `patchelf` to set the RUNPATH and ELF interpreter of the executables so that the right libraries are found at runtime. + + Some notes: + + - All [`meta`](#chap-meta) attributes are optional, but it’s still a good idea to provide at least the `description`, `homepage` and [`license`](#sec-meta-license). + + - You can use `nix-prefetch-url url` to get the SHA-256 hash of source distributions. There are similar commands as `nix-prefetch-git` and `nix-prefetch-hg` available in `nix-prefetch-scripts` package. + + - A list of schemes for `mirror://` URLs can be found in [`pkgs/build-support/fetchurl/mirrors.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/fetchurl/mirrors.nix). + + The exact syntax and semantics of the Nix expression language, including the built-in function, are described in the Nix manual in the [chapter on writing Nix expressions](https://hydra.nixos.org/job/nix/trunk/tarball/latest/download-by-type/doc/manual/#chap-writing-nix-expressions). + +4. Add a call to the function defined in the previous step to [`pkgs/top-level/all-packages.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix) with some descriptive name for the variable, e.g. `libfoo`. + + ```ShellSession + $ emacs pkgs/top-level/all-packages.nix + ``` + + The attributes in that file are sorted by category (like “Development / Libraries”) that more-or-less correspond to the directory structure of Nixpkgs, and then by attribute name. + +5. To test whether the package builds, run the following command from the root of the nixpkgs source tree: + + ```ShellSession + $ nix-build -A libfoo + ``` + + where `libfoo` should be the variable name defined in the previous step. You may want to add the flag `-K` to keep the temporary build directory in case something fails. If the build succeeds, a symlink `./result` to the package in the Nix store is created. + +6. If you want to install the package into your profile (optional), do + + ```ShellSession + $ nix-env -f . -iA libfoo + ``` + +7. Optionally commit the new package and open a pull request [to nixpkgs](https://github.com/NixOS/nixpkgs/pulls), or use [the Patches category](https://discourse.nixos.org/t/about-the-patches-category/477) on Discourse for sending a patch without a GitHub account. + ## Hierarchy {#sec-hierarchy} Each package should be stored in its own directory somewhere in the `pkgs/` tree, i.e. in `pkgs/category/subcategory/.../pkgname`. Below are some rules for picking the right category for a package. Many packages fall under several categories; what matters is the _primary_ purpose of a package. For example, the `libxml2` package builds both a library and some tools; but it’s a library foremost, so it goes under `pkgs/development/libraries`. From f3a050a191cc20d834931328c0fc3c089c3d3716 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 25 Jul 2023 18:17:24 +0200 Subject: [PATCH 08/42] doc/reviewing-contributions: Rough move to new contribution doc files No content was changed, new titles are wrapped with () to signal that they will need to be decided on in a future commit. Section in the manual have been preserved with a simple redirect to GitHub, the proper anchors should be filled out in a future commit once the new section names are decided. --- CONTRIBUTING-new.md | 46 ++- .../reviewing-contributions.chapter.md | 305 +----------------- maintainers/README.md | 107 ++++++ nixos/README.md | 75 +++++ pkgs/README.md | 101 ++++++ 5 files changed, 337 insertions(+), 297 deletions(-) diff --git a/CONTRIBUTING-new.md b/CONTRIBUTING-new.md index 46b08333a71d..9265fb9444b5 100644 --- a/CONTRIBUTING-new.md +++ b/CONTRIBUTING-new.md @@ -144,11 +144,55 @@ Anything that does not cause user or downstream dependency regressions can be ba - Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) - Security critical applications (E.g. `firefox`) -## (Merging a pull request) +## Reviewing contributions {#chap-reviewing-contributions} + +::: {.warning} +The following section is a draft, and the policy for reviewing is still being discussed in issues such as [#11166](https://github.com/NixOS/nixpkgs/issues/11166) and [#20836](https://github.com/NixOS/nixpkgs/issues/20836). +::: + +The Nixpkgs project receives a fairly high number of contributions via GitHub pull requests. Reviewing and approving these is an important task and a way to contribute to the project. + +The high change rate of Nixpkgs makes any pull request that remains open for too long subject to conflicts that will require extra work from the submitter or the merger. Reviewing pull requests in a timely manner and being responsive to the comments is the key to avoid this issue. GitHub provides sort filters that can be used to see the [most recently](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc) and the [least recently](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-asc) updated pull requests. We highly encourage looking at [this list of ready to merge, unreviewed pull requests](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+review%3Anone+status%3Asuccess+-label%3A%222.status%3A+work-in-progress%22+no%3Aproject+no%3Aassignee+no%3Amilestone). + +When reviewing a pull request, please always be nice and polite. Controversial changes can lead to controversial opinions, but it is important to respect every community member and their work. + +GitHub provides reactions as a simple and quick way to provide feedback to pull requests or any comments. The thumb-down reaction should be used with care and if possible accompanied with some explanation so the submitter has directions to improve their contribution. + +Pull request reviews should include a list of what has been reviewed in a comment, so other reviewers and mergers can know the state of the review. + +All the review template samples provided in this section are generic and meant as examples. Their usage is optional and the reviewer is free to adapt them to their liking. + +### Other submissions {#reviewing-contributions-other-submissions} + +Other type of submissions requires different reviewing steps. + +If you consider having enough knowledge and experience in a topic and would like to be a long-term reviewer for related submissions, please contact the current reviewers for that topic. They will give you information about the reviewing process. The main reviewers for a topic can be hard to find as there is no list, but checking past pull requests to see who reviewed or git-blaming the code to see who committed to that topic can give some hints. + +Container system, boot system and library changes are some examples of the pull requests fitting this category. + +## (Merging a pull request) | Merging pull requests {#reviewing-contributions--merging-pull-requests} The *Nixpkgs committers* are people who have been given permission to merge. +It is possible for community members that have enough knowledge and experience on a special topic to contribute by merging pull requests. + +In case the PR is stuck waiting for the original author to apply a trivial +change (a typo, capitalisation change, etc.) and the author allowed the members +to modify the PR, consider applying it yourself. (or commit the existing review +suggestion) You should pay extra attention to make sure the addition doesn't go +against the idea of the original PR and would not be opposed by the author. + + + +Please see the discussion in [GitHub nixpkgs issue #50105](https://github.com/NixOS/nixpkgs/issues/50105) for information on how to proceed to be granted this level of access. + +In a case a contributor definitively leaves the Nix community, they should create an issue or post on [Discourse](https://discourse.nixos.org) with references of packages and modules they maintain so the maintainership can be taken over by other contributors. + ## (Flow of changes) Most contributions are based on and merged into these branches: diff --git a/doc/contributing/reviewing-contributions.chapter.md b/doc/contributing/reviewing-contributions.chapter.md index 10c72fe3d13e..c291ef5b1293 100644 --- a/doc/contributing/reviewing-contributions.chapter.md +++ b/doc/contributing/reviewing-contributions.chapter.md @@ -1,322 +1,35 @@ # Reviewing contributions {#chap-reviewing-contributions} -::: {.warning} -The following section is a draft, and the policy for reviewing is still being discussed in issues such as [#11166](https://github.com/NixOS/nixpkgs/issues/11166) and [#20836](https://github.com/NixOS/nixpkgs/issues/20836). -::: - -The Nixpkgs project receives a fairly high number of contributions via GitHub pull requests. Reviewing and approving these is an important task and a way to contribute to the project. - -The high change rate of Nixpkgs makes any pull request that remains open for too long subject to conflicts that will require extra work from the submitter or the merger. Reviewing pull requests in a timely manner and being responsive to the comments is the key to avoid this issue. GitHub provides sort filters that can be used to see the [most recently](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc) and the [least recently](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-asc) updated pull requests. We highly encourage looking at [this list of ready to merge, unreviewed pull requests](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+review%3Anone+status%3Asuccess+-label%3A%222.status%3A+work-in-progress%22+no%3Aproject+no%3Aassignee+no%3Amilestone). - -When reviewing a pull request, please always be nice and polite. Controversial changes can lead to controversial opinions, but it is important to respect every community member and their work. - -GitHub provides reactions as a simple and quick way to provide feedback to pull requests or any comments. The thumb-down reaction should be used with care and if possible accompanied with some explanation so the submitter has directions to improve their contribution. - -Pull request reviews should include a list of what has been reviewed in a comment, so other reviewers and mergers can know the state of the review. - -All the review template samples provided in this section are generic and meant as examples. Their usage is optional and the reviewer is free to adapt them to their liking. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ## Package updates {#reviewing-contributions-package-updates} -A package update is the most trivial and common type of pull request. These pull requests mainly consist of updating the version part of the package name and the source hash. - -It can happen that non-trivial updates include patches or more complex changes. - -Reviewing process: - -- Ensure that the package versioning fits the guidelines. -- Ensure that the commit text fits the guidelines. -- Ensure that the package maintainers are notified. - - [CODEOWNERS](https://help.github.com/articles/about-codeowners) will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers. -- Ensure that the meta field information is correct. - - License can change with version updates, so it should be checked to match the upstream license. - - If the package has no maintainer, a maintainer must be set. This can be the update submitter or a community member that accepts to take maintainership of the package. -- Ensure that the code contains no typos. -- Building the package locally. - - pull requests are often targeted to the master or staging branch, and building the pull request locally when it is submitted can trigger many source builds. - - It is possible to rebase the changes on nixos-unstable or nixpkgs-unstable for easier review by running the following commands from a nixpkgs clone. - - ```ShellSession - $ git fetch origin nixos-unstable - $ git fetch origin pull/PRNUMBER/head - $ git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD - ``` - - - The first command fetches the nixos-unstable branch. - - The second command fetches the pull request changes, `PRNUMBER` is the number at the end of the pull request title and `BASEBRANCH` the base branch of the pull request. - - The third command rebases the pull request changes to the nixos-unstable branch. - - The [nixpkgs-review](https://github.com/Mic92/nixpkgs-review) tool can be used to review a pull request content in a single command. `PRNUMBER` should be replaced by the number at the end of the pull request title. You can also provide the full github pull request url. - - ```ShellSession - $ nix-shell -p nixpkgs-review --run "nixpkgs-review pr PRNUMBER" - ``` -- Running every binary. - -Sample template for a package update review is provided below. - -```markdown -##### Reviewed points - -- [ ] package name fits guidelines -- [ ] package version fits guidelines -- [ ] package build on ARCHITECTURE -- [ ] executables tested on ARCHITECTURE -- [ ] all depending packages build -- [ ] patches have a comment describing either the upstream URL or a reason why the patch wasn't upstreamed -- [ ] patches that are remotely available are fetched rather than vendored - -##### Possible improvements - -##### Comments -``` +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ## New packages {#reviewing-contributions-new-packages} -New packages are a common type of pull requests. These pull requests consists in adding a new nix-expression for a package. - -Review process: - -- Ensure that the package versioning fits the guidelines. -- Ensure that the commit name fits the guidelines. -- Ensure that the meta fields contain correct information. - - License must match the upstream license. - - Platforms should be set (or the package will not get binary substitutes). - - Maintainers must be set. This can be the package submitter or a community member that accepts taking up maintainership of the package. -- Report detected typos. -- Ensure the package source: - - Uses mirror URLs when available. - - Uses the most appropriate functions (e.g. packages from GitHub should use `fetchFromGitHub`). -- Building the package locally. -- Running every binary. - -Sample template for a new package review is provided below. - -```markdown -##### Reviewed points - -- [ ] package path fits guidelines -- [ ] package name fits guidelines -- [ ] package version fits guidelines -- [ ] package build on ARCHITECTURE -- [ ] executables tested on ARCHITECTURE -- [ ] `meta.description` is set and fits guidelines -- [ ] `meta.license` fits upstream license -- [ ] `meta.platforms` is set -- [ ] `meta.maintainers` is set -- [ ] build time only dependencies are declared in `nativeBuildInputs` -- [ ] source is fetched using the appropriate function -- [ ] the list of `phases` is not overridden -- [ ] when a phase (like `installPhase`) is overridden it starts with `runHook preInstall` and ends with `runHook postInstall`. -- [ ] patches have a comment describing either the upstream URL or a reason why the patch wasn't upstreamed -- [ ] patches that are remotely available are fetched rather than vendored - -##### Possible improvements - -##### Comments -``` +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ## Module updates {#reviewing-contributions-module-updates} -Module updates are submissions changing modules in some ways. These often contains changes to the options or introduce new options. - -Reviewing process: - -- Ensure that the module maintainers are notified. - - [CODEOWNERS](https://help.github.com/articles/about-codeowners/) will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers. -- Ensure that the module tests, if any, are succeeding. -- Ensure that the introduced options are correct. - - Type should be appropriate (string related types differs in their merging capabilities, `loaOf` and `string` types are deprecated). - - Description, default and example should be provided. -- Ensure that option changes are backward compatible. - - `mkRenamedOptionModuleWith` provides a way to make option changes backward compatible. -- Ensure that removed options are declared with `mkRemovedOptionModule` -- Ensure that changes that are not backward compatible are mentioned in release notes. -- Ensure that documentations affected by the change is updated. - -Sample template for a module update review is provided below. - -```markdown -##### Reviewed points - -- [ ] changes are backward compatible -- [ ] removed options are declared with `mkRemovedOptionModule` -- [ ] changes that are not backward compatible are documented in release notes -- [ ] module tests succeed on ARCHITECTURE -- [ ] options types are appropriate -- [ ] options description is set -- [ ] options example is provided -- [ ] documentation affected by the changes is updated - -##### Possible improvements - -##### Comments -``` +This section has been moved to [nixos/README.md](https://github.com/NixOS/nixpkgs/blob/master/nixos/README.md). ## New modules {#reviewing-contributions-new-modules} -New modules submissions introduce a new module to NixOS. - -Reviewing process: - -- Ensure that the module tests, if any, are succeeding. -- Ensure that the introduced options are correct. - - Type should be appropriate (string related types differs in their merging capabilities, `loaOf` and `string` types are deprecated). - - Description, default and example should be provided. -- Ensure that module `meta` field is present - - Maintainers should be declared in `meta.maintainers`. - - Module documentation should be declared with `meta.doc`. -- Ensure that the module respect other modules functionality. - - For example, enabling a module should not open firewall ports by default. - -Sample template for a new module review is provided below. - -```markdown -##### Reviewed points - -- [ ] module path fits the guidelines -- [ ] module tests succeed on ARCHITECTURE -- [ ] options have appropriate types -- [ ] options have default -- [ ] options have example -- [ ] options have descriptions -- [ ] No unneeded package is added to environment.systemPackages -- [ ] meta.maintainers is set -- [ ] module documentation is declared in meta.doc - -##### Possible improvements - -##### Comments -``` +This section has been moved to [nixos/README.md](https://github.com/NixOS/nixpkgs/blob/master/nixos/README.md). ## Individual maintainer list {#reviewing-contributions-individual-maintainer-list} -When adding users to `maintainers/maintainer-list.nix`, the following -checks should be performed: - -- If the user has specified a GPG key, verify that the commit is - signed by their key. - - First, validate that the commit adding the maintainer is signed by - the key the maintainer listed. Check out the pull request and - compare its signing key with the listed key in the commit. - - If the commit is not signed or it is signed by a different user, ask - them to either recommit using that key or to remove their key - information. - - Given a maintainer entry like this: - - ``` nix - { - example = { - email = "user@example.com"; - name = "Example User"; - keys = [{ - fingerprint = "0000 0000 2A70 6423 0AED 3C11 F04F 7A19 AAA6 3AFE"; - }]; - } - }; - ``` - - First receive their key from a keyserver: - - $ gpg --recv-keys 0xF04F7A19AAA63AFE - gpg: key 0xF04F7A19AAA63AFE: public key "Example " imported - gpg: Total number processed: 1 - gpg: imported: 1 - - Then check the commit is signed by that key: - - $ git log --show-signature - commit b87862a4f7d32319b1de428adb6cdbdd3a960153 - gpg: Signature made Wed Mar 12 13:32:24 2003 +0000 - gpg: using RSA key 000000002A7064230AED3C11F04F7A19AAA63AFE - gpg: Good signature from "Example User - Author: Example User - Date: Wed Mar 12 13:32:24 2003 +0000 - - maintainers: adding example - - and validate that there is a `Good signature` and the printed key - matches the user's submitted key. - - Note: GitHub's "Verified" label does not display the user's full key - fingerprint, and should not be used for validating the key matches. - -- If the user has specified a `github` account name, ensure they have - also specified a `githubId` and verify the two match. - - Maintainer entries that include a `github` field must also include - their `githubId`. People can and do change their GitHub name - frequently, and the ID is used as the official and stable identity - of the maintainer. - - Given a maintainer entry like this: - - ``` nix - { - example = { - email = "user@example.com"; - name = "Example User"; - github = "ghost"; - githubId = 10137; - } - }; - ``` - - First, make sure that the listed GitHub handle matches the author of - the commit. - - Then, visit the URL `https://api.github.com/users/ghost` and - validate that the `id` field matches the provided `githubId`. +This section has been moved to [maintainers/README.md](https://github.com/NixOS/nixpkgs/blob/master/maintainers/README.md). ## Maintainer teams {#reviewing-contributions-maintainer-teams} -Feel free to create a new maintainer team in `maintainers/team-list.nix` -when a group is collectively responsible for a collection of packages. -Use taste and personal judgement when deciding if a team is warranted. - -Teams are allowed to define their own rules about membership. - -For example, some teams will represent a business or other group which -wants to carefully track its members. Other teams may be very open about -who can join, and allow anybody to participate. - -When reviewing changes to a team, read the team's scope and the context -around the member list for indications about the team's membership -policy. - -In any case, request reviews from the existing team members. If the team -lists no specific membership policy, feel free to merge changes to the -team after giving the existing members a few days to respond. - -*Important:* If a team says it is a closed group, do not merge additions -to the team without an approval by at least one existing member. +This section has been moved to [maintainers/README.md](https://github.com/NixOS/nixpkgs/blob/master/maintainers/README.md). ## Other submissions {#reviewing-contributions-other-submissions} -Other type of submissions requires different reviewing steps. - -If you consider having enough knowledge and experience in a topic and would like to be a long-term reviewer for related submissions, please contact the current reviewers for that topic. They will give you information about the reviewing process. The main reviewers for a topic can be hard to find as there is no list, but checking past pull requests to see who reviewed or git-blaming the code to see who committed to that topic can give some hints. - -Container system, boot system and library changes are some examples of the pull requests fitting this category. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ## Merging pull requests {#reviewing-contributions--merging-pull-requests} -It is possible for community members that have enough knowledge and experience on a special topic to contribute by merging pull requests. - -In case the PR is stuck waiting for the original author to apply a trivial -change (a typo, capitalisation change, etc.) and the author allowed the members -to modify the PR, consider applying it yourself. (or commit the existing review -suggestion) You should pay extra attention to make sure the addition doesn't go -against the idea of the original PR and would not be opposed by the author. - - - -Please see the discussion in [GitHub nixpkgs issue #50105](https://github.com/NixOS/nixpkgs/issues/50105) for information on how to proceed to be granted this level of access. - -In a case a contributor definitively leaves the Nix community, they should create an issue or post on [Discourse](https://discourse.nixos.org) with references of packages and modules they maintain so the maintainership can be taken over by other contributors. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). diff --git a/maintainers/README.md b/maintainers/README.md index 3914586e5b61..4b691277bde7 100644 --- a/maintainers/README.md +++ b/maintainers/README.md @@ -5,3 +5,110 @@ maintain specific individual packages. We encourage people who care about a package to assign themselves as a maintainer. When a pull request is made against a package, OfBorg will notify the appropriate maintainer(s). + +## (Reviewing contributions) + +### Individual maintainer list {#reviewing-contributions-individual-maintainer-list} + +When adding users to `maintainers/maintainer-list.nix`, the following +checks should be performed: + +- If the user has specified a GPG key, verify that the commit is + signed by their key. + + First, validate that the commit adding the maintainer is signed by + the key the maintainer listed. Check out the pull request and + compare its signing key with the listed key in the commit. + + If the commit is not signed or it is signed by a different user, ask + them to either recommit using that key or to remove their key + information. + + Given a maintainer entry like this: + + ``` nix + { + example = { + email = "user@example.com"; + name = "Example User"; + keys = [{ + fingerprint = "0000 0000 2A70 6423 0AED 3C11 F04F 7A19 AAA6 3AFE"; + }]; + } + }; + ``` + + First receive their key from a keyserver: + + $ gpg --recv-keys 0xF04F7A19AAA63AFE + gpg: key 0xF04F7A19AAA63AFE: public key "Example " imported + gpg: Total number processed: 1 + gpg: imported: 1 + + Then check the commit is signed by that key: + + $ git log --show-signature + commit b87862a4f7d32319b1de428adb6cdbdd3a960153 + gpg: Signature made Wed Mar 12 13:32:24 2003 +0000 + gpg: using RSA key 000000002A7064230AED3C11F04F7A19AAA63AFE + gpg: Good signature from "Example User + Author: Example User + Date: Wed Mar 12 13:32:24 2003 +0000 + + maintainers: adding example + + and validate that there is a `Good signature` and the printed key + matches the user's submitted key. + + Note: GitHub's "Verified" label does not display the user's full key + fingerprint, and should not be used for validating the key matches. + +- If the user has specified a `github` account name, ensure they have + also specified a `githubId` and verify the two match. + + Maintainer entries that include a `github` field must also include + their `githubId`. People can and do change their GitHub name + frequently, and the ID is used as the official and stable identity + of the maintainer. + + Given a maintainer entry like this: + + ``` nix + { + example = { + email = "user@example.com"; + name = "Example User"; + github = "ghost"; + githubId = 10137; + } + }; + ``` + + First, make sure that the listed GitHub handle matches the author of + the commit. + + Then, visit the URL `https://api.github.com/users/ghost` and + validate that the `id` field matches the provided `githubId`. + +### Maintainer teams {#reviewing-contributions-maintainer-teams} + +Feel free to create a new maintainer team in `maintainers/team-list.nix` +when a group is collectively responsible for a collection of packages. +Use taste and personal judgement when deciding if a team is warranted. + +Teams are allowed to define their own rules about membership. + +For example, some teams will represent a business or other group which +wants to carefully track its members. Other teams may be very open about +who can join, and allow anybody to participate. + +When reviewing changes to a team, read the team's scope and the context +around the member list for indications about the team's membership +policy. + +In any case, request reviews from the existing team members. If the team +lists no specific membership policy, feel free to merge changes to the +team after giving the existing members a few days to respond. + +*Important:* If a team says it is a closed group, do not merge additions +to the team without an approval by at least one existing member. diff --git a/nixos/README.md b/nixos/README.md index 260209e94ee7..913f1eb48fbc 100644 --- a/nixos/README.md +++ b/nixos/README.md @@ -3,3 +3,78 @@ NixOS is a Linux distribution based on the purely functional package management system Nix. More information can be found at https://nixos.org/nixos and in the manual in doc/manual. + +## (Reviewing contributions) + +### Module updates {#reviewing-contributions-module-updates} + +Module updates are submissions changing modules in some ways. These often contains changes to the options or introduce new options. + +Reviewing process: + +- Ensure that the module maintainers are notified. + - [CODEOWNERS](https://help.github.com/articles/about-codeowners/) will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers. +- Ensure that the module tests, if any, are succeeding. +- Ensure that the introduced options are correct. + - Type should be appropriate (string related types differs in their merging capabilities, `loaOf` and `string` types are deprecated). + - Description, default and example should be provided. +- Ensure that option changes are backward compatible. + - `mkRenamedOptionModuleWith` provides a way to make option changes backward compatible. +- Ensure that removed options are declared with `mkRemovedOptionModule` +- Ensure that changes that are not backward compatible are mentioned in release notes. +- Ensure that documentations affected by the change is updated. + +Sample template for a module update review is provided below. + +```markdown +##### Reviewed points + +- [ ] changes are backward compatible +- [ ] removed options are declared with `mkRemovedOptionModule` +- [ ] changes that are not backward compatible are documented in release notes +- [ ] module tests succeed on ARCHITECTURE +- [ ] options types are appropriate +- [ ] options description is set +- [ ] options example is provided +- [ ] documentation affected by the changes is updated + +##### Possible improvements + +##### Comments +``` + +### New modules {#reviewing-contributions-new-modules} + +New modules submissions introduce a new module to NixOS. + +Reviewing process: + +- Ensure that the module tests, if any, are succeeding. +- Ensure that the introduced options are correct. + - Type should be appropriate (string related types differs in their merging capabilities, `loaOf` and `string` types are deprecated). + - Description, default and example should be provided. +- Ensure that module `meta` field is present + - Maintainers should be declared in `meta.maintainers`. + - Module documentation should be declared with `meta.doc`. +- Ensure that the module respect other modules functionality. + - For example, enabling a module should not open firewall ports by default. + +Sample template for a new module review is provided below. + +```markdown +##### Reviewed points + +- [ ] module path fits the guidelines +- [ ] module tests succeed on ARCHITECTURE +- [ ] options have appropriate types +- [ ] options have default +- [ ] options have example +- [ ] options have descriptions +- [ ] No unneeded package is added to environment.systemPackages +- [ ] meta.maintainers is set +- [ ] module documentation is declared in meta.doc + +##### Possible improvements + +##### Comments +``` diff --git a/pkgs/README.md b/pkgs/README.md index 3f607564c3c6..4c736e658f09 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -595,3 +595,104 @@ stdenv.mkDerivation { ... } ``` + +## (Reviewing contributions) + +### Package updates {#reviewing-contributions-package-updates} + +A package update is the most trivial and common type of pull request. These pull requests mainly consist of updating the version part of the package name and the source hash. + +It can happen that non-trivial updates include patches or more complex changes. + +Reviewing process: + +- Ensure that the package versioning fits the guidelines. +- Ensure that the commit text fits the guidelines. +- Ensure that the package maintainers are notified. + - [CODEOWNERS](https://help.github.com/articles/about-codeowners) will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers. +- Ensure that the meta field information is correct. + - License can change with version updates, so it should be checked to match the upstream license. + - If the package has no maintainer, a maintainer must be set. This can be the update submitter or a community member that accepts to take maintainership of the package. +- Ensure that the code contains no typos. +- Building the package locally. + - pull requests are often targeted to the master or staging branch, and building the pull request locally when it is submitted can trigger many source builds. + - It is possible to rebase the changes on nixos-unstable or nixpkgs-unstable for easier review by running the following commands from a nixpkgs clone. + + ```ShellSession + $ git fetch origin nixos-unstable + $ git fetch origin pull/PRNUMBER/head + $ git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD + ``` + + - The first command fetches the nixos-unstable branch. + - The second command fetches the pull request changes, `PRNUMBER` is the number at the end of the pull request title and `BASEBRANCH` the base branch of the pull request. + - The third command rebases the pull request changes to the nixos-unstable branch. + - The [nixpkgs-review](https://github.com/Mic92/nixpkgs-review) tool can be used to review a pull request content in a single command. `PRNUMBER` should be replaced by the number at the end of the pull request title. You can also provide the full github pull request url. + + ```ShellSession + $ nix-shell -p nixpkgs-review --run "nixpkgs-review pr PRNUMBER" + ``` +- Running every binary. + +Sample template for a package update review is provided below. + +```markdown +##### Reviewed points + +- [ ] package name fits guidelines +- [ ] package version fits guidelines +- [ ] package build on ARCHITECTURE +- [ ] executables tested on ARCHITECTURE +- [ ] all depending packages build +- [ ] patches have a comment describing either the upstream URL or a reason why the patch wasn't upstreamed +- [ ] patches that are remotely available are fetched rather than vendored + +##### Possible improvements + +##### Comments +``` + +### New packages {#reviewing-contributions-new-packages} + +New packages are a common type of pull requests. These pull requests consists in adding a new nix-expression for a package. + +Review process: + +- Ensure that the package versioning fits the guidelines. +- Ensure that the commit name fits the guidelines. +- Ensure that the meta fields contain correct information. + - License must match the upstream license. + - Platforms should be set (or the package will not get binary substitutes). + - Maintainers must be set. This can be the package submitter or a community member that accepts taking up maintainership of the package. +- Report detected typos. +- Ensure the package source: + - Uses mirror URLs when available. + - Uses the most appropriate functions (e.g. packages from GitHub should use `fetchFromGitHub`). +- Building the package locally. +- Running every binary. + +Sample template for a new package review is provided below. + +```markdown +##### Reviewed points + +- [ ] package path fits guidelines +- [ ] package name fits guidelines +- [ ] package version fits guidelines +- [ ] package build on ARCHITECTURE +- [ ] executables tested on ARCHITECTURE +- [ ] `meta.description` is set and fits guidelines +- [ ] `meta.license` fits upstream license +- [ ] `meta.platforms` is set +- [ ] `meta.maintainers` is set +- [ ] build time only dependencies are declared in `nativeBuildInputs` +- [ ] source is fetched using the appropriate function +- [ ] the list of `phases` is not overridden +- [ ] when a phase (like `installPhase`) is overridden it starts with `runHook preInstall` and ends with `runHook postInstall`. +- [ ] patches have a comment describing either the upstream URL or a reason why the patch wasn't upstreamed +- [ ] patches that are remotely available are fetched rather than vendored + +##### Possible improvements + +##### Comments +``` From 86f14e461ef18bf5c0dbc63f46fdc5d13d183628 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 25 Jul 2023 18:29:04 +0200 Subject: [PATCH 09/42] doc/submitting-changes: Rough move to new contribution doc files No content was changed, new titles are wrapped with () to signal that they will need to be decided on in a future commit. Section in the manual have been preserved with a simple redirect to GitHub, the proper anchors should be filled out in a future commit once the new section names are decided. --- CONTRIBUTING-new.md | 273 +++++++++++++++- .../submitting-changes.chapter.md | 300 ++---------------- pkgs/README.md | 69 ++++ 3 files changed, 363 insertions(+), 279 deletions(-) diff --git a/CONTRIBUTING-new.md b/CONTRIBUTING-new.md index 9265fb9444b5..76f7cf5f4cc8 100644 --- a/CONTRIBUTING-new.md +++ b/CONTRIBUTING-new.md @@ -27,6 +27,63 @@ under the terms of [COPYING](COPYING), which is an MIT-like license. The old config generation system used impure shell scripts and could break in specific circumstances (see #1234). +### Making patches {#submitting-changes-making-patches} + +- Read [Manual (How to write packages for Nix)](https://nixos.org/nixpkgs/manual/). + +- Fork [the Nixpkgs repository](https://github.com/nixos/nixpkgs/) on GitHub. + +- Create a branch for your future fix. + + - You can make branch from a commit of your local `nixos-version`. That will help you to avoid additional local compilations. Because you will receive packages from binary cache. For example + + ```ShellSession + $ nixos-version --hash + 0998212 + $ git checkout 0998212 + $ git checkout -b 'fix/pkg-name-update' + ``` + + - Please avoid working directly on the `master` branch. + +- Make commits of logical units. + +- If you removed pkgs or made some major NixOS changes, write about it in the release notes for the next stable release. For example `nixos/doc/manual/release-notes/rl-2003.xml`. + +- Check for unnecessary whitespace with `git diff --check` before committing. + +- Format the commit in a following way: + + ``` + (pkg-name | nixos/): (from -> to | init at version | refactor | etc) + Additional information. + ``` + + - Examples: + - `nginx: init at 2.0.1` + - `firefox: 54.0.1 -> 55.0` + - `nixos/hydra: add bazBaz option` + - `nixos/nginx: refactor config generation` + +- Test your changes. If you work with + + - nixpkgs: + + - update pkg + - `nix-env -iA pkg-attribute-name -f ` + - add pkg + - Make sure it’s in `pkgs/top-level/all-packages.nix` + - `nix-env -iA pkg-attribute-name -f ` + - _If you don’t want to install pkg in you profile_. + - `nix-build -A pkg-attribute-name ` and check results in the folder `result`. It will appear in the same directory where you did `nix-build`. + - If you installed your package with `nix-env`, you can run `nix-env -e pkg-name` where `pkg-name` is as reported by `nix-env -q` to uninstall it from your system. + + - NixOS and its modules: + - You can add new module to your NixOS configuration file (usually it’s `/etc/nixos/configuration.nix`). And do `sudo nixos-rebuild test -I nixpkgs= --fast`. + +- If you have commits `pkg-name: oh, forgot to insert whitespace`: squash commits in this case. Use `git rebase -i`. + +- [Rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) your branch against current `master`. ### Writing good commit messages @@ -40,10 +97,84 @@ Useful git commands that can help a lot with this are `git commit --patch --amen ### (Creating a pull request) +- Push your changes to your fork of nixpkgs. +- Create the pull request +- Follow [the contribution guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#submitting-changes). + When pull requests are made, our tooling automation bot, [OfBorg](https://github.com/NixOS/ofborg) will perform various checks to help ensure expression quality. +#### Pull Request Template {#submitting-changes-pull-request-template} + +The pull request template helps determine what steps have been made for a contribution so far, and will help guide maintainers on the status of a change. The motivation section of the PR should include any extra details the title does not address and link any existing issues related to the pull request. + +When a PR is created, it will be pre-populated with some checkboxes detailed below: + +##### Tested using sandboxing {#submitting-changes-tested-with-sandbox} + +When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of `fetch*` functions and files outside the Nix store. Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [sandbox](https://nixos.org/nix/manual/#conf-sandbox) in Nix manual for details. + +Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for [nixpkgs](https://github.com/NixOS/nixpkgs/) people are asked to test builds with sandboxing enabled (see `Tested using sandboxing` in the pull request template) because in sandboxing is also used. + +Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing **before** building the package: + +- **Globally enable sandboxing on NixOS**: add the following to `configuration.nix` + + ```nix + nix.useSandbox = true; + ``` + +- **Globally enable sandboxing on non-NixOS platforms**: add the following to: `/etc/nix/nix.conf` + + ```ini + sandbox = true + ``` + +##### Built on platform(s) {#submitting-changes-platform-diversity} + +Many Nix packages are designed to run on multiple platforms. As such, it’s important to let the maintainer know which platforms your changes have been tested on. It’s not always practical to test a change on all platforms, and is not required for a pull request to be merged. Only check the systems you tested the build on in this section. + +##### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) {#submitting-changes-nixos-tests} + +Packages with automated tests are much more likely to be merged in a timely fashion because it doesn’t require as much manual testing by the maintainer to verify the functionality of the package. If there are existing tests for the package, they should be run to verify your changes do not break the tests. Tests can only be run on Linux. For more details on writing and running tests, see the [section in the NixOS manual](https://nixos.org/nixos/manual/index.html#sec-nixos-tests). + +##### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` {#submitting-changes-tested-compilation} + +If you are updating a package’s version, you can use `nixpkgs-review` to make sure all packages that depend on the updated package still compile correctly. The `nixpkgs-review` utility can look for and build all dependencies either based on uncommitted changes with the `wip` option or specifying a GitHub pull request number. + +Review changes from pull request number 12345: + +```ShellSession +nix-shell -p nixpkgs-review --run "nixpkgs-review pr 12345" +``` + +Alternatively, with flakes (and analogously for the other commands below): + +```ShellSession +nix run nixpkgs#nixpkgs-review -- pr 12345 +``` + +Review uncommitted changes: + +```ShellSession +nix-shell -p nixpkgs-review --run "nixpkgs-review wip" +``` + +Review changes from last commit: + +```ShellSession +nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD" +``` + +##### Tested execution of all binary files (usually in `./result/bin/`) {#submitting-changes-tested-execution} + +It’s important to test any executables generated by a build when you change or create a package in nixpkgs. This can be done by looking in `./result/bin` and running any files in there, or at a minimum, the main executable for the package. For example, if you make a change to texlive, you probably would only check the binaries associated with the change you made rather than testing all of them. + +##### Meets Nixpkgs contribution standards {#submitting-changes-contribution-standards} + +The last checkbox is fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). The contributing document has detailed information on standards the Nix community has for commit messages, reviews, licensing of contributions you make to the project, etc... Everyone should read and understand the standards the community has for contributing before submitting a pull request. + #### Rebasing between branches (i.e. from master to staging) From time to time, changes between branches must be rebased, for example, if the @@ -144,6 +275,13 @@ Anything that does not cause user or downstream dependency regressions can be ba - Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) - Security critical applications (E.g. `firefox`) +### Hotfixing pull requests {#submitting-changes-hotfixing-pull-requests} + +- Make the appropriate changes in you branch. +- Don’t create additional commits, do + - `git rebase -i` + - `git push --force` to your branch. + ## Reviewing contributions {#chap-reviewing-contributions} ::: {.warning} @@ -193,7 +331,7 @@ Please see the discussion in [GitHub nixpkgs issue #50105](https://github.com/Ni In a case a contributor definitively leaves the Nix community, they should create an issue or post on [Discourse](https://discourse.nixos.org) with references of packages and modules they maintain so the maintainership can be taken over by other contributors. -## (Flow of changes) +## (Flow of changes) | Commit policy {#submitting-changes-commit-policy} Most contributions are based on and merged into these branches: @@ -205,6 +343,139 @@ Most contributions are based on and merged into these branches: contributed to this branch. This branch is merged into master when deemed of sufficiently high quality +- Commits must be sufficiently tested before being merged, both for the master and staging branches. +- Hydra builds for master and staging should not be used as testing platform, it’s a build farm for changes that have been already tested. +- When changing the bootloader installation process, extra care must be taken. Grub installations cannot be rolled back, hence changes may break people’s installations forever. For any non-trivial change to the bootloader please file a PR asking for review, especially from \@edolstra. + +### Branches {#submitting-changes-branches} + +The `nixpkgs` repository has three major branches: +- `master` +- `staging` +- `staging-next` + +The most important distinction between them is that `staging` +(colored red in the diagram below) can receive commits which cause +a mass-rebuild (for example, anything that changes the `drvPath` of +`stdenv`). The other two branches `staging-next` and `master` +(colored green in the diagram below) can *not* receive commits which +cause a mass-rebuild. + +Arcs between the branches show possible merges into these branches, +either from other branches or from independently submitted PRs. The +colors of these edges likewise show whether or not they could +trigger a mass rebuild (red) or must not trigger a mass rebuild +(green). + +Hydra runs automatic builds for the green branches. + +Notice that the automatic merges are all green arrows. This is by +design. Any merge which might cause a mass rebuild on a branch +which has automatic builds (`staging-next`, `master`) will be a +manual merge to make sure it is good use of compute power. + +Nixpkgs has two branches so that there is one branch (`staging`) +which accepts mass-rebuilding commits, and one fast-rebuilding +branch which accepts independent PRs (`master`). The `staging-next` +branch allows the Hydra operators to batch groups of commits to +`staging` to be built. By keeping the `staging-next` branch +separate from `staging`, this batching does not block +developers from merging changes into `staging`. + +```{.graphviz caption="Staging workflow"} +digraph { + master [color="green" fontcolor=green] + "staging-next" [color="green" fontcolor=green] + staging [color="red" fontcolor=red] + + "small changes" [fontcolor=green shape=none] + "small changes" -> master [color=green] + + "mass-rebuilds and other large changes" [fontcolor=red shape=none] + "mass-rebuilds and other large changes" -> staging [color=red] + + "critical security fixes" [fontcolor=green shape=none] + "critical security fixes" -> master [color=green] + + "staging fixes which do not cause staging to mass-rebuild" [fontcolor=green shape=none] + "staging fixes which do not cause staging to mass-rebuild" -> "staging-next" [color=green] + + "staging-next" -> master [color="red"] [label="manual merge"] [fontcolor="red"] + "staging" -> "staging-next" [color="red"] [label="manual merge"] [fontcolor="red"] + + master -> "staging-next" [color="green"] [label="automatic merge (GitHub Action)"] [fontcolor="green"] + "staging-next" -> staging [color="green"] [label="automatic merge (GitHub Action)"] [fontcolor="green"] +} +``` + +[This GitHub Action](https://github.com/NixOS/nixpkgs/blob/master/.github/workflows/periodic-merge-6h.yml) brings changes from `master` to `staging-next` and from `staging-next` to `staging` every 6 hours; these are the green arrows in the diagram above. The red arrows in the diagram above are done manually and much less frequently. You can get an idea of how often these merges occur by looking at the git history. + + +#### Master branch {#submitting-changes-master-branch} + +The `master` branch is the main development branch. It should only see non-breaking commits that do not cause mass rebuilds. + +#### Staging branch {#submitting-changes-staging-branch} + +The `staging` branch is a development branch where mass-rebuilds go. Mass rebuilds are commits that cause rebuilds for many packages, like more than 500 (or perhaps, if it's 'light' packages, 1000). It should only see non-breaking mass-rebuild commits. That means it is not to be used for testing, and changes must have been well tested already. If the branch is already in a broken state, please refrain from adding extra new breakages. + +During the process of a releasing a new NixOS version, this branch or the release-critical packages can be restricted to non-breaking changes. + +#### Staging-next branch {#submitting-changes-staging-next-branch} + +The `staging-next` branch is for stabilizing mass-rebuilds submitted to the `staging` branch prior to merging them into `master`. Mass-rebuilds must go via the `staging` branch. It must only see non-breaking commits that are fixing issues blocking it from being merged into the `master` branch. + +If the branch is already in a broken state, please refrain from adding extra new breakages. Stabilize it for a few days and then merge into master. + +During the process of a releasing a new NixOS version, this branch or the release-critical packages can be restricted to non-breaking changes. + +#### Stable release branches {#submitting-changes-stable-release-branches} + +The same staging workflow applies to stable release branches, but the main branch is called `release-*` instead of `master`. + +Example branch names: `release-21.11`, `staging-21.11`, `staging-next-21.11`. + +Most changes added to the stable release branches are cherry-picked (“backported”) from the `master` and staging branches. + +#### Automatically backporting a Pull Request {#submitting-changes-stable-release-branches-automatic-backports} + +Assign label `backport ` (e.g. `backport release-21.11`) to the PR and a backport PR is automatically created after the PR is merged. + +#### Manually backporting changes {#submitting-changes-stable-release-branches-manual-backports} + +Cherry-pick changes via `git cherry-pick -x ` so that the original commit id is included in the commit message. + +Add a reason for the backport when it is not obvious from the original commit message. You can do this by cherry picking with `git cherry-pick -xe `, which allows editing the commit message. This is not needed for minor version updates that include security and bug fixes but don't add new features or when the commit fixes an otherwise broken package. + +Here is an example of a cherry-picked commit message with good reason description: + +``` +zfs: Keep trying root import until it works + +Works around #11003. + +(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9) + +Reason: several people cannot boot with ZFS on NVMe +``` + +Other examples of reasons are: + +- Previously the build would fail due to, e.g., `getaddrinfo` not being defined +- The previous download links were all broken +- Crash when starting on some X11 systems + +#### Acceptable backport criteria {#acceptable-backport-criteria} + +The stable branch does have some changes which cannot be backported. Most notable are breaking changes. The desire is to have stable users be uninterrupted when updating packages. + +However, many changes are able to be backported, including: +- New Packages / Modules +- Security / Patch updates +- Version updates which include new functionality (but no breaking changes) +- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) +- Security critical applications (E.g. `firefox`) + ## Coding conventions {#chap-conventions} ### File naming and organisation {#sec-organisation} diff --git a/doc/contributing/submitting-changes.chapter.md b/doc/contributing/submitting-changes.chapter.md index 5a3d269569f0..d47a5359779e 100644 --- a/doc/contributing/submitting-changes.chapter.md +++ b/doc/contributing/submitting-changes.chapter.md @@ -1,344 +1,88 @@ # Submitting changes {#chap-submitting-changes} -## Making patches {#submitting-changes-making-patches} - -- Read [Manual (How to write packages for Nix)](https://nixos.org/nixpkgs/manual/). - -- Fork [the Nixpkgs repository](https://github.com/nixos/nixpkgs/) on GitHub. - -- Create a branch for your future fix. - - - You can make branch from a commit of your local `nixos-version`. That will help you to avoid additional local compilations. Because you will receive packages from binary cache. For example - - ```ShellSession - $ nixos-version --hash - 0998212 - $ git checkout 0998212 - $ git checkout -b 'fix/pkg-name-update' - ``` - - - Please avoid working directly on the `master` branch. - -- Make commits of logical units. - -- If you removed pkgs or made some major NixOS changes, write about it in the release notes for the next stable release. For example `nixos/doc/manual/release-notes/rl-2003.xml`. - -- Check for unnecessary whitespace with `git diff --check` before committing. - -- Format the commit in a following way: - - ``` - (pkg-name | nixos/): (from -> to | init at version | refactor | etc) - Additional information. - ``` - - - Examples: - - `nginx: init at 2.0.1` - - `firefox: 54.0.1 -> 55.0` - - `nixos/hydra: add bazBaz option` - - `nixos/nginx: refactor config generation` - -- Test your changes. If you work with - - - nixpkgs: - - - update pkg - - `nix-env -iA pkg-attribute-name -f ` - - add pkg - - Make sure it’s in `pkgs/top-level/all-packages.nix` - - `nix-env -iA pkg-attribute-name -f ` - - _If you don’t want to install pkg in you profile_. - - `nix-build -A pkg-attribute-name ` and check results in the folder `result`. It will appear in the same directory where you did `nix-build`. - - If you installed your package with `nix-env`, you can run `nix-env -e pkg-name` where `pkg-name` is as reported by `nix-env -q` to uninstall it from your system. - - - NixOS and its modules: - - You can add new module to your NixOS configuration file (usually it’s `/etc/nixos/configuration.nix`). And do `sudo nixos-rebuild test -I nixpkgs= --fast`. - -- If you have commits `pkg-name: oh, forgot to insert whitespace`: squash commits in this case. Use `git rebase -i`. - -- [Rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) your branch against current `master`. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ## Submitting changes {#submitting-changes-submitting-changes} -- Push your changes to your fork of nixpkgs. -- Create the pull request -- Follow [the contribution guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#submitting-changes). +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ## Submitting security fixes {#submitting-changes-submitting-security-fixes} -Security fixes are submitted in the same way as other changes and thus the same guidelines apply. - -- If a new version fixing the vulnerability has been released, update the package; -- If the security fix comes in the form of a patch and a CVE is available, then add the patch to the Nixpkgs tree, and apply it to the package. - The name of the patch should be the CVE identifier, so e.g. `CVE-2019-13636.patch`; If a patch is fetched the name needs to be set as well, e.g.: - - ```nix - (fetchpatch { - name = "CVE-2019-11068.patch"; - url = "https://gitlab.gnome.org/GNOME/libxslt/commit/e03553605b45c88f0b4b2980adfbbb8f6fca2fd6.patch"; - hash = "sha256-SEKe/8HcW0UBHCfPTTOnpRlzmV2nQPPeL6HOMxBZd14="; - }) - ``` - -If a security fix applies to both master and a stable release then, similar to regular changes, they are preferably delivered via master first and cherry-picked to the release branch. - -Critical security fixes may by-pass the staging branches and be delivered directly to release branches such as `master` and `release-*`. +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ## Deprecating/removing packages {#submitting-changes-deprecating-packages} -There is currently no policy when to remove a package. - -Before removing a package, one should try to find a new maintainer or fix smaller issues first. +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ### Steps to remove a package from Nixpkgs {#steps-to-remove-a-package-from-nixpkgs} -We use jbidwatcher as an example for a discontinued project here. - -1. Have Nixpkgs checked out locally and up to date. -1. Create a new branch for your change, e.g. `git checkout -b jbidwatcher` -1. Remove the actual package including its directory, e.g. `git rm -rf pkgs/applications/misc/jbidwatcher` -1. Remove the package from the list of all packages (`pkgs/top-level/all-packages.nix`). -1. Add an alias for the package name in `pkgs/top-level/aliases.nix` (There is also `pkgs/applications/editors/vim/plugins/aliases.nix`. Package sets typically do not have aliases, so we can't add them there.) - - For example in this case: - - ``` - jbidwatcher = throw "jbidwatcher was discontinued in march 2021"; # added 2021-03-15 - ``` - - The throw message should explain in short why the package was removed for users that still have it installed. - -1. Test if the changes introduced any issues by running `nix-env -qaP -f . --show-trace`. It should show the list of packages without errors. -1. Commit the changes. Explain again why the package was removed. If it was declared discontinued upstream, add a link to the source. - - ```ShellSession - $ git add pkgs/applications/misc/jbidwatcher/default.nix pkgs/top-level/all-packages.nix pkgs/top-level/aliases.nix - $ git commit - ``` - - Example commit message: - - ``` - jbidwatcher: remove - - project was discontinued in march 2021. the program does not work anymore because ebay changed the login. - - https://web.archive.org/web/20210315205723/http://www.jbidwatcher.com/ - ``` - -1. Push changes to your GitHub fork with `git push` -1. Create a pull request against Nixpkgs. Mention the package maintainer. - -This is how the pull request looks like in this case: [https://github.com/NixOS/nixpkgs/pull/116470](https://github.com/NixOS/nixpkgs/pull/116470) +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ## Pull Request Template {#submitting-changes-pull-request-template} -The pull request template helps determine what steps have been made for a contribution so far, and will help guide maintainers on the status of a change. The motivation section of the PR should include any extra details the title does not address and link any existing issues related to the pull request. - -When a PR is created, it will be pre-populated with some checkboxes detailed below: +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ### Tested using sandboxing {#submitting-changes-tested-with-sandbox} -When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of `fetch*` functions and files outside the Nix store. Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [sandbox](https://nixos.org/nix/manual/#conf-sandbox) in Nix manual for details. - -Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for [nixpkgs](https://github.com/NixOS/nixpkgs/) people are asked to test builds with sandboxing enabled (see `Tested using sandboxing` in the pull request template) because in sandboxing is also used. - -Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing **before** building the package: - -- **Globally enable sandboxing on NixOS**: add the following to `configuration.nix` - - ```nix - nix.useSandbox = true; - ``` - -- **Globally enable sandboxing on non-NixOS platforms**: add the following to: `/etc/nix/nix.conf` - - ```ini - sandbox = true - ``` +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ### Built on platform(s) {#submitting-changes-platform-diversity} -Many Nix packages are designed to run on multiple platforms. As such, it’s important to let the maintainer know which platforms your changes have been tested on. It’s not always practical to test a change on all platforms, and is not required for a pull request to be merged. Only check the systems you tested the build on in this section. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) {#submitting-changes-nixos-tests} -Packages with automated tests are much more likely to be merged in a timely fashion because it doesn’t require as much manual testing by the maintainer to verify the functionality of the package. If there are existing tests for the package, they should be run to verify your changes do not break the tests. Tests can only be run on Linux. For more details on writing and running tests, see the [section in the NixOS manual](https://nixos.org/nixos/manual/index.html#sec-nixos-tests). +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` {#submitting-changes-tested-compilation} -If you are updating a package’s version, you can use `nixpkgs-review` to make sure all packages that depend on the updated package still compile correctly. The `nixpkgs-review` utility can look for and build all dependencies either based on uncommitted changes with the `wip` option or specifying a GitHub pull request number. - -Review changes from pull request number 12345: - -```ShellSession -nix-shell -p nixpkgs-review --run "nixpkgs-review pr 12345" -``` - -Alternatively, with flakes (and analogously for the other commands below): - -```ShellSession -nix run nixpkgs#nixpkgs-review -- pr 12345 -``` - -Review uncommitted changes: - -```ShellSession -nix-shell -p nixpkgs-review --run "nixpkgs-review wip" -``` - -Review changes from last commit: - -```ShellSession -nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD" -``` +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ### Tested execution of all binary files (usually in `./result/bin/`) {#submitting-changes-tested-execution} -It’s important to test any executables generated by a build when you change or create a package in nixpkgs. This can be done by looking in `./result/bin` and running any files in there, or at a minimum, the main executable for the package. For example, if you make a change to texlive, you probably would only check the binaries associated with the change you made rather than testing all of them. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ### Meets Nixpkgs contribution standards {#submitting-changes-contribution-standards} -The last checkbox is fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). The contributing document has detailed information on standards the Nix community has for commit messages, reviews, licensing of contributions you make to the project, etc... Everyone should read and understand the standards the community has for contributing before submitting a pull request. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ## Hotfixing pull requests {#submitting-changes-hotfixing-pull-requests} -- Make the appropriate changes in you branch. -- Don’t create additional commits, do - - `git rebase -i` - - `git push --force` to your branch. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ## Commit policy {#submitting-changes-commit-policy} -- Commits must be sufficiently tested before being merged, both for the master and staging branches. -- Hydra builds for master and staging should not be used as testing platform, it’s a build farm for changes that have been already tested. -- When changing the bootloader installation process, extra care must be taken. Grub installations cannot be rolled back, hence changes may break people’s installations forever. For any non-trivial change to the bootloader please file a PR asking for review, especially from \@edolstra. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). ### Branches {#submitting-changes-branches} -The `nixpkgs` repository has three major branches: -- `master` -- `staging` -- `staging-next` - -The most important distinction between them is that `staging` -(colored red in the diagram below) can receive commits which cause -a mass-rebuild (for example, anything that changes the `drvPath` of -`stdenv`). The other two branches `staging-next` and `master` -(colored green in the diagram below) can *not* receive commits which -cause a mass-rebuild. - -Arcs between the branches show possible merges into these branches, -either from other branches or from independently submitted PRs. The -colors of these edges likewise show whether or not they could -trigger a mass rebuild (red) or must not trigger a mass rebuild -(green). - -Hydra runs automatic builds for the green branches. - -Notice that the automatic merges are all green arrows. This is by -design. Any merge which might cause a mass rebuild on a branch -which has automatic builds (`staging-next`, `master`) will be a -manual merge to make sure it is good use of compute power. - -Nixpkgs has two branches so that there is one branch (`staging`) -which accepts mass-rebuilding commits, and one fast-rebuilding -branch which accepts independent PRs (`master`). The `staging-next` -branch allows the Hydra operators to batch groups of commits to -`staging` to be built. By keeping the `staging-next` branch -separate from `staging`, this batching does not block -developers from merging changes into `staging`. - -```{.graphviz caption="Staging workflow"} -digraph { - master [color="green" fontcolor=green] - "staging-next" [color="green" fontcolor=green] - staging [color="red" fontcolor=red] - - "small changes" [fontcolor=green shape=none] - "small changes" -> master [color=green] - - "mass-rebuilds and other large changes" [fontcolor=red shape=none] - "mass-rebuilds and other large changes" -> staging [color=red] - - "critical security fixes" [fontcolor=green shape=none] - "critical security fixes" -> master [color=green] - - "staging fixes which do not cause staging to mass-rebuild" [fontcolor=green shape=none] - "staging fixes which do not cause staging to mass-rebuild" -> "staging-next" [color=green] - - "staging-next" -> master [color="red"] [label="manual merge"] [fontcolor="red"] - "staging" -> "staging-next" [color="red"] [label="manual merge"] [fontcolor="red"] - - master -> "staging-next" [color="green"] [label="automatic merge (GitHub Action)"] [fontcolor="green"] - "staging-next" -> staging [color="green"] [label="automatic merge (GitHub Action)"] [fontcolor="green"] -} -``` - -[This GitHub Action](https://github.com/NixOS/nixpkgs/blob/master/.github/workflows/periodic-merge-6h.yml) brings changes from `master` to `staging-next` and from `staging-next` to `staging` every 6 hours; these are the green arrows in the diagram above. The red arrows in the diagram above are done manually and much less frequently. You can get an idea of how often these merges occur by looking at the git history. - +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). #### Master branch {#submitting-changes-master-branch} -The `master` branch is the main development branch. It should only see non-breaking commits that do not cause mass rebuilds. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). #### Staging branch {#submitting-changes-staging-branch} -The `staging` branch is a development branch where mass-rebuilds go. Mass rebuilds are commits that cause rebuilds for many packages, like more than 500 (or perhaps, if it's 'light' packages, 1000). It should only see non-breaking mass-rebuild commits. That means it is not to be used for testing, and changes must have been well tested already. If the branch is already in a broken state, please refrain from adding extra new breakages. - -During the process of a releasing a new NixOS version, this branch or the release-critical packages can be restricted to non-breaking changes. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). #### Staging-next branch {#submitting-changes-staging-next-branch} -The `staging-next` branch is for stabilizing mass-rebuilds submitted to the `staging` branch prior to merging them into `master`. Mass-rebuilds must go via the `staging` branch. It must only see non-breaking commits that are fixing issues blocking it from being merged into the `master` branch. - -If the branch is already in a broken state, please refrain from adding extra new breakages. Stabilize it for a few days and then merge into master. - -During the process of a releasing a new NixOS version, this branch or the release-critical packages can be restricted to non-breaking changes. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). #### Stable release branches {#submitting-changes-stable-release-branches} -The same staging workflow applies to stable release branches, but the main branch is called `release-*` instead of `master`. - -Example branch names: `release-21.11`, `staging-21.11`, `staging-next-21.11`. - -Most changes added to the stable release branches are cherry-picked (“backported”) from the `master` and staging branches. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). #### Automatically backporting a Pull Request {#submitting-changes-stable-release-branches-automatic-backports} -Assign label `backport ` (e.g. `backport release-21.11`) to the PR and a backport PR is automatically created after the PR is merged. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). #### Manually backporting changes {#submitting-changes-stable-release-branches-manual-backports} -Cherry-pick changes via `git cherry-pick -x ` so that the original commit id is included in the commit message. - -Add a reason for the backport when it is not obvious from the original commit message. You can do this by cherry picking with `git cherry-pick -xe `, which allows editing the commit message. This is not needed for minor version updates that include security and bug fixes but don't add new features or when the commit fixes an otherwise broken package. - -Here is an example of a cherry-picked commit message with good reason description: - -``` -zfs: Keep trying root import until it works - -Works around #11003. - -(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9) - -Reason: several people cannot boot with ZFS on NVMe -``` - -Other examples of reasons are: - -- Previously the build would fail due to, e.g., `getaddrinfo` not being defined -- The previous download links were all broken -- Crash when starting on some X11 systems +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). #### Acceptable backport criteria {#acceptable-backport-criteria} -The stable branch does have some changes which cannot be backported. Most notable are breaking changes. The desire is to have stable users be uninterrupted when updating packages. +This section has been moved to [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). -However, many changes are able to be backported, including: -- New Packages / Modules -- Security / Patch updates -- Version updates which include new functionality (but no breaking changes) -- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) -- Security critical applications (E.g. `firefox`) diff --git a/pkgs/README.md b/pkgs/README.md index 4c736e658f09..8559d9bee027 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -474,6 +474,53 @@ If you do need to do create this sort of patch file, one way to do so is with gi $ git diff -a > nixpkgs/pkgs/the/package/0001-changes.patch ``` +## Deprecating/removing packages {#submitting-changes-deprecating-packages} + +There is currently no policy when to remove a package. + +Before removing a package, one should try to find a new maintainer or fix smaller issues first. + +### Steps to remove a package from Nixpkgs {#steps-to-remove-a-package-from-nixpkgs} + +We use jbidwatcher as an example for a discontinued project here. + +1. Have Nixpkgs checked out locally and up to date. +1. Create a new branch for your change, e.g. `git checkout -b jbidwatcher` +1. Remove the actual package including its directory, e.g. `git rm -rf pkgs/applications/misc/jbidwatcher` +1. Remove the package from the list of all packages (`pkgs/top-level/all-packages.nix`). +1. Add an alias for the package name in `pkgs/top-level/aliases.nix` (There is also `pkgs/applications/editors/vim/plugins/aliases.nix`. Package sets typically do not have aliases, so we can't add them there.) + + For example in this case: + + ``` + jbidwatcher = throw "jbidwatcher was discontinued in march 2021"; # added 2021-03-15 + ``` + + The throw message should explain in short why the package was removed for users that still have it installed. + +1. Test if the changes introduced any issues by running `nix-env -qaP -f . --show-trace`. It should show the list of packages without errors. +1. Commit the changes. Explain again why the package was removed. If it was declared discontinued upstream, add a link to the source. + + ```ShellSession + $ git add pkgs/applications/misc/jbidwatcher/default.nix pkgs/top-level/all-packages.nix pkgs/top-level/aliases.nix + $ git commit + ``` + + Example commit message: + + ``` + jbidwatcher: remove + + project was discontinued in march 2021. the program does not work anymore because ebay changed the login. + + https://web.archive.org/web/20210315205723/http://www.jbidwatcher.com/ + ``` + +1. Push changes to your GitHub fork with `git push` +1. Create a pull request against Nixpkgs. Mention the package maintainer. + +This is how the pull request looks like in this case: [https://github.com/NixOS/nixpkgs/pull/116470](https://github.com/NixOS/nixpkgs/pull/116470) + ## Testing changes | Package tests {#sec-package-tests} To run the main types of tests locally: @@ -696,3 +743,25 @@ Sample template for a new package review is provided below. ##### Comments ``` + +## (Security) + +### Submitting security fixes {#submitting-changes-submitting-security-fixes} + +Security fixes are submitted in the same way as other changes and thus the same guidelines apply. + +- If a new version fixing the vulnerability has been released, update the package; +- If the security fix comes in the form of a patch and a CVE is available, then add the patch to the Nixpkgs tree, and apply it to the package. + The name of the patch should be the CVE identifier, so e.g. `CVE-2019-13636.patch`; If a patch is fetched the name needs to be set as well, e.g.: + + ```nix + (fetchpatch { + name = "CVE-2019-11068.patch"; + url = "https://gitlab.gnome.org/GNOME/libxslt/commit/e03553605b45c88f0b4b2980adfbbb8f6fca2fd6.patch"; + hash = "sha256-SEKe/8HcW0UBHCfPTTOnpRlzmV2nQPPeL6HOMxBZd14="; + }) + ``` + +If a security fix applies to both master and a stable release then, similar to regular changes, they are preferably delivered via master first and cherry-picked to the release branch. + +Critical security fixes may by-pass the staging branches and be delivered directly to release branches such as `master` and `release-*`. From 129da60f578723edc9ca6405ca7f53b31afd1875 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 25 Jul 2023 18:34:15 +0200 Subject: [PATCH 10/42] doc/vulnerability-roundup: Rough move to new contribution doc files No content was changed, new titles are wrapped with () to signal that they will need to be decided on in a future commit. Section in the manual have been preserved with a simple redirect to GitHub, the proper anchors should be filled out in a future commit once the new section names are decided. --- .../vulnerability-roundup.chapter.md | 42 ++--------------- pkgs/README.md | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/doc/contributing/vulnerability-roundup.chapter.md b/doc/contributing/vulnerability-roundup.chapter.md index d451420f9815..0880fecea982 100644 --- a/doc/contributing/vulnerability-roundup.chapter.md +++ b/doc/contributing/vulnerability-roundup.chapter.md @@ -1,45 +1,11 @@ # Vulnerability Roundup {#chap-vulnerability-roundup} +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). + ## Issues {#vulnerability-roundup-issues} -Vulnerable packages in Nixpkgs are managed using issues. -Currently opened ones can be found using the following: - -[github.com/NixOS/nixpkgs/issues?q=is:issue+is:open+"Vulnerability+roundup"](https://github.com/NixOS/nixpkgs/issues?q=is%3Aissue+is%3Aopen+%22Vulnerability+roundup%22) - -Each issue correspond to a vulnerable version of a package; As a consequence: - -- One issue can contain several CVEs; -- One CVE can be shared across several issues; -- A single package can be concerned by several issues. - - -A "Vulnerability roundup" issue usually respects the following format: - -```txt -, - - - - - - -``` - -Note that there can be an extra comment containing links to previously reported (and still open) issues for the same package. - +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). ## Triaging and Fixing {#vulnerability-roundup-triaging-and-fixing} -**Note**: An issue can be a "false positive" (i.e. automatically opened, but without the package it refers to being actually vulnerable). -If you find such a "false positive", comment on the issue an explanation of why it falls into this category, linking as much information as the necessary to help maintainers double check. - -If you are investigating a "true positive": - -- Find the earliest patched version or a code patch in the CVE details; -- Is the issue already patched (version up-to-date or patch applied manually) in Nixpkgs's `master` branch? - - **No**: - - [Submit a security fix](#submitting-changes-submitting-security-fixes); - - Once the fix is merged into `master`, [submit the change to the vulnerable release branch(es)](https://nixos.org/manual/nixpkgs/stable/#submitting-changes-stable-release-branches); - - **Yes**: [Backport the change to the vulnerable release branch(es)](https://nixos.org/manual/nixpkgs/stable/#submitting-changes-stable-release-branches). -- When the patch has made it into all the relevant branches (`master`, and the vulnerable releases), close the relevant issue(s). +This section has been moved to [pkgs/README.md](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md). diff --git a/pkgs/README.md b/pkgs/README.md index 8559d9bee027..774b738f688b 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -765,3 +765,49 @@ Security fixes are submitted in the same way as other changes and thus the same If a security fix applies to both master and a stable release then, similar to regular changes, they are preferably delivered via master first and cherry-picked to the release branch. Critical security fixes may by-pass the staging branches and be delivered directly to release branches such as `master` and `release-*`. + +### Vulnerability Roundup {#chap-vulnerability-roundup} + +#### Issues {#vulnerability-roundup-issues} + +Vulnerable packages in Nixpkgs are managed using issues. +Currently opened ones can be found using the following: + +[github.com/NixOS/nixpkgs/issues?q=is:issue+is:open+"Vulnerability+roundup"](https://github.com/NixOS/nixpkgs/issues?q=is%3Aissue+is%3Aopen+%22Vulnerability+roundup%22) + +Each issue correspond to a vulnerable version of a package; As a consequence: + +- One issue can contain several CVEs; +- One CVE can be shared across several issues; +- A single package can be concerned by several issues. + + +A "Vulnerability roundup" issue usually respects the following format: + +```txt +, + + + + + + +``` + +Note that there can be an extra comment containing links to previously reported (and still open) issues for the same package. + + +#### Triaging and Fixing {#vulnerability-roundup-triaging-and-fixing} + +**Note**: An issue can be a "false positive" (i.e. automatically opened, but without the package it refers to being actually vulnerable). +If you find such a "false positive", comment on the issue an explanation of why it falls into this category, linking as much information as the necessary to help maintainers double check. + +If you are investigating a "true positive": + +- Find the earliest patched version or a code patch in the CVE details; +- Is the issue already patched (version up-to-date or patch applied manually) in Nixpkgs's `master` branch? + - **No**: + - [Submit a security fix](#submitting-changes-submitting-security-fixes); + - Once the fix is merged into `master`, [submit the change to the vulnerable release branch(es)](https://nixos.org/manual/nixpkgs/stable/#submitting-changes-stable-release-branches); + - **Yes**: [Backport the change to the vulnerable release branch(es)](https://nixos.org/manual/nixpkgs/stable/#submitting-changes-stable-release-branches). +- When the patch has made it into all the relevant branches (`master`, and the vulnerable releases), close the relevant issue(s). From 549ecbc977b1d165f1de702f6c6fed0cdc1f5b6c Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 2 Aug 2023 18:33:22 +0200 Subject: [PATCH 11/42] doc: Add empty development section --- doc/development.md | 6 ++++++ doc/manual.md.in | 1 + 2 files changed, 7 insertions(+) create mode 100644 doc/development.md diff --git a/doc/development.md b/doc/development.md new file mode 100644 index 000000000000..d1b479b6cd8a --- /dev/null +++ b/doc/development.md @@ -0,0 +1,6 @@ +# Development of Nixpkgs {#part-development} + +This section shows you how Nixpkgs is being developed and how you can interact with the contributors and the latest updates. +If you are interested in contributing yourself, see [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). + + diff --git a/doc/manual.md.in b/doc/manual.md.in index a4a73a913097..6b8d351380f9 100644 --- a/doc/manual.md.in +++ b/doc/manual.md.in @@ -10,5 +10,6 @@ using-nixpkgs.md lib.md stdenv.md builders.md +development.md contributing.md ``` From 37968083e7e85ea469066d9c4720b1a419b38eb6 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 2 Aug 2023 18:38:44 +0200 Subject: [PATCH 12/42] CONTRIBUTING.md: Move opening issues section to Nixpkgs manual This isn't relevant to contributors specifically, it applies to all users --- CONTRIBUTING.md | 6 ------ doc/development.md | 6 +++++- doc/development/opening-issues.chapter.md | 7 +++++++ 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 doc/development/opening-issues.chapter.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 95d23e3f7ed1..7a2ea329ded1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,11 +1,5 @@ # How to contribute -## Opening issues - -* Make sure you have a [GitHub account](https://github.com/signup/free) -* Make sure there is no open issue on the topic -* [Submit a new issue](https://github.com/NixOS/nixpkgs/issues/new/choose) by choosing the kind of topic and fill out the template - ## Submitting changes Read the ["Submitting changes"](https://nixos.org/nixpkgs/manual/#chap-submitting-changes) section of the nixpkgs manual. It explains how to write, test, and iterate on your change, and which branch to base your pull request against. diff --git a/doc/development.md b/doc/development.md index d1b479b6cd8a..0c092befca24 100644 --- a/doc/development.md +++ b/doc/development.md @@ -3,4 +3,8 @@ This section shows you how Nixpkgs is being developed and how you can interact with the contributors and the latest updates. If you are interested in contributing yourself, see [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). - + + +```{=include=} chapters +development/opening-issues.chapter.md +``` diff --git a/doc/development/opening-issues.chapter.md b/doc/development/opening-issues.chapter.md new file mode 100644 index 000000000000..2b82efae593a --- /dev/null +++ b/doc/development/opening-issues.chapter.md @@ -0,0 +1,7 @@ +# Opening issues {#sec-opening-issues} + +* Make sure you have a [GitHub account](https://github.com/signup/free) +* Make sure there is no open issue on the topic +* [Submit a new issue](https://github.com/NixOS/nixpkgs/issues/new/choose) by choosing the kind of topic and fill out the template + + From 1a2906024a029e3eea8dbc1327edcda5bbe10a6f Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 2 Aug 2023 18:40:24 +0200 Subject: [PATCH 13/42] CONTRIBUTING.md: Remove temporarily So that the CONTRIBUTING-new.md can take its place and Git detect the rename --- CONTRIBUTING.md | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 7a2ea329ded1..000000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,11 +0,0 @@ -# How to contribute - -## Submitting changes - -Read the ["Submitting changes"](https://nixos.org/nixpkgs/manual/#chap-submitting-changes) section of the nixpkgs manual. It explains how to write, test, and iterate on your change, and which branch to base your pull request against. - -Below is a short excerpt of some points in there: - -## Reviewing contributions - -See the nixpkgs manual for more details on how to [Review contributions](https://nixos.org/nixpkgs/manual/#chap-reviewing-contributions). From 350eb69c170cde0d8c0bf8afd117f8352cacec6d Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 2 Aug 2023 18:41:19 +0200 Subject: [PATCH 14/42] Move CONTRIBUTING-new.md to CONTRIBUTING.md The -new version was assembled in the previous commits --- CONTRIBUTING-new.md => CONTRIBUTING.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CONTRIBUTING-new.md => CONTRIBUTING.md (100%) diff --git a/CONTRIBUTING-new.md b/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING-new.md rename to CONTRIBUTING.md From 3d5fc07cfb6835d5928a1b3388dbbb5a2a61133e Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 2 Aug 2023 19:25:04 +0200 Subject: [PATCH 15/42] CONTRIBUTING.md: Add intro --- CONTRIBUTING.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 76f7cf5f4cc8..17f63d1868d6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,12 @@ # Contributing to Nixpkgs +This document is for people wanting to contribute to the implementation of Nixpkgs. +This involves interacting with implementation changes that are proposed using [GitHub](https://github.com/) [pull requests](https://docs.github.com/pull-requests) to the [Nixpkgs](https://github.com/nixos/nixpkgs/) repository (which you're in right now). + +As such, a GitHub account is required, which you can sign up for [here](https://github.com/signup). +Additionally this document assumes that you already know how to use GitHub and Git. +If that's not the case, we recommend learning about it first [here](https://docs.github.com/en/get-started/quickstart/hello-world). + ## (Proposing a change) | Submitting changes Note: contributing implies licensing those contributions From ecee8c3af416051cdde0d2dcdcaec644cda45b38 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 2 Aug 2023 20:30:42 +0200 Subject: [PATCH 16/42] CONTRIBUTING.md: Add overview --- CONTRIBUTING.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 17f63d1868d6..69b47595aba4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,6 +7,15 @@ As such, a GitHub account is required, which you can sign up for [here](https:// Additionally this document assumes that you already know how to use GitHub and Git. If that's not the case, we recommend learning about it first [here](https://docs.github.com/en/get-started/quickstart/hello-world). +## Overview + +This file contains general contributing information, but individual parts also have more specific information to them in their respective `README.md` files, linked here: +- [`lib`](./lib): Sources and documentation of the [library functions](https://nixos.org/manual/nixpkgs/stable/#chap-functions) +- [`maintainers`](./maintainers): Nixpkgs maintainer and team listings, maintainer scripts +- [`pkgs`](./pkgs): Package and [builder](https://nixos.org/manual/nixpkgs/stable/#part-builders) definitions +- [`doc`](./doc): Sources and infrastructure for the [Nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/) +- [`nixos`](./nixos): Implementation of [NixOS](https://nixos.org/manual/nixos/stable/) + ## (Proposing a change) | Submitting changes Note: contributing implies licensing those contributions From 44293fb0325a3df0aa33a736bef01a6d9d88803a Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 2 Aug 2023 20:30:47 +0200 Subject: [PATCH 17/42] pkgs/README.md: Add overview --- pkgs/README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pkgs/README.md b/pkgs/README.md index 774b738f688b..2f511a35c5d7 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -1,5 +1,26 @@ # Contributing to Nixpkgs packages +This document is for people wanting to contribute specifically to the package collection in Nixpkgs. +See the [CONTRIBUTING.md](../CONTRIBUTING.md) document for more general information. + +## Overview + +- [`top-level`](./top-level): Entrypoints, package set aggregations + - [`impure.nix`](./top-level/impure.nix), [`default.nix`](./top-level/default.nix), [`config.nix`](./top-level/config.nix): Definitions for the evaluation entry point of `import ` + - [`stage.nix`](./top-level/stage.nix), [`all-packages.nix`](./top-level/all-packages.nix), [`splice.nix`](./top-level/splice.nix): Definitions for the top-level attribute set made available through `import {…}` + - `*-packages.nix`, [`linux-kernels.nix`](./top-level/linux-kernels.nix), [`unixtools.nix`](./top-level/unixtools.nix): Aggregations of nested package sets defined in `development` + - [`aliases.nix`](./top-level/aliases.nix), [`python-aliases.nix`](./top-level/python-aliases.nix): Aliases for package definitions that have been renamed or removed + - `release*.nix`, [`make-tarball.nix`](./top-level/make-tarball.nix), [`packages-config.nix`](./top-level/packages-config.nix), [`metrics.nix`](./top-level/metrics.nix), [`nixpkgs-basic-release-checks.nix`](./top-level/nixpkgs-basic-release-checks.nix): Entry-points and utilities used by Hydra for continuous integration +- [`development`](./development) + - `*-modules`, `*-packages`, `*-pkgs`: Package definitions for nested package sets + - All other directories loosely categorise top-level package definitions, see [category hierarchy](#category-hierarchy) +- [`build-support`](./build-support): [Builders](https://nixos.org/manual/nixpkgs/stable/#part-builders) + - `fetch*`: [Fetchers](https://nixos.org/manual/nixpkgs/stable/#chap-pkgs-fetchers) +- [`stdenv`](./stdenv): [Standard environment](https://nixos.org/manual/nixpkgs/stable/#part-stdenv) +- [`pkgs-lib`](./pkgs-lib): Definitions for utilities that need packages but are not needed for packages +- [`test`](./test): Tests not directly associated with any specific packages +- All other directories loosely categorise top-level packages definitions, see [category hierarchy](#category-hierarchy) + ## Quick Start to Adding a Package {#chap-quick-start} To add a package to Nixpkgs: @@ -78,7 +99,7 @@ To add a package to Nixpkgs: 7. Optionally commit the new package and open a pull request [to nixpkgs](https://github.com/NixOS/nixpkgs/pulls), or use [the Patches category](https://discourse.nixos.org/t/about-the-patches-category/477) on Discourse for sending a patch without a GitHub account. -## Hierarchy {#sec-hierarchy} +## Category Hierarchy Each package should be stored in its own directory somewhere in the `pkgs/` tree, i.e. in `pkgs/category/subcategory/.../pkgname`. Below are some rules for picking the right category for a package. Many packages fall under several categories; what matters is the _primary_ purpose of a package. For example, the `libxml2` package builds both a library and some tools; but it’s a library foremost, so it goes under `pkgs/development/libraries`. From 9489e19e218dac7a3df1523214e8f54e13949044 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 3 Aug 2023 00:06:30 +0200 Subject: [PATCH 18/42] CONTRIBUTING.md: Move pull request template section to the bottom --- CONTRIBUTING.md | 139 ++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69b47595aba4..c8e3eb7c5c87 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -121,76 +121,6 @@ When pull requests are made, our tooling automation bot, [OfBorg](https://github.com/NixOS/ofborg) will perform various checks to help ensure expression quality. -#### Pull Request Template {#submitting-changes-pull-request-template} - -The pull request template helps determine what steps have been made for a contribution so far, and will help guide maintainers on the status of a change. The motivation section of the PR should include any extra details the title does not address and link any existing issues related to the pull request. - -When a PR is created, it will be pre-populated with some checkboxes detailed below: - -##### Tested using sandboxing {#submitting-changes-tested-with-sandbox} - -When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of `fetch*` functions and files outside the Nix store. Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [sandbox](https://nixos.org/nix/manual/#conf-sandbox) in Nix manual for details. - -Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for [nixpkgs](https://github.com/NixOS/nixpkgs/) people are asked to test builds with sandboxing enabled (see `Tested using sandboxing` in the pull request template) because in sandboxing is also used. - -Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing **before** building the package: - -- **Globally enable sandboxing on NixOS**: add the following to `configuration.nix` - - ```nix - nix.useSandbox = true; - ``` - -- **Globally enable sandboxing on non-NixOS platforms**: add the following to: `/etc/nix/nix.conf` - - ```ini - sandbox = true - ``` - -##### Built on platform(s) {#submitting-changes-platform-diversity} - -Many Nix packages are designed to run on multiple platforms. As such, it’s important to let the maintainer know which platforms your changes have been tested on. It’s not always practical to test a change on all platforms, and is not required for a pull request to be merged. Only check the systems you tested the build on in this section. - -##### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) {#submitting-changes-nixos-tests} - -Packages with automated tests are much more likely to be merged in a timely fashion because it doesn’t require as much manual testing by the maintainer to verify the functionality of the package. If there are existing tests for the package, they should be run to verify your changes do not break the tests. Tests can only be run on Linux. For more details on writing and running tests, see the [section in the NixOS manual](https://nixos.org/nixos/manual/index.html#sec-nixos-tests). - -##### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` {#submitting-changes-tested-compilation} - -If you are updating a package’s version, you can use `nixpkgs-review` to make sure all packages that depend on the updated package still compile correctly. The `nixpkgs-review` utility can look for and build all dependencies either based on uncommitted changes with the `wip` option or specifying a GitHub pull request number. - -Review changes from pull request number 12345: - -```ShellSession -nix-shell -p nixpkgs-review --run "nixpkgs-review pr 12345" -``` - -Alternatively, with flakes (and analogously for the other commands below): - -```ShellSession -nix run nixpkgs#nixpkgs-review -- pr 12345 -``` - -Review uncommitted changes: - -```ShellSession -nix-shell -p nixpkgs-review --run "nixpkgs-review wip" -``` - -Review changes from last commit: - -```ShellSession -nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD" -``` - -##### Tested execution of all binary files (usually in `./result/bin/`) {#submitting-changes-tested-execution} - -It’s important to test any executables generated by a build when you change or create a package in nixpkgs. This can be done by looking in `./result/bin` and running any files in there, or at a minimum, the main executable for the package. For example, if you make a change to texlive, you probably would only check the binaries associated with the change you made rather than testing all of them. - -##### Meets Nixpkgs contribution standards {#submitting-changes-contribution-standards} - -The last checkbox is fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). The contributing document has detailed information on standards the Nix community has for commit messages, reviews, licensing of contributions you make to the project, etc... Everyone should read and understand the standards the community has for contributing before submitting a pull request. - #### Rebasing between branches (i.e. from master to staging) From time to time, changes between branches must be rebased, for example, if the @@ -696,3 +626,72 @@ Names of files and directories should be in lowercase, with dashes between words - Arguments should be listed in the order they are used, with the exception of `lib`, which always goes first. +## Pull Request Template {#submitting-changes-pull-request-template} + +The pull request template helps determine what steps have been made for a contribution so far, and will help guide maintainers on the status of a change. The motivation section of the PR should include any extra details the title does not address and link any existing issues related to the pull request. + +When a PR is created, it will be pre-populated with some checkboxes detailed below: + +### Tested using sandboxing {#submitting-changes-tested-with-sandbox} + +When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of `fetch*` functions and files outside the Nix store. Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [sandbox](https://nixos.org/nix/manual/#conf-sandbox) in Nix manual for details. + +Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for [nixpkgs](https://github.com/NixOS/nixpkgs/) people are asked to test builds with sandboxing enabled (see `Tested using sandboxing` in the pull request template) because in sandboxing is also used. + +Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing **before** building the package: + +- **Globally enable sandboxing on NixOS**: add the following to `configuration.nix` + + ```nix + nix.useSandbox = true; + ``` + +- **Globally enable sandboxing on non-NixOS platforms**: add the following to: `/etc/nix/nix.conf` + + ```ini + sandbox = true + ``` + +### Built on platform(s) {#submitting-changes-platform-diversity} + +Many Nix packages are designed to run on multiple platforms. As such, it’s important to let the maintainer know which platforms your changes have been tested on. It’s not always practical to test a change on all platforms, and is not required for a pull request to be merged. Only check the systems you tested the build on in this section. + +### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) {#submitting-changes-nixos-tests} + +Packages with automated tests are much more likely to be merged in a timely fashion because it doesn’t require as much manual testing by the maintainer to verify the functionality of the package. If there are existing tests for the package, they should be run to verify your changes do not break the tests. Tests can only be run on Linux. For more details on writing and running tests, see the [section in the NixOS manual](https://nixos.org/nixos/manual/index.html#sec-nixos-tests). + +### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` {#submitting-changes-tested-compilation} + +If you are updating a package’s version, you can use `nixpkgs-review` to make sure all packages that depend on the updated package still compile correctly. The `nixpkgs-review` utility can look for and build all dependencies either based on uncommitted changes with the `wip` option or specifying a GitHub pull request number. + +Review changes from pull request number 12345: + +```ShellSession +nix-shell -p nixpkgs-review --run "nixpkgs-review pr 12345" +``` + +Alternatively, with flakes (and analogously for the other commands below): + +```ShellSession +nix run nixpkgs#nixpkgs-review -- pr 12345 +``` + +Review uncommitted changes: + +```ShellSession +nix-shell -p nixpkgs-review --run "nixpkgs-review wip" +``` + +Review changes from last commit: + +```ShellSession +nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD" +``` + +### Tested execution of all binary files (usually in `./result/bin/`) {#submitting-changes-tested-execution} + +It’s important to test any executables generated by a build when you change or create a package in nixpkgs. This can be done by looking in `./result/bin` and running any files in there, or at a minimum, the main executable for the package. For example, if you make a change to texlive, you probably would only check the binaries associated with the change you made rather than testing all of them. + +### Meets Nixpkgs contribution standards {#submitting-changes-contribution-standards} + +The last checkbox is fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). The contributing document has detailed information on standards the Nix community has for commit messages, reviews, licensing of contributions you make to the project, etc... Everyone should read and understand the standards the community has for contributing before submitting a pull request. From dfe311b1b8253f4bcf21333725105298c366eb1a Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 3 Aug 2023 00:11:35 +0200 Subject: [PATCH 19/42] CONTRIBUTING.md: Collect paragraphs into a new commit conventions section --- CONTRIBUTING.md | 90 ++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c8e3eb7c5c87..b5d5a158b4b6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,28 +21,6 @@ This file contains general contributing information, but individual parts also h Note: contributing implies licensing those contributions under the terms of [COPYING](COPYING), which is an MIT-like license. -* Format the commit messages in the following way: - - ``` - (pkg-name | nixos/): (from -> to | init at version | refactor | etc) - - (Motivation for change. Link to release notes. Additional information.) - ``` - - For consistency, there should not be a period at the end of the commit message's summary line (the first line of the commit message). - - Examples: - - * nginx: init at 2.0.1 - * firefox: 54.0.1 -> 55.0 - https://www.mozilla.org/en-US/firefox/55.0/releasenotes/ - * nixos/hydra: add bazBaz option - - Dual baz behavior is needed to do foo. - * nixos/nginx: refactor config generation - - The old config generation system used impure shell scripts and could break in specific circumstances (see #1234). - ### Making patches {#submitting-changes-making-patches} - Read [Manual (How to write packages for Nix)](https://nixos.org/nixpkgs/manual/). @@ -62,25 +40,8 @@ under the terms of [COPYING](COPYING), which is an MIT-like license. - Please avoid working directly on the `master` branch. -- Make commits of logical units. - - If you removed pkgs or made some major NixOS changes, write about it in the release notes for the next stable release. For example `nixos/doc/manual/release-notes/rl-2003.xml`. -- Check for unnecessary whitespace with `git diff --check` before committing. - -- Format the commit in a following way: - - ``` - (pkg-name | nixos/): (from -> to | init at version | refactor | etc) - Additional information. - ``` - - - Examples: - - `nginx: init at 2.0.1` - - `firefox: 54.0.1 -> 55.0` - - `nixos/hydra: add bazBaz option` - - `nixos/nginx: refactor config generation` - - Test your changes. If you work with - nixpkgs: @@ -97,19 +58,9 @@ under the terms of [COPYING](COPYING), which is an MIT-like license. - NixOS and its modules: - You can add new module to your NixOS configuration file (usually it’s `/etc/nixos/configuration.nix`). And do `sudo nixos-rebuild test -I nixpkgs= --fast`. -- If you have commits `pkg-name: oh, forgot to insert whitespace`: squash commits in this case. Use `git rebase -i`. - [Rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) your branch against current `master`. -### Writing good commit messages - -In addition to writing properly formatted commit messages, it's important to include relevant information so other developers can later understand *why* a change was made. While this information usually can be found by digging code, mailing list/Discourse archives, pull request discussions or upstream changes, it may require a lot of work. - -Package version upgrades usually allow for simpler commit messages, including attribute name, old and new version, as well as a reference to the relevant release notes/changelog. Every once in a while a package upgrade requires more extensive changes, and that subsequently warrants a more verbose message. - -Pull requests should not be squash merged in order to keep complete commit messages and GPG signatures intact and must not be when the change doesn't make sense as a single commit. -This means that, when addressing review comments in order to keep the pull request in an always mergeable status, you will sometimes need to rewrite your branch's history and then force-push it with `git push --force-with-lease`. -Useful git commands that can help a lot with this are `git commit --patch --amend` and `git rebase --interactive`. For more details consult the git man pages or online resources like [git-rebase.io](https://git-rebase.io/) or [The Pro Git Book](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). ### (Creating a pull request) @@ -626,6 +577,47 @@ Names of files and directories should be in lowercase, with dashes between words - Arguments should be listed in the order they are used, with the exception of `lib`, which always goes first. +## Commit conventions + +- Create a commit for each logical unit. + +- Check for unnecessary whitespace with `git diff --check` before committing. + +- If you have commits `pkg-name: oh, forgot to insert whitespace`: squash commits in this case. Use `git rebase -i`. + +- Format the commit messages in the following way: + + ``` + (pkg-name | nixos/): (from -> to | init at version | refactor | etc) + + (Motivation for change. Link to release notes. Additional information.) + ``` + + For consistency, there should not be a period at the end of the commit message's summary line (the first line of the commit message). + + Examples: + + * nginx: init at 2.0.1 + * firefox: 54.0.1 -> 55.0 + + https://www.mozilla.org/en-US/firefox/55.0/releasenotes/ + * nixos/hydra: add bazBaz option + + Dual baz behavior is needed to do foo. + * nixos/nginx: refactor config generation + + The old config generation system used impure shell scripts and could break in specific circumstances (see #1234). + +### Writing good commit messages + +In addition to writing properly formatted commit messages, it's important to include relevant information so other developers can later understand *why* a change was made. While this information usually can be found by digging code, mailing list/Discourse archives, pull request discussions or upstream changes, it may require a lot of work. + +Package version upgrades usually allow for simpler commit messages, including attribute name, old and new version, as well as a reference to the relevant release notes/changelog. Every once in a while a package upgrade requires more extensive changes, and that subsequently warrants a more verbose message. + +Pull requests should not be squash merged in order to keep complete commit messages and GPG signatures intact and must not be when the change doesn't make sense as a single commit. +This means that, when addressing review comments in order to keep the pull request in an always mergeable status, you will sometimes need to rewrite your branch's history and then force-push it with `git push --force-with-lease`. +Useful git commands that can help a lot with this are `git commit --patch --amend` and `git rebase --interactive`. For more details consult the git man pages or online resources like [git-rebase.io](https://git-rebase.io/) or [The Pro Git Book](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). + ## Pull Request Template {#submitting-changes-pull-request-template} The pull request template helps determine what steps have been made for a contribution so far, and will help guide maintainers on the status of a change. The motivation section of the PR should include any extra details the title does not address and link any existing issues related to the pull request. From 99c6942d83b73fbb741f4806da83b2fb03e9daee Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 3 Aug 2023 00:13:58 +0200 Subject: [PATCH 20/42] CONTRIBUTING.md: Coding conventions -> code conventions It's not conventions about how to do coding, it's about what the code should look like --- CONTRIBUTING.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b5d5a158b4b6..314e174cf5d2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -373,7 +373,8 @@ However, many changes are able to be backported, including: - Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) - Security critical applications (E.g. `firefox`) -## Coding conventions {#chap-conventions} + +## Code conventions ### File naming and organisation {#sec-organisation} From 67ae88c0724a03b770baa013f27afcc960c9f002 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 3 Aug 2023 00:12:58 +0200 Subject: [PATCH 21/42] CONTRIBUTING.md: Write a new section on how to propose a change Removing paragraphs from the other sections that aren't necessary anymore --- CONTRIBUTING.md | 89 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 314e174cf5d2..0b0efb640e35 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,30 +16,75 @@ This file contains general contributing information, but individual parts also h - [`doc`](./doc): Sources and infrastructure for the [Nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/) - [`nixos`](./nixos): Implementation of [NixOS](https://nixos.org/manual/nixos/stable/) -## (Proposing a change) | Submitting changes +## How to propose a change -Note: contributing implies licensing those contributions -under the terms of [COPYING](COPYING), which is an MIT-like license. +This section describes in some detail how changes can be made and proposed with pull requests. + +> **Note** +> Be aware that contributing implies licensing those contributions under the terms of [COPYING](./COPYING), an MIT-like license. + +0. Set up a local version of Nixpkgs to work with using GitHub and Git + 1. [Fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository) the [Nixpkgs repository](https://github.com/nixos/nixpkgs/). + 1. [Clone the forked repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#cloning-your-forked-repository) into a local `nixpkgs` directory. + 1. [Configure the upstream Nixpkgs repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#configuring-git-to-sync-your-fork-with-the-upstream-repository). + +1. Create and switch to a new Git branch, ideally such that: + - The name of the branch hints at the change you'd like to implement, e.g. `update-hello`. + - The base of the branch includes the most recent changes on the `master` branch. + > **Note** + > Depending on the change you may want to use a different branch, see + + ```bash + # Make sure you have the latest changes from upstream Nixpkgs + git fetch upstream + + # Create and switch to a new branch based off the master branch in Nixpkgs + git switch --create update-hello upstream/master + ``` + + To avoid having to download and build potentially many derivations, at the expense of using a potentially outdated version, you can base the branch off a specific [Git commit](https://www.git-scm.com/docs/gitglossary#def_commit) instead: + - The commit of the latest `nixpkgs-unstable` channel, available [here](https://channels.nixos.org/nixpkgs-unstable/git-revision). + - The commit of a local Nixpkgs downloaded using [nix-channel](https://nixos.org/manual/nix/stable/command-ref/nix-channel), available using `nix-instantiate --eval --expr '(import ).trivial.revisionWithDefault null'` + - If you're using NixOS, the commit of your NixOS installation, available with `nixos-version --revision`. + + Once you have an appropriate commit you can use it instead of `upstream/master` in the above command: + ```bash + git switch --create update-hello + ``` + +2. Make the desired changes in the local Nixpkgs repository using an editor of your choice. + Make sure to: + - Adhere to both the [general code conventions](#code-conventions), and the code conventions specific to the part you're making changes to. + See the [overview section](#overview) for more specific information. + - Test the changes. + See the [overview section](#overview) for more specific information. + - If necessary, document the change. + See the [overview section](#overview) for more specific information. + +3. Commit your changes using `git commit`. + Make sure to adhere to the [commit conventions](#commit-conventions). + + Repeat the steps 2 and 3 as many times as necessary. + Advance to the next step if all the commits (viewable with `git log`) make sense together. + +4. Push your commits to your fork of Nixpkgs. + ``` + git push --set-upstream origin HEAD + ``` + + The above command will output a link that allows you to directly quickly do the next step: + ``` + remote: Create a pull request for 'update-hello' on GitHub by visiting: + remote: https://github.com/myUser/nixpkgs/pull/new/update-hello + ``` + +5. [Create a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request#creating-the-pull-request) from the new branch in your Nixpkgs fork to the upstream Nixpkgs repository. + Generally you should use `master` as the pull requests base branch. + See for when a different branch should be used instead. + Make sure to go through the [pull request template](#pull-request-template) in the pre-filled default description. ### Making patches {#submitting-changes-making-patches} -- Read [Manual (How to write packages for Nix)](https://nixos.org/nixpkgs/manual/). - -- Fork [the Nixpkgs repository](https://github.com/nixos/nixpkgs/) on GitHub. - -- Create a branch for your future fix. - - - You can make branch from a commit of your local `nixos-version`. That will help you to avoid additional local compilations. Because you will receive packages from binary cache. For example - - ```ShellSession - $ nixos-version --hash - 0998212 - $ git checkout 0998212 - $ git checkout -b 'fix/pkg-name-update' - ``` - - - Please avoid working directly on the `master` branch. - - If you removed pkgs or made some major NixOS changes, write about it in the release notes for the next stable release. For example `nixos/doc/manual/release-notes/rl-2003.xml`. - Test your changes. If you work with @@ -64,10 +109,6 @@ under the terms of [COPYING](COPYING), which is an MIT-like license. ### (Creating a pull request) -- Push your changes to your fork of nixpkgs. -- Create the pull request -- Follow [the contribution guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#submitting-changes). - When pull requests are made, our tooling automation bot, [OfBorg](https://github.com/NixOS/ofborg) will perform various checks to help ensure expression quality. From 5789cc3754a8b97900d09bca0e3ef29c5879e13b Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 4 Aug 2023 20:02:54 +0200 Subject: [PATCH 22/42] CONTRIBUTING.md: Clean up "Making patches" section Moving and collecting bits into the appropriate places, also writing some new sentences --- CONTRIBUTING.md | 51 ++++++++++++++++++++++--------------------------- nixos/README.md | 4 ++++ pkgs/README.md | 9 +++++++++ 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b0efb640e35..76be3515f306 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -83,35 +83,28 @@ This section describes in some detail how changes can be made and proposed with See for when a different branch should be used instead. Make sure to go through the [pull request template](#pull-request-template) in the pre-filled default description. -### Making patches {#submitting-changes-making-patches} +6. Respond to review comments, potential CI failures and potential merge conflicts by updating the pull request. + Always keep the pull request in a mergeable state. -- If you removed pkgs or made some major NixOS changes, write about it in the release notes for the next stable release. For example `nixos/doc/manual/release-notes/rl-2003.xml`. + To add new commits, repeat steps 2-3 and push the result using + ``` + git push + ``` -- Test your changes. If you work with + To change existing commits you will have to [rewrite Git history](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). + Useful Git commands that can help a lot with this are `git commit --patch --amend` and `git rebase --interactive`. + With a rewritten history you need to force-push the commits using + ``` + git push --force-with-lease + ``` - - nixpkgs: - - - update pkg - - `nix-env -iA pkg-attribute-name -f ` - - add pkg - - Make sure it’s in `pkgs/top-level/all-packages.nix` - - `nix-env -iA pkg-attribute-name -f ` - - _If you don’t want to install pkg in you profile_. - - `nix-build -A pkg-attribute-name ` and check results in the folder `result`. It will appear in the same directory where you did `nix-build`. - - If you installed your package with `nix-env`, you can run `nix-env -e pkg-name` where `pkg-name` is as reported by `nix-env -q` to uninstall it from your system. - - - NixOS and its modules: - - You can add new module to your NixOS configuration file (usually it’s `/etc/nixos/configuration.nix`). And do `sudo nixos-rebuild test -I nixpkgs= --fast`. - - -- [Rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) your branch against current `master`. - - -### (Creating a pull request) - -When pull requests are made, our tooling automation bot, -[OfBorg](https://github.com/NixOS/ofborg) will perform various checks -to help ensure expression quality. + In case of merge conflicts you will also have to [rebasing the branch](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) on top of current `master`. + Sometimes this can be done [on GitHub directly](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/keeping-your-pull-request-in-sync-with-the-base-branch#updating-your-pull-request-branch), but if not you will have to rebase locally using + ``` + git fetch upstream + git rebase upstream/master + git push --force-with-lease + ``` #### Rebasing between branches (i.e. from master to staging) @@ -417,6 +410,10 @@ However, many changes are able to be backported, including: ## Code conventions +### Release notes + +If you removed pkgs or made some major NixOS changes, write about it in the release notes for the next stable release. For example `nixos/doc/manual/release-notes/rl-2003.xml`. + ### File naming and organisation {#sec-organisation} Names of files and directories should be in lowercase, with dashes between words — not in camel case. For instance, it should be `all-packages.nix`, not `allPackages.nix` or `AllPackages.nix`. @@ -657,8 +654,6 @@ In addition to writing properly formatted commit messages, it's important to inc Package version upgrades usually allow for simpler commit messages, including attribute name, old and new version, as well as a reference to the relevant release notes/changelog. Every once in a while a package upgrade requires more extensive changes, and that subsequently warrants a more verbose message. Pull requests should not be squash merged in order to keep complete commit messages and GPG signatures intact and must not be when the change doesn't make sense as a single commit. -This means that, when addressing review comments in order to keep the pull request in an always mergeable status, you will sometimes need to rewrite your branch's history and then force-push it with `git push --force-with-lease`. -Useful git commands that can help a lot with this are `git commit --patch --amend` and `git rebase --interactive`. For more details consult the git man pages or online resources like [git-rebase.io](https://git-rebase.io/) or [The Pro Git Book](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). ## Pull Request Template {#submitting-changes-pull-request-template} diff --git a/nixos/README.md b/nixos/README.md index 913f1eb48fbc..6e966e7a65d0 100644 --- a/nixos/README.md +++ b/nixos/README.md @@ -4,6 +4,10 @@ NixOS is a Linux distribution based on the purely functional package management system Nix. More information can be found at https://nixos.org/nixos and in the manual in doc/manual. +## Testing changes + +You can add new module to your NixOS configuration file (usually it’s `/etc/nixos/configuration.nix`). And do `sudo nixos-rebuild test -I nixpkgs= --fast`. + ## (Reviewing contributions) ### Module updates {#reviewing-contributions-module-updates} diff --git a/pkgs/README.md b/pkgs/README.md index 2f511a35c5d7..055c8e76a5c4 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -544,6 +544,15 @@ This is how the pull request looks like in this case: [https://github.com/NixOS/ ## Testing changes | Package tests {#sec-package-tests} +- update pkg + - `nix-env -iA pkg-attribute-name -f ` +- add pkg + - Make sure it’s in `pkgs/top-level/all-packages.nix` + - `nix-env -iA pkg-attribute-name -f ` +- _If you don’t want to install pkg in you profile_. + - `nix-build -A pkg-attribute-name ` and check results in the folder `result`. It will appear in the same directory where you did `nix-build`. +- If you installed your package with `nix-env`, you can run `nix-env -e pkg-name` where `pkg-name` is as reported by `nix-env -q` to uninstall it from your system. + To run the main types of tests locally: - Run package-internal tests with `nix-build --attr pkgs.PACKAGE.passthru.tests` From aace54f1aa213eac52bbdf954c348ed400413489 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 4 Aug 2023 20:10:08 +0200 Subject: [PATCH 23/42] CONTRIBUTING.md: Move flow of changes section up --- CONTRIBUTING.md | 290 ++++++++++++++++++++++++------------------------ 1 file changed, 145 insertions(+), 145 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 76be3515f306..be8a4b1729c9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,6 +106,151 @@ This section describes in some detail how changes can be made and proposed with git push --force-with-lease ``` +## (Flow of changes) | Commit policy {#submitting-changes-commit-policy} + +Most contributions are based on and merged into these branches: + +* `master` is the main branch where all small contributions go +* `staging` is branched from master, changes that have a big impact on + Hydra builds go to this branch +* `staging-next` is branched from staging and only fixes to stabilize + and security fixes with a big impact on Hydra builds should be + contributed to this branch. This branch is merged into master when + deemed of sufficiently high quality + +- Commits must be sufficiently tested before being merged, both for the master and staging branches. +- Hydra builds for master and staging should not be used as testing platform, it’s a build farm for changes that have been already tested. +- When changing the bootloader installation process, extra care must be taken. Grub installations cannot be rolled back, hence changes may break people’s installations forever. For any non-trivial change to the bootloader please file a PR asking for review, especially from \@edolstra. + +### Branches {#submitting-changes-branches} + +The `nixpkgs` repository has three major branches: +- `master` +- `staging` +- `staging-next` + +The most important distinction between them is that `staging` +(colored red in the diagram below) can receive commits which cause +a mass-rebuild (for example, anything that changes the `drvPath` of +`stdenv`). The other two branches `staging-next` and `master` +(colored green in the diagram below) can *not* receive commits which +cause a mass-rebuild. + +Arcs between the branches show possible merges into these branches, +either from other branches or from independently submitted PRs. The +colors of these edges likewise show whether or not they could +trigger a mass rebuild (red) or must not trigger a mass rebuild +(green). + +Hydra runs automatic builds for the green branches. + +Notice that the automatic merges are all green arrows. This is by +design. Any merge which might cause a mass rebuild on a branch +which has automatic builds (`staging-next`, `master`) will be a +manual merge to make sure it is good use of compute power. + +Nixpkgs has two branches so that there is one branch (`staging`) +which accepts mass-rebuilding commits, and one fast-rebuilding +branch which accepts independent PRs (`master`). The `staging-next` +branch allows the Hydra operators to batch groups of commits to +`staging` to be built. By keeping the `staging-next` branch +separate from `staging`, this batching does not block +developers from merging changes into `staging`. + +```{.graphviz caption="Staging workflow"} +digraph { + master [color="green" fontcolor=green] + "staging-next" [color="green" fontcolor=green] + staging [color="red" fontcolor=red] + + "small changes" [fontcolor=green shape=none] + "small changes" -> master [color=green] + + "mass-rebuilds and other large changes" [fontcolor=red shape=none] + "mass-rebuilds and other large changes" -> staging [color=red] + + "critical security fixes" [fontcolor=green shape=none] + "critical security fixes" -> master [color=green] + + "staging fixes which do not cause staging to mass-rebuild" [fontcolor=green shape=none] + "staging fixes which do not cause staging to mass-rebuild" -> "staging-next" [color=green] + + "staging-next" -> master [color="red"] [label="manual merge"] [fontcolor="red"] + "staging" -> "staging-next" [color="red"] [label="manual merge"] [fontcolor="red"] + + master -> "staging-next" [color="green"] [label="automatic merge (GitHub Action)"] [fontcolor="green"] + "staging-next" -> staging [color="green"] [label="automatic merge (GitHub Action)"] [fontcolor="green"] +} +``` + +[This GitHub Action](https://github.com/NixOS/nixpkgs/blob/master/.github/workflows/periodic-merge-6h.yml) brings changes from `master` to `staging-next` and from `staging-next` to `staging` every 6 hours; these are the green arrows in the diagram above. The red arrows in the diagram above are done manually and much less frequently. You can get an idea of how often these merges occur by looking at the git history. + + +#### Master branch {#submitting-changes-master-branch} + +The `master` branch is the main development branch. It should only see non-breaking commits that do not cause mass rebuilds. + +#### Staging branch {#submitting-changes-staging-branch} + +The `staging` branch is a development branch where mass-rebuilds go. Mass rebuilds are commits that cause rebuilds for many packages, like more than 500 (or perhaps, if it's 'light' packages, 1000). It should only see non-breaking mass-rebuild commits. That means it is not to be used for testing, and changes must have been well tested already. If the branch is already in a broken state, please refrain from adding extra new breakages. + +During the process of a releasing a new NixOS version, this branch or the release-critical packages can be restricted to non-breaking changes. + +#### Staging-next branch {#submitting-changes-staging-next-branch} + +The `staging-next` branch is for stabilizing mass-rebuilds submitted to the `staging` branch prior to merging them into `master`. Mass-rebuilds must go via the `staging` branch. It must only see non-breaking commits that are fixing issues blocking it from being merged into the `master` branch. + +If the branch is already in a broken state, please refrain from adding extra new breakages. Stabilize it for a few days and then merge into master. + +During the process of a releasing a new NixOS version, this branch or the release-critical packages can be restricted to non-breaking changes. + +#### Stable release branches {#submitting-changes-stable-release-branches} + +The same staging workflow applies to stable release branches, but the main branch is called `release-*` instead of `master`. + +Example branch names: `release-21.11`, `staging-21.11`, `staging-next-21.11`. + +Most changes added to the stable release branches are cherry-picked (“backported”) from the `master` and staging branches. + +#### Automatically backporting a Pull Request {#submitting-changes-stable-release-branches-automatic-backports} + +Assign label `backport ` (e.g. `backport release-21.11`) to the PR and a backport PR is automatically created after the PR is merged. + +#### Manually backporting changes {#submitting-changes-stable-release-branches-manual-backports} + +Cherry-pick changes via `git cherry-pick -x ` so that the original commit id is included in the commit message. + +Add a reason for the backport when it is not obvious from the original commit message. You can do this by cherry picking with `git cherry-pick -xe `, which allows editing the commit message. This is not needed for minor version updates that include security and bug fixes but don't add new features or when the commit fixes an otherwise broken package. + +Here is an example of a cherry-picked commit message with good reason description: + +``` +zfs: Keep trying root import until it works + +Works around #11003. + +(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9) + +Reason: several people cannot boot with ZFS on NVMe +``` + +Other examples of reasons are: + +- Previously the build would fail due to, e.g., `getaddrinfo` not being defined +- The previous download links were all broken +- Crash when starting on some X11 systems + +#### Acceptable backport criteria {#acceptable-backport-criteria} + +The stable branch does have some changes which cannot be backported. Most notable are breaking changes. The desire is to have stable users be uninterrupted when updating packages. + +However, many changes are able to be backported, including: +- New Packages / Modules +- Security / Patch updates +- Version updates which include new functionality (but no breaking changes) +- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) +- Security critical applications (E.g. `firefox`) + #### Rebasing between branches (i.e. from master to staging) From time to time, changes between branches must be rebased, for example, if the @@ -262,151 +407,6 @@ Please see the discussion in [GitHub nixpkgs issue #50105](https://github.com/Ni In a case a contributor definitively leaves the Nix community, they should create an issue or post on [Discourse](https://discourse.nixos.org) with references of packages and modules they maintain so the maintainership can be taken over by other contributors. -## (Flow of changes) | Commit policy {#submitting-changes-commit-policy} - -Most contributions are based on and merged into these branches: - -* `master` is the main branch where all small contributions go -* `staging` is branched from master, changes that have a big impact on - Hydra builds go to this branch -* `staging-next` is branched from staging and only fixes to stabilize - and security fixes with a big impact on Hydra builds should be - contributed to this branch. This branch is merged into master when - deemed of sufficiently high quality - -- Commits must be sufficiently tested before being merged, both for the master and staging branches. -- Hydra builds for master and staging should not be used as testing platform, it’s a build farm for changes that have been already tested. -- When changing the bootloader installation process, extra care must be taken. Grub installations cannot be rolled back, hence changes may break people’s installations forever. For any non-trivial change to the bootloader please file a PR asking for review, especially from \@edolstra. - -### Branches {#submitting-changes-branches} - -The `nixpkgs` repository has three major branches: -- `master` -- `staging` -- `staging-next` - -The most important distinction between them is that `staging` -(colored red in the diagram below) can receive commits which cause -a mass-rebuild (for example, anything that changes the `drvPath` of -`stdenv`). The other two branches `staging-next` and `master` -(colored green in the diagram below) can *not* receive commits which -cause a mass-rebuild. - -Arcs between the branches show possible merges into these branches, -either from other branches or from independently submitted PRs. The -colors of these edges likewise show whether or not they could -trigger a mass rebuild (red) or must not trigger a mass rebuild -(green). - -Hydra runs automatic builds for the green branches. - -Notice that the automatic merges are all green arrows. This is by -design. Any merge which might cause a mass rebuild on a branch -which has automatic builds (`staging-next`, `master`) will be a -manual merge to make sure it is good use of compute power. - -Nixpkgs has two branches so that there is one branch (`staging`) -which accepts mass-rebuilding commits, and one fast-rebuilding -branch which accepts independent PRs (`master`). The `staging-next` -branch allows the Hydra operators to batch groups of commits to -`staging` to be built. By keeping the `staging-next` branch -separate from `staging`, this batching does not block -developers from merging changes into `staging`. - -```{.graphviz caption="Staging workflow"} -digraph { - master [color="green" fontcolor=green] - "staging-next" [color="green" fontcolor=green] - staging [color="red" fontcolor=red] - - "small changes" [fontcolor=green shape=none] - "small changes" -> master [color=green] - - "mass-rebuilds and other large changes" [fontcolor=red shape=none] - "mass-rebuilds and other large changes" -> staging [color=red] - - "critical security fixes" [fontcolor=green shape=none] - "critical security fixes" -> master [color=green] - - "staging fixes which do not cause staging to mass-rebuild" [fontcolor=green shape=none] - "staging fixes which do not cause staging to mass-rebuild" -> "staging-next" [color=green] - - "staging-next" -> master [color="red"] [label="manual merge"] [fontcolor="red"] - "staging" -> "staging-next" [color="red"] [label="manual merge"] [fontcolor="red"] - - master -> "staging-next" [color="green"] [label="automatic merge (GitHub Action)"] [fontcolor="green"] - "staging-next" -> staging [color="green"] [label="automatic merge (GitHub Action)"] [fontcolor="green"] -} -``` - -[This GitHub Action](https://github.com/NixOS/nixpkgs/blob/master/.github/workflows/periodic-merge-6h.yml) brings changes from `master` to `staging-next` and from `staging-next` to `staging` every 6 hours; these are the green arrows in the diagram above. The red arrows in the diagram above are done manually and much less frequently. You can get an idea of how often these merges occur by looking at the git history. - - -#### Master branch {#submitting-changes-master-branch} - -The `master` branch is the main development branch. It should only see non-breaking commits that do not cause mass rebuilds. - -#### Staging branch {#submitting-changes-staging-branch} - -The `staging` branch is a development branch where mass-rebuilds go. Mass rebuilds are commits that cause rebuilds for many packages, like more than 500 (or perhaps, if it's 'light' packages, 1000). It should only see non-breaking mass-rebuild commits. That means it is not to be used for testing, and changes must have been well tested already. If the branch is already in a broken state, please refrain from adding extra new breakages. - -During the process of a releasing a new NixOS version, this branch or the release-critical packages can be restricted to non-breaking changes. - -#### Staging-next branch {#submitting-changes-staging-next-branch} - -The `staging-next` branch is for stabilizing mass-rebuilds submitted to the `staging` branch prior to merging them into `master`. Mass-rebuilds must go via the `staging` branch. It must only see non-breaking commits that are fixing issues blocking it from being merged into the `master` branch. - -If the branch is already in a broken state, please refrain from adding extra new breakages. Stabilize it for a few days and then merge into master. - -During the process of a releasing a new NixOS version, this branch or the release-critical packages can be restricted to non-breaking changes. - -#### Stable release branches {#submitting-changes-stable-release-branches} - -The same staging workflow applies to stable release branches, but the main branch is called `release-*` instead of `master`. - -Example branch names: `release-21.11`, `staging-21.11`, `staging-next-21.11`. - -Most changes added to the stable release branches are cherry-picked (“backported”) from the `master` and staging branches. - -#### Automatically backporting a Pull Request {#submitting-changes-stable-release-branches-automatic-backports} - -Assign label `backport ` (e.g. `backport release-21.11`) to the PR and a backport PR is automatically created after the PR is merged. - -#### Manually backporting changes {#submitting-changes-stable-release-branches-manual-backports} - -Cherry-pick changes via `git cherry-pick -x ` so that the original commit id is included in the commit message. - -Add a reason for the backport when it is not obvious from the original commit message. You can do this by cherry picking with `git cherry-pick -xe `, which allows editing the commit message. This is not needed for minor version updates that include security and bug fixes but don't add new features or when the commit fixes an otherwise broken package. - -Here is an example of a cherry-picked commit message with good reason description: - -``` -zfs: Keep trying root import until it works - -Works around #11003. - -(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9) - -Reason: several people cannot boot with ZFS on NVMe -``` - -Other examples of reasons are: - -- Previously the build would fail due to, e.g., `getaddrinfo` not being defined -- The previous download links were all broken -- Crash when starting on some X11 systems - -#### Acceptable backport criteria {#acceptable-backport-criteria} - -The stable branch does have some changes which cannot be backported. Most notable are breaking changes. The desire is to have stable users be uninterrupted when updating packages. - -However, many changes are able to be backported, including: -- New Packages / Modules -- Security / Patch updates -- Version updates which include new functionality (but no breaking changes) -- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) -- Security critical applications (E.g. `firefox`) - ## Code conventions From 7ab012c60c5e3e02b1d447c7dc6539d87c28ea42 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 4 Aug 2023 22:49:53 +0200 Subject: [PATCH 24/42] CONTRIBUTING.md: Replace staging workflow diagram Can't be rendered in GitHub markdown, replacing it with a Git branch diagram using mermaid --- CONTRIBUTING.md | 62 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index be8a4b1729c9..8af84dead78f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -157,30 +157,52 @@ branch allows the Hydra operators to batch groups of commits to separate from `staging`, this batching does not block developers from merging changes into `staging`. -```{.graphviz caption="Staging workflow"} -digraph { - master [color="green" fontcolor=green] - "staging-next" [color="green" fontcolor=green] - staging [color="red" fontcolor=red] +```mermaid +%%{init: { + 'theme': 'base', + 'themeVariables': { + 'gitInv0': '#ff0000', + 'gitInv1': '#ff0000', + 'git2': '#ff4444', + 'commitLabelFontSize': '15px' + }, + 'gitGraph': { + 'showCommitLabel':true, + 'mainBranchName': 'master', + 'rotateCommitLabel': true + } +} }%% +gitGraph + commit id:" " + branch staging-next + branch staging - "small changes" [fontcolor=green shape=none] - "small changes" -> master [color=green] + checkout master + checkout staging + checkout master + commit id:" " + checkout staging-next + merge master id:"automatic" + checkout staging + merge staging-next id:"automatic " - "mass-rebuilds and other large changes" [fontcolor=red shape=none] - "mass-rebuilds and other large changes" -> staging [color=red] + checkout staging-next + merge staging type:HIGHLIGHT id:"manual" + commit id:"fixup" - "critical security fixes" [fontcolor=green shape=none] - "critical security fixes" -> master [color=green] + checkout master + checkout staging + checkout master + commit id:" " + checkout staging-next + merge master id:"automatic " + checkout staging + merge staging-next id:"automatic " - "staging fixes which do not cause staging to mass-rebuild" [fontcolor=green shape=none] - "staging fixes which do not cause staging to mass-rebuild" -> "staging-next" [color=green] - - "staging-next" -> master [color="red"] [label="manual merge"] [fontcolor="red"] - "staging" -> "staging-next" [color="red"] [label="manual merge"] [fontcolor="red"] - - master -> "staging-next" [color="green"] [label="automatic merge (GitHub Action)"] [fontcolor="green"] - "staging-next" -> staging [color="green"] [label="automatic merge (GitHub Action)"] [fontcolor="green"] -} + checkout staging-next + commit id:"fixup " + checkout master + merge staging-next type:HIGHLIGHT id:"manual (PR)" ``` [This GitHub Action](https://github.com/NixOS/nixpkgs/blob/master/.github/workflows/periodic-merge-6h.yml) brings changes from `master` to `staging-next` and from `staging-next` to `staging` every 6 hours; these are the green arrows in the diagram above. The red arrows in the diagram above are done manually and much less frequently. You can get an idea of how often these merges occur by looking at the git history. From 9cae39708bb77b48a40ce1a928e285b458c7ba59 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 7 Aug 2023 21:04:22 +0200 Subject: [PATCH 25/42] CONTRIBUTING.md: Clean up and condense staging workflow section --- CONTRIBUTING.md | 107 +++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 61 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8af84dead78f..4bcdbca5abda 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,57 +106,38 @@ This section describes in some detail how changes can be made and proposed with git push --force-with-lease ``` -## (Flow of changes) | Commit policy {#submitting-changes-commit-policy} +## Flow of changes -Most contributions are based on and merged into these branches: +After a Nixpkgs pull requests is merged, it eventually makes it to the [official Hydra CI](https://hydra.nixos.org/). +Hydra regularly evaluates and builds Nixpkgs, updating [the official channels](http://channels.nixos.org/) when specific Hydra jobs succeeded. +See [Nix Channel Status](https://status.nixos.org/) for the current channels and their state. +Here's a brief overview of the main Git branches and what channels they're used for: -* `master` is the main branch where all small contributions go -* `staging` is branched from master, changes that have a big impact on - Hydra builds go to this branch -* `staging-next` is branched from staging and only fixes to stabilize - and security fixes with a big impact on Hydra builds should be - contributed to this branch. This branch is merged into master when - deemed of sufficiently high quality +- `master`: The main branch, used for the unstable channels such as `nixpkgs-unstable`, `nixos-unstable` and `nixos-unstable-small`. +- `release-YY.MM` (e.g. `release-23.05`): The NixOS release branches, used for the stable channels such as `nixos-23.05`, `nixos-23.05-small` and `nixpkgs-23.05-darwin`. -- Commits must be sufficiently tested before being merged, both for the master and staging branches. -- Hydra builds for master and staging should not be used as testing platform, it’s a build farm for changes that have been already tested. -- When changing the bootloader installation process, extra care must be taken. Grub installations cannot be rolled back, hence changes may break people’s installations forever. For any non-trivial change to the bootloader please file a PR asking for review, especially from \@edolstra. +When a channel is updated, a corresponding Git branch is also updated to point to the corresponding commit. +So e.g. the [`nixpkgs-unstable` branch](https://github.com/nixos/nixpkgs/tree/nixpkgs-unstable) corresponds to the Git commit from the [`nixpkgs-unstable` channel](https://channels.nixos.org/nixpkgs-unstable). -### Branches {#submitting-changes-branches} +### Staging -The `nixpkgs` repository has three major branches: -- `master` -- `staging` -- `staging-next` +The staging workflow exists to batch Hydra builds of many packages together. -The most important distinction between them is that `staging` -(colored red in the diagram below) can receive commits which cause -a mass-rebuild (for example, anything that changes the `drvPath` of -`stdenv`). The other two branches `staging-next` and `master` -(colored green in the diagram below) can *not* receive commits which -cause a mass-rebuild. +It works by directing commits that cause [mass rebuilds](#mass-rebuilds) to a separate `staging` branch that isn't directly built by Hydra. +Regularly, the `staging` branch is _manually_ merged into a `staging-next` branch to be built by Hydra using the [`nixpkgs:staging-next` jobset](https://hydra.nixos.org/jobset/nixpkgs/staging-next). +The `staging-next` branch should then only receive direct commits in order to fix Hydra builds. +Once it is verified that there are no major regressions, it is merged into `master` using [a pull requests](https://github.com/NixOS/nixpkgs/pulls?q=head%3Astaging-next). +This is done manually in order to ensure it's a good use of Hydra's computing resources. +By keeping the `staging-next` branch separate from `staging`, this batching does not block developers from merging changes into `staging`. -Arcs between the branches show possible merges into these branches, -either from other branches or from independently submitted PRs. The -colors of these edges likewise show whether or not they could -trigger a mass rebuild (red) or must not trigger a mass rebuild -(green). +In order for the `staging` and `staging-next` branches to be up-to-date with the latest commits on `master`, there are regular _automated_ merges from `master` into `staging-next` and `staging`. +This is implemented using GitHub workflows [here](.github/workflows/periodic-merge-6h.yml) and [here](.github/workflows/periodic-merge-24h.yml). -Hydra runs automatic builds for the green branches. - -Notice that the automatic merges are all green arrows. This is by -design. Any merge which might cause a mass rebuild on a branch -which has automatic builds (`staging-next`, `master`) will be a -manual merge to make sure it is good use of compute power. - -Nixpkgs has two branches so that there is one branch (`staging`) -which accepts mass-rebuilding commits, and one fast-rebuilding -branch which accepts independent PRs (`master`). The `staging-next` -branch allows the Hydra operators to batch groups of commits to -`staging` to be built. By keeping the `staging-next` branch -separate from `staging`, this batching does not block -developers from merging changes into `staging`. +> **Note** +> Changes must be sufficiently tested before being merged into any branch. +> Hydra builds should not be used as testing platform. +Here is a Git history diagram showing the flow of commits between the three branches: ```mermaid %%{init: { 'theme': 'base', @@ -205,32 +186,33 @@ gitGraph merge staging-next type:HIGHLIGHT id:"manual (PR)" ``` -[This GitHub Action](https://github.com/NixOS/nixpkgs/blob/master/.github/workflows/periodic-merge-6h.yml) brings changes from `master` to `staging-next` and from `staging-next` to `staging` every 6 hours; these are the green arrows in the diagram above. The red arrows in the diagram above are done manually and much less frequently. You can get an idea of how often these merges occur by looking at the git history. +Here's an overview of the different branches: -#### Master branch {#submitting-changes-master-branch} +| branch | `master` | `staging` | `staging-next` | +| --- | --- | --- | --- | +| Used for development | :heavy_check_mark: | :heavy_check_mark: | :x: | +| Built by Hydra | :heavy_check_mark: | :x: | :heavy_check_mark: | +| [Mass rebuilds](#mass-rebuilds) | :x: | :heavy_check_mark: | :warning: Only to fix Hydra builds | +| Critical security fixes | :heavy_check_mark: for non-mass-rebuilds | :x: | :heavy_check_mark: for mass-rebuilds | +| Automatically merged into | `staging-next` | - | `staging` | +| Manually merged into | - | `staging-next` | `master` | -The `master` branch is the main development branch. It should only see non-breaking commits that do not cause mass rebuilds. +The staging workflow is used for all main branches, `master` and `release-YY.MM`, with corresponding names: +- `master`/`release-YY.MM` +- `staging`/`staging-YY.MM` +- `staging-next`/`staging-next-YY.MM` -#### Staging branch {#submitting-changes-staging-branch} +#### Mass rebuilds -The `staging` branch is a development branch where mass-rebuilds go. Mass rebuilds are commits that cause rebuilds for many packages, like more than 500 (or perhaps, if it's 'light' packages, 1000). It should only see non-breaking mass-rebuild commits. That means it is not to be used for testing, and changes must have been well tested already. If the branch is already in a broken state, please refrain from adding extra new breakages. +Which changes cause mass rebuilds is not formally defined. +In order to help the decision, CI automatically assigns [`rebuild` labels](https://github.com/NixOS/nixpkgs/labels?q=rebuild) to pull requests based on the number of packages they cause rebuilds for. +As a rule of thumb, if the number of rebuilds is **over 500**, it can be considered a mass rebuild. +To get a sense for what changes are considered mass rebuilds, see [previously merged pull requests to the staging branches](https://github.com/NixOS/nixpkgs/issues?q=base%3Astaging+-base%3Astaging-next+is%3Amerged). -During the process of a releasing a new NixOS version, this branch or the release-critical packages can be restricted to non-breaking changes. +### Releases -#### Staging-next branch {#submitting-changes-staging-next-branch} - -The `staging-next` branch is for stabilizing mass-rebuilds submitted to the `staging` branch prior to merging them into `master`. Mass-rebuilds must go via the `staging` branch. It must only see non-breaking commits that are fixing issues blocking it from being merged into the `master` branch. - -If the branch is already in a broken state, please refrain from adding extra new breakages. Stabilize it for a few days and then merge into master. - -During the process of a releasing a new NixOS version, this branch or the release-critical packages can be restricted to non-breaking changes. - -#### Stable release branches {#submitting-changes-stable-release-branches} - -The same staging workflow applies to stable release branches, but the main branch is called `release-*` instead of `master`. - -Example branch names: `release-21.11`, `staging-21.11`, `staging-next-21.11`. +The NixOS release process is documented in the [NixOS Release Wiki](https://nixos.github.io/release-wiki/) Most changes added to the stable release branches are cherry-picked (“backported”) from the `master` and staging branches. @@ -640,6 +622,9 @@ Names of files and directories should be in lowercase, with dashes between words ## Commit conventions + +- When changing the bootloader installation process, extra care must be taken. Grub installations cannot be rolled back, hence changes may break people’s installations forever. For any non-trivial change to the bootloader please file a PR asking for review, especially from \@edolstra. + - Create a commit for each logical unit. - Check for unnecessary whitespace with `git diff --check` before committing. From b66560884542d2c6d2cc1e7cdcd1202f8347e88d Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 7 Aug 2023 21:18:42 +0200 Subject: [PATCH 26/42] CONTRIBUTING.md: Move release sections together Will be cleaned up in the next commit --- CONTRIBUTING.md | 142 ++++++++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4bcdbca5abda..b6a504104221 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -119,6 +119,77 @@ Here's a brief overview of the main Git branches and what channels they're used When a channel is updated, a corresponding Git branch is also updated to point to the corresponding commit. So e.g. the [`nixpkgs-unstable` branch](https://github.com/nixos/nixpkgs/tree/nixpkgs-unstable) corresponds to the Git commit from the [`nixpkgs-unstable` channel](https://channels.nixos.org/nixpkgs-unstable). +### Releases + +The NixOS release process is documented in the [NixOS Release Wiki](https://nixos.github.io/release-wiki/) + +Most changes added to the stable release branches are cherry-picked (“backported”) from the `master` and staging branches. + +#### Backporting changes + +Follow these steps to backport a change into a release branch in compliance with the [commit policy](https://nixos.org/nixpkgs/manual/#submitting-changes-stable-release-branches). + +You can add a label such as `backport release-23.05` to a PR, so that merging it will +automatically create a backport (via [a GitHub Action](.github/workflows/backport.yml)). +This also works for pull requests that have already been merged, and might take a couple of minutes to trigger. + +You can also create the backport manually: + +1. Take note of the commits in which the change was introduced into `master` branch. +2. Check out the target _release branch_, e.g. `release-23.05`. Do not use a _channel branch_ like `nixos-23.05` or `nixpkgs-23.05-darwin`. +3. Create a branch for your change, e.g. `git checkout -b backport`. +4. When the reason to backport is not obvious from the original commit message, use `git cherry-pick -xe ` and add a reason. Otherwise use `git cherry-pick -x `. That's fine for minor version updates that only include security and bug fixes, commits that fixes an otherwise broken package or similar. Please also ensure the commits exists on the master branch; in the case of squashed or rebased merges, the commit hash will change and the new commits can be found in the merge message at the bottom of the master pull request. +5. Push to GitHub and open a backport pull request. Make sure to select the release branch (e.g. `release-23.05`) as the target branch of the pull request, and link to the pull request in which the original change was committed to `master`. The pull request title should be the commit title with the release version as prefix, e.g. `[23.05]`. +6. When the backport pull request is merged and you have the necessary privileges you can also replace the label `9.needs: port to stable` with `8.has: port to stable` on the original pull request. This way maintainers can keep track of missing backports easier. + +#### Automatically backporting a Pull Request {#submitting-changes-stable-release-branches-automatic-backports} + +Assign label `backport ` (e.g. `backport release-21.11`) to the PR and a backport PR is automatically created after the PR is merged. + +#### Manually backporting changes {#submitting-changes-stable-release-branches-manual-backports} + +Cherry-pick changes via `git cherry-pick -x ` so that the original commit id is included in the commit message. + +Add a reason for the backport when it is not obvious from the original commit message. You can do this by cherry picking with `git cherry-pick -xe `, which allows editing the commit message. This is not needed for minor version updates that include security and bug fixes but don't add new features or when the commit fixes an otherwise broken package. + +Here is an example of a cherry-picked commit message with good reason description: + +``` +zfs: Keep trying root import until it works + +Works around #11003. + +(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9) + +Reason: several people cannot boot with ZFS on NVMe +``` + +Other examples of reasons are: + +- Previously the build would fail due to, e.g., `getaddrinfo` not being defined +- The previous download links were all broken +- Crash when starting on some X11 systems + +#### Acceptable backport criteria {#acceptable-backport-criteria} + +The stable branch does have some changes which cannot be backported. Most notable are breaking changes. The desire is to have stable users be uninterrupted when updating packages. + +However, many changes are able to be backported, including: +- New Packages / Modules +- Security / Patch updates +- Version updates which include new functionality (but no breaking changes) +- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) +- Security critical applications (E.g. `firefox`) + +#### Criteria for Backporting changes + +Anything that does not cause user or downstream dependency regressions can be backported. This includes: +- New Packages / Modules +- Security / Patch updates +- Version updates which include new functionality (but no breaking changes) +- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) +- Security critical applications (E.g. `firefox`) + ### Staging The staging workflow exists to batch Hydra builds of many packages together. @@ -210,51 +281,6 @@ In order to help the decision, CI automatically assigns [`rebuild` labels](https As a rule of thumb, if the number of rebuilds is **over 500**, it can be considered a mass rebuild. To get a sense for what changes are considered mass rebuilds, see [previously merged pull requests to the staging branches](https://github.com/NixOS/nixpkgs/issues?q=base%3Astaging+-base%3Astaging-next+is%3Amerged). -### Releases - -The NixOS release process is documented in the [NixOS Release Wiki](https://nixos.github.io/release-wiki/) - -Most changes added to the stable release branches are cherry-picked (“backported”) from the `master` and staging branches. - -#### Automatically backporting a Pull Request {#submitting-changes-stable-release-branches-automatic-backports} - -Assign label `backport ` (e.g. `backport release-21.11`) to the PR and a backport PR is automatically created after the PR is merged. - -#### Manually backporting changes {#submitting-changes-stable-release-branches-manual-backports} - -Cherry-pick changes via `git cherry-pick -x ` so that the original commit id is included in the commit message. - -Add a reason for the backport when it is not obvious from the original commit message. You can do this by cherry picking with `git cherry-pick -xe `, which allows editing the commit message. This is not needed for minor version updates that include security and bug fixes but don't add new features or when the commit fixes an otherwise broken package. - -Here is an example of a cherry-picked commit message with good reason description: - -``` -zfs: Keep trying root import until it works - -Works around #11003. - -(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9) - -Reason: several people cannot boot with ZFS on NVMe -``` - -Other examples of reasons are: - -- Previously the build would fail due to, e.g., `getaddrinfo` not being defined -- The previous download links were all broken -- Crash when starting on some X11 systems - -#### Acceptable backport criteria {#acceptable-backport-criteria} - -The stable branch does have some changes which cannot be backported. Most notable are breaking changes. The desire is to have stable users be uninterrupted when updating packages. - -However, many changes are able to be backported, including: -- New Packages / Modules -- Security / Patch updates -- Version updates which include new functionality (but no breaking changes) -- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) -- Security critical applications (E.g. `firefox`) - #### Rebasing between branches (i.e. from master to staging) From time to time, changes between branches must be rebased, for example, if the @@ -329,32 +355,6 @@ for review, which allows you to sidestep this issue. This is not a bulletproof method though, as OfBorg still does review requests even on draft PRs. ``` -### Backporting changes - -Follow these steps to backport a change into a release branch in compliance with the [commit policy](https://nixos.org/nixpkgs/manual/#submitting-changes-stable-release-branches). - -You can add a label such as `backport release-23.05` to a PR, so that merging it will -automatically create a backport (via [a GitHub Action](.github/workflows/backport.yml)). -This also works for pull requests that have already been merged, and might take a couple of minutes to trigger. - -You can also create the backport manually: - -1. Take note of the commits in which the change was introduced into `master` branch. -2. Check out the target _release branch_, e.g. `release-23.05`. Do not use a _channel branch_ like `nixos-23.05` or `nixpkgs-23.05-darwin`. -3. Create a branch for your change, e.g. `git checkout -b backport`. -4. When the reason to backport is not obvious from the original commit message, use `git cherry-pick -xe ` and add a reason. Otherwise use `git cherry-pick -x `. That's fine for minor version updates that only include security and bug fixes, commits that fixes an otherwise broken package or similar. Please also ensure the commits exists on the master branch; in the case of squashed or rebased merges, the commit hash will change and the new commits can be found in the merge message at the bottom of the master pull request. -5. Push to GitHub and open a backport pull request. Make sure to select the release branch (e.g. `release-23.05`) as the target branch of the pull request, and link to the pull request in which the original change was committed to `master`. The pull request title should be the commit title with the release version as prefix, e.g. `[23.05]`. -6. When the backport pull request is merged and you have the necessary privileges you can also replace the label `9.needs: port to stable` with `8.has: port to stable` on the original pull request. This way maintainers can keep track of missing backports easier. - -#### Criteria for Backporting changes - -Anything that does not cause user or downstream dependency regressions can be backported. This includes: -- New Packages / Modules -- Security / Patch updates -- Version updates which include new functionality (but no breaking changes) -- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) -- Security critical applications (E.g. `firefox`) - ### Hotfixing pull requests {#submitting-changes-hotfixing-pull-requests} - Make the appropriate changes in you branch. From 3639a9e4822540c3d4ae219e760edea7bab2fc23 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 7 Aug 2023 22:37:31 +0200 Subject: [PATCH 27/42] CONTRIBUTING.md: Clean up releases section --- CONTRIBUTING.md | 100 ++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 54 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b6a504104221..82bb0edb63f9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -121,74 +121,66 @@ So e.g. the [`nixpkgs-unstable` branch](https://github.com/nixos/nixpkgs/tree/ni ### Releases -The NixOS release process is documented in the [NixOS Release Wiki](https://nixos.github.io/release-wiki/) +Nixpkgs in its entirety is tied to the NixOS release process, which is documented in the [NixOS Release Wiki](https://nixos.github.io/release-wiki/). -Most changes added to the stable release branches are cherry-picked (“backported”) from the `master` and staging branches. +Changes should generally always go to the `master` branch. +Once in `master`, it can be backported to the `release-YY.MM` branches if [acceptable](#acceptable-backport-criteria). +A change should only go to the `release-YY.MM` branch directly if `master` doesn't need that change. + +#### Acceptable backport criteria + +Backports are only accepted to supported releases. +The oldest supported release (`YYMM`) can be found using +``` +nix-instantiate --eval -A lib.trivial.oldestSupportedRelease +``` + +The release branches should generally not receive any breaking changes, both for the Nix expressions and derivations. +So these changes are acceptable to backport: +- New packages, modules and functions +- Security fixes +- Package version updates + - Patch versions with fixes + - Minor versions with new functionality, but no breaking changes + +In addition, major package version updates with breaking changes are also acceptable for: +- Services that would fail without up-to-date client software, such as `spotify`, `steam`, and `discord` +- Security critical applications, such as `firefox` and `chromium` #### Backporting changes -Follow these steps to backport a change into a release branch in compliance with the [commit policy](https://nixos.org/nixpkgs/manual/#submitting-changes-stable-release-branches). +Once a pull request has been merged into `master`, a backport pull request to the corresponding `release-YY.MM` branch can be created either automatically or manually. -You can add a label such as `backport release-23.05` to a PR, so that merging it will -automatically create a backport (via [a GitHub Action](.github/workflows/backport.yml)). -This also works for pull requests that have already been merged, and might take a couple of minutes to trigger. +##### Automatically backporting changes -You can also create the backport manually: +> **Note** +> You have to be a [Nixpkgs maintainer](./maintainers) to automatically create a backport pull request. -1. Take note of the commits in which the change was introduced into `master` branch. -2. Check out the target _release branch_, e.g. `release-23.05`. Do not use a _channel branch_ like `nixos-23.05` or `nixpkgs-23.05-darwin`. -3. Create a branch for your change, e.g. `git checkout -b backport`. -4. When the reason to backport is not obvious from the original commit message, use `git cherry-pick -xe ` and add a reason. Otherwise use `git cherry-pick -x `. That's fine for minor version updates that only include security and bug fixes, commits that fixes an otherwise broken package or similar. Please also ensure the commits exists on the master branch; in the case of squashed or rebased merges, the commit hash will change and the new commits can be found in the merge message at the bottom of the master pull request. -5. Push to GitHub and open a backport pull request. Make sure to select the release branch (e.g. `release-23.05`) as the target branch of the pull request, and link to the pull request in which the original change was committed to `master`. The pull request title should be the commit title with the release version as prefix, e.g. `[23.05]`. -6. When the backport pull request is merged and you have the necessary privileges you can also replace the label `9.needs: port to stable` with `8.has: port to stable` on the original pull request. This way maintainers can keep track of missing backports easier. +Add the [`backport release-YY.MM` label](https://github.com/NixOS/nixpkgs/labels?q=backport) to the pull request on the `master` branch. +This will cause [a GitHub Action](.github/workflows/backport.yml) to open a pull request to the `release-YY.MM` branch a few minutes later. +This can be done on both open or already merged pull requests. -#### Automatically backporting a Pull Request {#submitting-changes-stable-release-branches-automatic-backports} +##### Manually backporting changes -Assign label `backport ` (e.g. `backport release-21.11`) to the PR and a backport PR is automatically created after the PR is merged. +To manually create a backport pull request, follow [the standard pull request process](#how-to-propose-a-change), with these notable differences: -#### Manually backporting changes {#submitting-changes-stable-release-branches-manual-backports} +- Use `release-YY.MM` for the base branch, both for the local branch and the pull request. + > **Warning** + > Do not use the `nixos-YY.MM` branch, that is a branch pointing to the tested release channel commit -Cherry-pick changes via `git cherry-pick -x ` so that the original commit id is included in the commit message. +- Instead of making manually making and committing the changes, use [`git cherry-pick -x`](https://git-scm.com/docs/git-cherry-pick) for each commit from the pull request you'd like to backport. + Either `git cherry-pick -x ` when the reason for the backport is obvious (such as minor versions, fixes, etc.), otherwise use `git cherry-pickx -xe ` to add a reason for the backport to the commit message. + Here is [an example](5688c39af5a6c5f3d646343443683da880eaefb8) of this. -Add a reason for the backport when it is not obvious from the original commit message. You can do this by cherry picking with `git cherry-pick -xe `, which allows editing the commit message. This is not needed for minor version updates that include security and bug fixes but don't add new features or when the commit fixes an otherwise broken package. + > **Warning** + > Ensure the commits exists on the master branch. + > In the case of squashed or rebased merges, the commit hash will change and the new commits can be found in the merge message at the bottom of the master pull request. -Here is an example of a cherry-picked commit message with good reason description: +- In the pull request description, link to the original pull request to `master`. + The pull request title should include `[YY.MM]` matching the release you're backporting to. -``` -zfs: Keep trying root import until it works - -Works around #11003. - -(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9) - -Reason: several people cannot boot with ZFS on NVMe -``` - -Other examples of reasons are: - -- Previously the build would fail due to, e.g., `getaddrinfo` not being defined -- The previous download links were all broken -- Crash when starting on some X11 systems - -#### Acceptable backport criteria {#acceptable-backport-criteria} - -The stable branch does have some changes which cannot be backported. Most notable are breaking changes. The desire is to have stable users be uninterrupted when updating packages. - -However, many changes are able to be backported, including: -- New Packages / Modules -- Security / Patch updates -- Version updates which include new functionality (but no breaking changes) -- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) -- Security critical applications (E.g. `firefox`) - -#### Criteria for Backporting changes - -Anything that does not cause user or downstream dependency regressions can be backported. This includes: -- New Packages / Modules -- Security / Patch updates -- Version updates which include new functionality (but no breaking changes) -- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) -- Security critical applications (E.g. `firefox`) +- When the backport pull request is merged and you have the necessary privileges you can also replace the label `9.needs: port to stable` with `8.has: port to stable` on the original pull request. + This way maintainers can keep track of missing backports easier. ### Staging From 4e3064d1b9eff6af9b54e15c2597a7a7079d028d Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Sun, 13 Aug 2023 22:29:52 +0200 Subject: [PATCH 28/42] CONTRIBUTING.md: Minor formatting fixes --- CONTRIBUTING.md | 51 +++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 82bb0edb63f9..5f4cb6d07df6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,11 +10,11 @@ If that's not the case, we recommend learning about it first [here](https://docs ## Overview This file contains general contributing information, but individual parts also have more specific information to them in their respective `README.md` files, linked here: -- [`lib`](./lib): Sources and documentation of the [library functions](https://nixos.org/manual/nixpkgs/stable/#chap-functions) -- [`maintainers`](./maintainers): Nixpkgs maintainer and team listings, maintainer scripts -- [`pkgs`](./pkgs): Package and [builder](https://nixos.org/manual/nixpkgs/stable/#part-builders) definitions -- [`doc`](./doc): Sources and infrastructure for the [Nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/) -- [`nixos`](./nixos): Implementation of [NixOS](https://nixos.org/manual/nixos/stable/) +- [`lib`](./lib/README.md): Sources and documentation of the [library functions](https://nixos.org/manual/nixpkgs/stable/#chap-functions) +- [`maintainers`](./maintainers/README.md): Nixpkgs maintainer and team listings, maintainer scripts +- [`pkgs`](./pkgs/README.md): Package and [builder](https://nixos.org/manual/nixpkgs/stable/#part-builders) definitions +- [`doc`](./doc/README.md): Sources and infrastructure for the [Nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/) +- [`nixos`](./nixos/README.md): Implementation of [NixOS](https://nixos.org/manual/nixos/stable/) ## How to propose a change @@ -98,7 +98,7 @@ This section describes in some detail how changes can be made and proposed with git push --force-with-lease ``` - In case of merge conflicts you will also have to [rebasing the branch](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) on top of current `master`. + In case of merge conflicts you will also have to [rebase the branch](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) on top of current `master`. Sometimes this can be done [on GitHub directly](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/keeping-your-pull-request-in-sync-with-the-base-branch#updating-your-pull-request-branch), but if not you will have to rebase locally using ``` git fetch upstream @@ -347,18 +347,17 @@ for review, which allows you to sidestep this issue. This is not a bulletproof method though, as OfBorg still does review requests even on draft PRs. ``` -### Hotfixing pull requests {#submitting-changes-hotfixing-pull-requests} +### Hotfixing pull requests - Make the appropriate changes in you branch. - Don’t create additional commits, do - `git rebase -i` - `git push --force` to your branch. -## Reviewing contributions {#chap-reviewing-contributions} +## Reviewing contributions -::: {.warning} -The following section is a draft, and the policy for reviewing is still being discussed in issues such as [#11166](https://github.com/NixOS/nixpkgs/issues/11166) and [#20836](https://github.com/NixOS/nixpkgs/issues/20836). -::: +> **Warning** +> The following section is a draft, and the policy for reviewing is still being discussed in issues such as [#11166](https://github.com/NixOS/nixpkgs/issues/11166) and [#20836](https://github.com/NixOS/nixpkgs/issues/20836). The Nixpkgs project receives a fairly high number of contributions via GitHub pull requests. Reviewing and approving these is an important task and a way to contribute to the project. @@ -372,15 +371,13 @@ Pull request reviews should include a list of what has been reviewed in a commen All the review template samples provided in this section are generic and meant as examples. Their usage is optional and the reviewer is free to adapt them to their liking. -### Other submissions {#reviewing-contributions-other-submissions} - -Other type of submissions requires different reviewing steps. +To get more information about how to review specific parts of Nixpkgs, refer to the documents linked to in the [overview section](#overview). If you consider having enough knowledge and experience in a topic and would like to be a long-term reviewer for related submissions, please contact the current reviewers for that topic. They will give you information about the reviewing process. The main reviewers for a topic can be hard to find as there is no list, but checking past pull requests to see who reviewed or git-blaming the code to see who committed to that topic can give some hints. Container system, boot system and library changes are some examples of the pull requests fitting this category. -## (Merging a pull request) | Merging pull requests {#reviewing-contributions--merging-pull-requests} +## Merging pull requests The *Nixpkgs committers* are people who have been given permission to merge. @@ -408,13 +405,13 @@ In a case a contributor definitively leaves the Nix community, they should creat ### Release notes -If you removed pkgs or made some major NixOS changes, write about it in the release notes for the next stable release. For example `nixos/doc/manual/release-notes/rl-2003.xml`. +If you removed pkgs or made some major NixOS changes, write about it in the release notes for the next stable release in [`nixos/doc/manual/release-notes`](./nixos/doc/manual/release-notes). -### File naming and organisation {#sec-organisation} +### File naming and organisation Names of files and directories should be in lowercase, with dashes between words — not in camel case. For instance, it should be `all-packages.nix`, not `allPackages.nix` or `AllPackages.nix`. -### Syntax {#sec-syntax} +### Syntax - Use 2 spaces of indentation per indentation level in Nix expressions, 4 spaces in shell scripts. @@ -654,17 +651,17 @@ Package version upgrades usually allow for simpler commit messages, including at Pull requests should not be squash merged in order to keep complete commit messages and GPG signatures intact and must not be when the change doesn't make sense as a single commit. -## Pull Request Template {#submitting-changes-pull-request-template} +## Pull Request Template The pull request template helps determine what steps have been made for a contribution so far, and will help guide maintainers on the status of a change. The motivation section of the PR should include any extra details the title does not address and link any existing issues related to the pull request. When a PR is created, it will be pre-populated with some checkboxes detailed below: -### Tested using sandboxing {#submitting-changes-tested-with-sandbox} +### Tested using sandboxing When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of `fetch*` functions and files outside the Nix store. Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [sandbox](https://nixos.org/nix/manual/#conf-sandbox) in Nix manual for details. -Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for [nixpkgs](https://github.com/NixOS/nixpkgs/) people are asked to test builds with sandboxing enabled (see `Tested using sandboxing` in the pull request template) because in sandboxing is also used. +Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for [nixpkgs](https://github.com/NixOS/nixpkgs/) people are asked to test builds with sandboxing enabled (see `Tested using sandboxing` in the pull request template) because in [Hydra](https://nixos.org/hydra/) sandboxing is also used. Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing **before** building the package: @@ -680,15 +677,15 @@ Depending if you use NixOS or other platforms you can use one of the following m sandbox = true ``` -### Built on platform(s) {#submitting-changes-platform-diversity} +### Built on platform(s) Many Nix packages are designed to run on multiple platforms. As such, it’s important to let the maintainer know which platforms your changes have been tested on. It’s not always practical to test a change on all platforms, and is not required for a pull request to be merged. Only check the systems you tested the build on in this section. -### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) {#submitting-changes-nixos-tests} +### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) Packages with automated tests are much more likely to be merged in a timely fashion because it doesn’t require as much manual testing by the maintainer to verify the functionality of the package. If there are existing tests for the package, they should be run to verify your changes do not break the tests. Tests can only be run on Linux. For more details on writing and running tests, see the [section in the NixOS manual](https://nixos.org/nixos/manual/index.html#sec-nixos-tests). -### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` {#submitting-changes-tested-compilation} +### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` If you are updating a package’s version, you can use `nixpkgs-review` to make sure all packages that depend on the updated package still compile correctly. The `nixpkgs-review` utility can look for and build all dependencies either based on uncommitted changes with the `wip` option or specifying a GitHub pull request number. @@ -716,10 +713,10 @@ Review changes from last commit: nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD" ``` -### Tested execution of all binary files (usually in `./result/bin/`) {#submitting-changes-tested-execution} +### Tested execution of all binary files (usually in `./result/bin/`) It’s important to test any executables generated by a build when you change or create a package in nixpkgs. This can be done by looking in `./result/bin` and running any files in there, or at a minimum, the main executable for the package. For example, if you make a change to texlive, you probably would only check the binaries associated with the change you made rather than testing all of them. -### Meets Nixpkgs contribution standards {#submitting-changes-contribution-standards} +### Meets Nixpkgs contribution standards -The last checkbox is fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md). The contributing document has detailed information on standards the Nix community has for commit messages, reviews, licensing of contributions you make to the project, etc... Everyone should read and understand the standards the community has for contributing before submitting a pull request. +The last checkbox is fits the guidelines in this `CONTRIBUTING.md` file. The contributing document has detailed information on standards the Nix community has for commit messages, reviews, licensing of contributions you make to the project, etc... Everyone should read and understand the standards the community has for contributing before submitting a pull request. From 2f345d070bf64051884867f3f3087932638c999c Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Sun, 13 Aug 2023 22:32:45 +0200 Subject: [PATCH 29/42] CONTRIBUTING.md: Remove duplicated section How to force push to PR's is already explained in the "How to propose a change" section at the beginning --- CONTRIBUTING.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5f4cb6d07df6..2d4829e2cede 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -347,13 +347,6 @@ for review, which allows you to sidestep this issue. This is not a bulletproof method though, as OfBorg still does review requests even on draft PRs. ``` -### Hotfixing pull requests - -- Make the appropriate changes in you branch. -- Don’t create additional commits, do - - `git rebase -i` - - `git push --force` to your branch. - ## Reviewing contributions > **Warning** From 2a99b5a70377478aa2e3dc65db60f497b9d39356 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Sun, 13 Aug 2023 22:34:34 +0200 Subject: [PATCH 30/42] CONTRIBUTING.md: Move rebasing section up Right into the "How to propose a change" section, because that's where it's relevant --- CONTRIBUTING.md | 148 ++++++++++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2d4829e2cede..a5706acd153b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,6 +106,80 @@ This section describes in some detail how changes can be made and proposed with git push --force-with-lease ``` +### Rebasing between branches (i.e. from master to staging) + +From time to time, changes between branches must be rebased, for example, if the +number of new rebuilds they would cause is too large for the target branch. When +rebasing, care must be taken to include only the intended changes, otherwise +many CODEOWNERS will be inadvertently requested for review. To achieve this, +rebasing should not be performed directly on the target branch, but on the merge +base between the current and target branch. As an additional precautionary measure, +you should temporarily mark the PR as draft for the duration of the operation. +This reduces the probability of mass-pinging people. (OfBorg might still +request a couple of persons for reviews though.) + +In the following example, we assume that the current branch, called `feature`, +is based on `master`, and we rebase it onto the merge base between +`master` and `staging` so that the PR can eventually be retargeted to +`staging` without causing a mess. The example uses `upstream` as the remote for `NixOS/nixpkgs.git` +while `origin` is the remote you are pushing to. + + +```console +# Rebase your commits onto the common merge base +git rebase --onto upstream/staging... upstream/master +# Force push your changes +git push origin feature --force-with-lease +``` + +The syntax `upstream/staging...` is equivalent to `upstream/staging...HEAD` and +stands for the merge base between `upstream/staging` and `HEAD` (hence between +`upstream/staging` and `upstream/master`). + +Then change the base branch in the GitHub PR using the *Edit* button in the upper +right corner, and switch from `master` to `staging`. *After* the PR has been +retargeted it might be necessary to do a final rebase onto the target branch, to +resolve any outstanding merge conflicts. + +```console +# Rebase onto target branch +git rebase upstream/staging +# Review and fixup possible conflicts +git status +# Force push your changes +git push origin feature --force-with-lease +``` + +#### Something went wrong and a lot of people were pinged + +It happens. Remember to be kind, especially to new contributors. +There is no way back, so the pull request should be closed and locked +(if possible). The changes should be re-submitted in a new PR, in which the people +originally involved in the conversation need to manually be pinged again. +No further discussion should happen on the original PR, as a lot of people +are now subscribed to it. + +The following message (or a version thereof) might be left when closing to +describe the situation, since closing and locking without any explanation +is kind of rude: + +```markdown +It looks like you accidentally mass-pinged a bunch of people, which are now subscribed +and getting notifications for everything in this pull request. Unfortunately, they +cannot be automatically unsubscribed from the issue (removing review request does not +unsubscribe), therefore development cannot continue in this pull request anymore. + +Please open a new pull request with your changes, link back to this one and ping the +people actually involved in here over there. + +In order to avoid this in the future, there are instructions for how to properly +rebase between branches in our [contribution guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#rebasing-between-branches-ie-from-master-to-staging). +Setting your pull request to draft prior to rebasing is strongly recommended. +In draft status, you can preview the list of people that are about to be requested +for review, which allows you to sidestep this issue. +This is not a bulletproof method though, as OfBorg still does review requests even on draft PRs. +``` + ## Flow of changes After a Nixpkgs pull requests is merged, it eventually makes it to the [official Hydra CI](https://hydra.nixos.org/). @@ -273,80 +347,6 @@ In order to help the decision, CI automatically assigns [`rebuild` labels](https As a rule of thumb, if the number of rebuilds is **over 500**, it can be considered a mass rebuild. To get a sense for what changes are considered mass rebuilds, see [previously merged pull requests to the staging branches](https://github.com/NixOS/nixpkgs/issues?q=base%3Astaging+-base%3Astaging-next+is%3Amerged). -#### Rebasing between branches (i.e. from master to staging) - -From time to time, changes between branches must be rebased, for example, if the -number of new rebuilds they would cause is too large for the target branch. When -rebasing, care must be taken to include only the intended changes, otherwise -many CODEOWNERS will be inadvertently requested for review. To achieve this, -rebasing should not be performed directly on the target branch, but on the merge -base between the current and target branch. As an additional precautionary measure, -you should temporarily mark the PR as draft for the duration of the operation. -This reduces the probability of mass-pinging people. (OfBorg might still -request a couple of persons for reviews though.) - -In the following example, we assume that the current branch, called `feature`, -is based on `master`, and we rebase it onto the merge base between -`master` and `staging` so that the PR can eventually be retargeted to -`staging` without causing a mess. The example uses `upstream` as the remote for `NixOS/nixpkgs.git` -while `origin` is the remote you are pushing to. - - -```console -# Rebase your commits onto the common merge base -git rebase --onto upstream/staging... upstream/master -# Force push your changes -git push origin feature --force-with-lease -``` - -The syntax `upstream/staging...` is equivalent to `upstream/staging...HEAD` and -stands for the merge base between `upstream/staging` and `HEAD` (hence between -`upstream/staging` and `upstream/master`). - -Then change the base branch in the GitHub PR using the *Edit* button in the upper -right corner, and switch from `master` to `staging`. *After* the PR has been -retargeted it might be necessary to do a final rebase onto the target branch, to -resolve any outstanding merge conflicts. - -```console -# Rebase onto target branch -git rebase upstream/staging -# Review and fixup possible conflicts -git status -# Force push your changes -git push origin feature --force-with-lease -``` - -##### Something went wrong and a lot of people were pinged - -It happens. Remember to be kind, especially to new contributors. -There is no way back, so the pull request should be closed and locked -(if possible). The changes should be re-submitted in a new PR, in which the people -originally involved in the conversation need to manually be pinged again. -No further discussion should happen on the original PR, as a lot of people -are now subscribed to it. - -The following message (or a version thereof) might be left when closing to -describe the situation, since closing and locking without any explanation -is kind of rude: - -```markdown -It looks like you accidentally mass-pinged a bunch of people, which are now subscribed -and getting notifications for everything in this pull request. Unfortunately, they -cannot be automatically unsubscribed from the issue (removing review request does not -unsubscribe), therefore development cannot continue in this pull request anymore. - -Please open a new pull request with your changes, link back to this one and ping the -people actually involved in here over there. - -In order to avoid this in the future, there are instructions for how to properly -rebase between branches in our [contribution guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#rebasing-between-branches-ie-from-master-to-staging). -Setting your pull request to draft prior to rebasing is strongly recommended. -In draft status, you can preview the list of people that are about to be requested -for review, which allows you to sidestep this issue. -This is not a bulletproof method though, as OfBorg still does review requests even on draft PRs. -``` - ## Reviewing contributions > **Warning** From 0bd8c9b4f9e2af62795dfbc257aa63bcb89e33e8 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 02:11:50 +0200 Subject: [PATCH 31/42] CONTRIBUTING.md: New section on which branch to use --- CONTRIBUTING.md | 81 ++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a5706acd153b..9876d4d9e6b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,7 @@ This section describes in some detail how changes can be made and proposed with - The name of the branch hints at the change you'd like to implement, e.g. `update-hello`. - The base of the branch includes the most recent changes on the `master` branch. > **Note** - > Depending on the change you may want to use a different branch, see + > Depending on the change you may want to use a different branch, see [][branch]. ```bash # Make sure you have the latest changes from upstream Nixpkgs @@ -106,6 +106,54 @@ This section describes in some detail how changes can be made and proposed with git push --force-with-lease ``` +### Which branch to use +[branch]: #which-branch-to-use + +Most changes should go to the `master` branch, but sometimes other branches should be used instead. +Use the following decision process to figure out which one it should be: + +Is the change [acceptable for releases][release-acceptable] and do you wish to have the change in the release? +- No: Use the `master` branch, do not backport the pull request. +- Yes: Can the change be implemented the same way on the `master` and release branches? + For example, a packages major version might differ between the `master` and release branches, such that separate security patches are required. + - Yes: Use the `master` branch and [backport the pull request](#backporting-changes). + - No: Create separate pull requests to the `master` and `release-XX.YY` branches. + +Furthermore, if the change causes a [mass rebuild][mass-rebuilds], use the appropriate staging branch instead: +- Mass rebuilds to `master` should go to `staging` instead. +- Mass rebuilds to `release-XX.YY` should go to `staging-XX.YY` instead. + +See [staging](#staging) for more details about such changes propagate between the branches. + +#### Changes acceptable for releases +[release-acceptable]: #changes-acceptable-for-releases + +Only changes to supported releases may be accepted. +The oldest supported release (`YYMM`) can be found using +``` +nix-instantiate --eval -A lib.trivial.oldestSupportedRelease +``` + +The release branches should generally not receive any breaking changes, both for the Nix expressions and derivations. +So these changes are acceptable to backport: +- New packages, modules and functions +- Security fixes +- Package version updates + - Patch versions with fixes + - Minor versions with new functionality, but no breaking changes + +In addition, major package version updates with breaking changes are also acceptable for: +- Services that would fail without up-to-date client software, such as `spotify`, `steam`, and `discord` +- Security critical applications, such as `firefox` and `chromium` + +#### Changes causing mass rebuilds +[mass-rebuilds]: #changes-causing-mass-rebuilds + +Which changes cause mass rebuilds is not formally defined. +In order to help the decision, CI automatically assigns [`rebuild` labels](https://github.com/NixOS/nixpkgs/labels?q=rebuild) to pull requests based on the number of packages they cause rebuilds for. +As a rule of thumb, if the number of rebuilds is **over 500**, it can be considered a mass rebuild. +To get a sense for what changes are considered mass rebuilds, see [previously merged pull requests to the staging branches](https://github.com/NixOS/nixpkgs/issues?q=base%3Astaging+-base%3Astaging-next+is%3Amerged). + ### Rebasing between branches (i.e. from master to staging) From time to time, changes between branches must be rebased, for example, if the @@ -197,29 +245,7 @@ So e.g. the [`nixpkgs-unstable` branch](https://github.com/nixos/nixpkgs/tree/ni Nixpkgs in its entirety is tied to the NixOS release process, which is documented in the [NixOS Release Wiki](https://nixos.github.io/release-wiki/). -Changes should generally always go to the `master` branch. -Once in `master`, it can be backported to the `release-YY.MM` branches if [acceptable](#acceptable-backport-criteria). -A change should only go to the `release-YY.MM` branch directly if `master` doesn't need that change. - -#### Acceptable backport criteria - -Backports are only accepted to supported releases. -The oldest supported release (`YYMM`) can be found using -``` -nix-instantiate --eval -A lib.trivial.oldestSupportedRelease -``` - -The release branches should generally not receive any breaking changes, both for the Nix expressions and derivations. -So these changes are acceptable to backport: -- New packages, modules and functions -- Security fixes -- Package version updates - - Patch versions with fixes - - Minor versions with new functionality, but no breaking changes - -In addition, major package version updates with breaking changes are also acceptable for: -- Services that would fail without up-to-date client software, such as `spotify`, `steam`, and `discord` -- Security critical applications, such as `firefox` and `chromium` +See [this section][branch] to know when to use the release branches. #### Backporting changes @@ -340,13 +366,6 @@ The staging workflow is used for all main branches, `master` and `release-YY.MM` - `staging`/`staging-YY.MM` - `staging-next`/`staging-next-YY.MM` -#### Mass rebuilds - -Which changes cause mass rebuilds is not formally defined. -In order to help the decision, CI automatically assigns [`rebuild` labels](https://github.com/NixOS/nixpkgs/labels?q=rebuild) to pull requests based on the number of packages they cause rebuilds for. -As a rule of thumb, if the number of rebuilds is **over 500**, it can be considered a mass rebuild. -To get a sense for what changes are considered mass rebuilds, see [previously merged pull requests to the staging branches](https://github.com/NixOS/nixpkgs/issues?q=base%3Astaging+-base%3Astaging-next+is%3Amerged). - ## Reviewing contributions > **Warning** From 16651342ea5cfe8a2cb1700865ed5e60ddae3603 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 02:46:50 +0200 Subject: [PATCH 32/42] CONTRIBUTING.md: Minor fixes --- CONTRIBUTING.md | 64 +++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9876d4d9e6b5..7e4ae122f518 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,11 +28,13 @@ This section describes in some detail how changes can be made and proposed with 1. [Clone the forked repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#cloning-your-forked-repository) into a local `nixpkgs` directory. 1. [Configure the upstream Nixpkgs repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#configuring-git-to-sync-your-fork-with-the-upstream-repository). -1. Create and switch to a new Git branch, ideally such that: +1. Figure out the branch that should be used for this change by going through [this section][branch]. + If in doubt use `master`, that's where most changes should go. + This can be changed later by [rebasing][rebasing]. + +2. Create and switch to a new Git branch, ideally such that: - The name of the branch hints at the change you'd like to implement, e.g. `update-hello`. - - The base of the branch includes the most recent changes on the `master` branch. - > **Note** - > Depending on the change you may want to use a different branch, see [][branch]. + - The base of the branch includes the most recent changes on the base branch from step 1, we'll assume `master` here. ```bash # Make sure you have the latest changes from upstream Nixpkgs @@ -52,7 +54,7 @@ This section describes in some detail how changes can be made and proposed with git switch --create update-hello ``` -2. Make the desired changes in the local Nixpkgs repository using an editor of your choice. +3. Make the desired changes in the local Nixpkgs repository using an editor of your choice. Make sure to: - Adhere to both the [general code conventions](#code-conventions), and the code conventions specific to the part you're making changes to. See the [overview section](#overview) for more specific information. @@ -61,13 +63,13 @@ This section describes in some detail how changes can be made and proposed with - If necessary, document the change. See the [overview section](#overview) for more specific information. -3. Commit your changes using `git commit`. +4. Commit your changes using `git commit`. Make sure to adhere to the [commit conventions](#commit-conventions). - Repeat the steps 2 and 3 as many times as necessary. + Repeat the steps 3-4 as many times as necessary. Advance to the next step if all the commits (viewable with `git log`) make sense together. -4. Push your commits to your fork of Nixpkgs. +5. Push your commits to your fork of Nixpkgs. ``` git push --set-upstream origin HEAD ``` @@ -78,33 +80,32 @@ This section describes in some detail how changes can be made and proposed with remote: https://github.com/myUser/nixpkgs/pull/new/update-hello ``` -5. [Create a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request#creating-the-pull-request) from the new branch in your Nixpkgs fork to the upstream Nixpkgs repository. - Generally you should use `master` as the pull requests base branch. - See for when a different branch should be used instead. - Make sure to go through the [pull request template](#pull-request-template) in the pre-filled default description. +6. [Create a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request#creating-the-pull-request) from the new branch in your Nixpkgs fork to the upstream Nixpkgs repository. + Use the branch from step 2 as the pull requests base branch, you can change this later by [rebasing][rebasing] if necessary. + Go through the [pull request template](#pull-request-template) in the pre-filled default description. -6. Respond to review comments, potential CI failures and potential merge conflicts by updating the pull request. +7. Respond to review comments, potential CI failures and potential merge conflicts by updating the pull request. Always keep the pull request in a mergeable state. - To add new commits, repeat steps 2-3 and push the result using - ``` - git push - ``` + - To add new commits, repeat steps 3-4 and push the result using + ``` + git push + ``` - To change existing commits you will have to [rewrite Git history](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). - Useful Git commands that can help a lot with this are `git commit --patch --amend` and `git rebase --interactive`. - With a rewritten history you need to force-push the commits using - ``` - git push --force-with-lease - ``` + - To change existing commits you will have to [rewrite Git history](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). + Useful Git commands that can help a lot with this are `git commit --patch --amend` and `git rebase --interactive`. + With a rewritten history you need to force-push the commits using + ``` + git push --force-with-lease + ``` - In case of merge conflicts you will also have to [rebase the branch](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) on top of current `master`. - Sometimes this can be done [on GitHub directly](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/keeping-your-pull-request-in-sync-with-the-base-branch#updating-your-pull-request-branch), but if not you will have to rebase locally using - ``` - git fetch upstream - git rebase upstream/master - git push --force-with-lease - ``` + - In case of merge conflicts you will also have to [rebase the branch](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) on top of current `master`. + Sometimes this can be done [on GitHub directly](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/keeping-your-pull-request-in-sync-with-the-base-branch#updating-your-pull-request-branch), but if not you will have to rebase locally using + ``` + git fetch upstream + git rebase upstream/master + git push --force-with-lease + ``` ### Which branch to use [branch]: #which-branch-to-use @@ -155,6 +156,7 @@ As a rule of thumb, if the number of rebuilds is **over 500**, it can be conside To get a sense for what changes are considered mass rebuilds, see [previously merged pull requests to the staging branches](https://github.com/NixOS/nixpkgs/issues?q=base%3Astaging+-base%3Astaging-next+is%3Amerged). ### Rebasing between branches (i.e. from master to staging) +[rebasing]: #rebasing-between-branches-ie-from-master-to-staging From time to time, changes between branches must be rebased, for example, if the number of new rebuilds they would cause is too large for the target branch. When @@ -270,7 +272,7 @@ To manually create a backport pull request, follow [the standard pull request pr - Instead of making manually making and committing the changes, use [`git cherry-pick -x`](https://git-scm.com/docs/git-cherry-pick) for each commit from the pull request you'd like to backport. Either `git cherry-pick -x ` when the reason for the backport is obvious (such as minor versions, fixes, etc.), otherwise use `git cherry-pickx -xe ` to add a reason for the backport to the commit message. - Here is [an example](5688c39af5a6c5f3d646343443683da880eaefb8) of this. + Here is [an example](https://github.com/nixos/nixpkgs/commit/5688c39af5a6c5f3d646343443683da880eaefb8) of this. > **Warning** > Ensure the commits exists on the master branch. From b069d2dfec737e0d22b8daa52bc2d6aac3e910ae Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 03:35:03 +0200 Subject: [PATCH 33/42] CONTRIBUTING.md: Move sections around Yeah I'm totally getting lazy with the commits, but it's really hard and takes a long time.. --- CONTRIBUTING.md | 434 +++++++++++++++++++++++++----------------------- 1 file changed, 224 insertions(+), 210 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e4ae122f518..933fb0e2efe2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,6 +8,7 @@ Additionally this document assumes that you already know how to use GitHub and G If that's not the case, we recommend learning about it first [here](https://docs.github.com/en/get-started/quickstart/hello-world). ## Overview +[overview]: #overview This file contains general contributing information, but individual parts also have more specific information to them in their respective `README.md` files, linked here: - [`lib`](./lib/README.md): Sources and documentation of the [library functions](https://nixos.org/manual/nixpkgs/stable/#chap-functions) @@ -16,7 +17,10 @@ This file contains general contributing information, but individual parts also h - [`doc`](./doc/README.md): Sources and infrastructure for the [Nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/) - [`nixos`](./nixos/README.md): Implementation of [NixOS](https://nixos.org/manual/nixos/stable/) -## How to propose a change +# How to's + +## How to create pull requests +[pr-create]: #how-to-create-pull-requests This section describes in some detail how changes can be made and proposed with pull requests. @@ -30,7 +34,7 @@ This section describes in some detail how changes can be made and proposed with 1. Figure out the branch that should be used for this change by going through [this section][branch]. If in doubt use `master`, that's where most changes should go. - This can be changed later by [rebasing][rebasing]. + This can be changed later by [rebasing][rebase]. 2. Create and switch to a new Git branch, ideally such that: - The name of the branch hints at the change you'd like to implement, e.g. `update-hello`. @@ -56,12 +60,12 @@ This section describes in some detail how changes can be made and proposed with 3. Make the desired changes in the local Nixpkgs repository using an editor of your choice. Make sure to: - - Adhere to both the [general code conventions](#code-conventions), and the code conventions specific to the part you're making changes to. - See the [overview section](#overview) for more specific information. + - Adhere to both the [general code conventions][code-conventions], and the code conventions specific to the part you're making changes to. + See the [overview section][overview] for more specific information. - Test the changes. - See the [overview section](#overview) for more specific information. + See the [overview section][overview] for more specific information. - If necessary, document the change. - See the [overview section](#overview) for more specific information. + See the [overview section][overview] for more specific information. 4. Commit your changes using `git commit`. Make sure to adhere to the [commit conventions](#commit-conventions). @@ -81,7 +85,7 @@ This section describes in some detail how changes can be made and proposed with ``` 6. [Create a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request#creating-the-pull-request) from the new branch in your Nixpkgs fork to the upstream Nixpkgs repository. - Use the branch from step 2 as the pull requests base branch, you can change this later by [rebasing][rebasing] if necessary. + Use the branch from step 2 as the pull requests base branch. Go through the [pull request template](#pull-request-template) in the pre-filled default description. 7. Respond to review comments, potential CI failures and potential merge conflicts by updating the pull request. @@ -107,56 +111,83 @@ This section describes in some detail how changes can be made and proposed with git push --force-with-lease ``` -### Which branch to use -[branch]: #which-branch-to-use + - If you need to change the base branch of the pull request, you can do so by [rebasing][rebase]. -Most changes should go to the `master` branch, but sometimes other branches should be used instead. -Use the following decision process to figure out which one it should be: +8. If your pull request is merged and [acceptable for releases][release-acceptable] you may [backport][pr-backport] the pull request. -Is the change [acceptable for releases][release-acceptable] and do you wish to have the change in the release? -- No: Use the `master` branch, do not backport the pull request. -- Yes: Can the change be implemented the same way on the `master` and release branches? - For example, a packages major version might differ between the `master` and release branches, such that separate security patches are required. - - Yes: Use the `master` branch and [backport the pull request](#backporting-changes). - - No: Create separate pull requests to the `master` and `release-XX.YY` branches. +### Pull request template +[pr-template]: #pull-request-template -Furthermore, if the change causes a [mass rebuild][mass-rebuilds], use the appropriate staging branch instead: -- Mass rebuilds to `master` should go to `staging` instead. -- Mass rebuilds to `release-XX.YY` should go to `staging-XX.YY` instead. +The pull request template helps determine what steps have been made for a contribution so far, and will help guide maintainers on the status of a change. The motivation section of the PR should include any extra details the title does not address and link any existing issues related to the pull request. -See [staging](#staging) for more details about such changes propagate between the branches. +When a PR is created, it will be pre-populated with some checkboxes detailed below: -#### Changes acceptable for releases -[release-acceptable]: #changes-acceptable-for-releases +#### Tested using sandboxing -Only changes to supported releases may be accepted. -The oldest supported release (`YYMM`) can be found using -``` -nix-instantiate --eval -A lib.trivial.oldestSupportedRelease +When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of `fetch*` functions and files outside the Nix store. Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [sandbox](https://nixos.org/nix/manual/#conf-sandbox) in Nix manual for details. + +Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for [nixpkgs](https://github.com/NixOS/nixpkgs/) people are asked to test builds with sandboxing enabled (see `Tested using sandboxing` in the pull request template) because in [Hydra](https://nixos.org/hydra/) sandboxing is also used. + +Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing **before** building the package: + +- **Globally enable sandboxing on NixOS**: add the following to `configuration.nix` + + ```nix + nix.useSandbox = true; + ``` + +- **Globally enable sandboxing on non-NixOS platforms**: add the following to: `/etc/nix/nix.conf` + + ```ini + sandbox = true + ``` + +#### Built on platform(s) + +Many Nix packages are designed to run on multiple platforms. As such, it’s important to let the maintainer know which platforms your changes have been tested on. It’s not always practical to test a change on all platforms, and is not required for a pull request to be merged. Only check the systems you tested the build on in this section. + +#### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) + +Packages with automated tests are much more likely to be merged in a timely fashion because it doesn’t require as much manual testing by the maintainer to verify the functionality of the package. If there are existing tests for the package, they should be run to verify your changes do not break the tests. Tests can only be run on Linux. For more details on writing and running tests, see the [section in the NixOS manual](https://nixos.org/nixos/manual/index.html#sec-nixos-tests). + +#### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` + +If you are updating a package’s version, you can use `nixpkgs-review` to make sure all packages that depend on the updated package still compile correctly. The `nixpkgs-review` utility can look for and build all dependencies either based on uncommitted changes with the `wip` option or specifying a GitHub pull request number. + +Review changes from pull request number 12345: + +```ShellSession +nix-shell -p nixpkgs-review --run "nixpkgs-review pr 12345" ``` -The release branches should generally not receive any breaking changes, both for the Nix expressions and derivations. -So these changes are acceptable to backport: -- New packages, modules and functions -- Security fixes -- Package version updates - - Patch versions with fixes - - Minor versions with new functionality, but no breaking changes +Alternatively, with flakes (and analogously for the other commands below): -In addition, major package version updates with breaking changes are also acceptable for: -- Services that would fail without up-to-date client software, such as `spotify`, `steam`, and `discord` -- Security critical applications, such as `firefox` and `chromium` +```ShellSession +nix run nixpkgs#nixpkgs-review -- pr 12345 +``` -#### Changes causing mass rebuilds -[mass-rebuilds]: #changes-causing-mass-rebuilds +Review uncommitted changes: -Which changes cause mass rebuilds is not formally defined. -In order to help the decision, CI automatically assigns [`rebuild` labels](https://github.com/NixOS/nixpkgs/labels?q=rebuild) to pull requests based on the number of packages they cause rebuilds for. -As a rule of thumb, if the number of rebuilds is **over 500**, it can be considered a mass rebuild. -To get a sense for what changes are considered mass rebuilds, see [previously merged pull requests to the staging branches](https://github.com/NixOS/nixpkgs/issues?q=base%3Astaging+-base%3Astaging-next+is%3Amerged). +```ShellSession +nix-shell -p nixpkgs-review --run "nixpkgs-review wip" +``` + +Review changes from last commit: + +```ShellSession +nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD" +``` + +#### Tested execution of all binary files (usually in `./result/bin/`) + +It’s important to test any executables generated by a build when you change or create a package in nixpkgs. This can be done by looking in `./result/bin` and running any files in there, or at a minimum, the main executable for the package. For example, if you make a change to texlive, you probably would only check the binaries associated with the change you made rather than testing all of them. + +#### Meets Nixpkgs contribution standards + +The last checkbox is fits the guidelines in this `CONTRIBUTING.md` file. The contributing document has detailed information on standards the Nix community has for commit messages, reviews, licensing of contributions you make to the project, etc... Everyone should read and understand the standards the community has for contributing before submitting a pull request. ### Rebasing between branches (i.e. from master to staging) -[rebasing]: #rebasing-between-branches-ie-from-master-to-staging +[rebase]: #rebasing-between-branches-ie-from-master-to-staging From time to time, changes between branches must be rebased, for example, if the number of new rebuilds they would cause is too large for the target branch. When @@ -230,30 +261,12 @@ for review, which allows you to sidestep this issue. This is not a bulletproof method though, as OfBorg still does review requests even on draft PRs. ``` -## Flow of changes - -After a Nixpkgs pull requests is merged, it eventually makes it to the [official Hydra CI](https://hydra.nixos.org/). -Hydra regularly evaluates and builds Nixpkgs, updating [the official channels](http://channels.nixos.org/) when specific Hydra jobs succeeded. -See [Nix Channel Status](https://status.nixos.org/) for the current channels and their state. -Here's a brief overview of the main Git branches and what channels they're used for: - -- `master`: The main branch, used for the unstable channels such as `nixpkgs-unstable`, `nixos-unstable` and `nixos-unstable-small`. -- `release-YY.MM` (e.g. `release-23.05`): The NixOS release branches, used for the stable channels such as `nixos-23.05`, `nixos-23.05-small` and `nixpkgs-23.05-darwin`. - -When a channel is updated, a corresponding Git branch is also updated to point to the corresponding commit. -So e.g. the [`nixpkgs-unstable` branch](https://github.com/nixos/nixpkgs/tree/nixpkgs-unstable) corresponds to the Git commit from the [`nixpkgs-unstable` channel](https://channels.nixos.org/nixpkgs-unstable). - -### Releases - -Nixpkgs in its entirety is tied to the NixOS release process, which is documented in the [NixOS Release Wiki](https://nixos.github.io/release-wiki/). - -See [this section][branch] to know when to use the release branches. - -#### Backporting changes +## How to backport pull requests +[pr-backport]: #how-to-backport-pull-requests Once a pull request has been merged into `master`, a backport pull request to the corresponding `release-YY.MM` branch can be created either automatically or manually. -##### Automatically backporting changes +### Automatically backporting changes > **Note** > You have to be a [Nixpkgs maintainer](./maintainers) to automatically create a backport pull request. @@ -262,16 +275,16 @@ Add the [`backport release-YY.MM` label](https://github.com/NixOS/nixpkgs/labels This will cause [a GitHub Action](.github/workflows/backport.yml) to open a pull request to the `release-YY.MM` branch a few minutes later. This can be done on both open or already merged pull requests. -##### Manually backporting changes +### Manually backporting changes -To manually create a backport pull request, follow [the standard pull request process](#how-to-propose-a-change), with these notable differences: +To manually create a backport pull request, follow [the standard pull request process][pr-create], with these notable differences: - Use `release-YY.MM` for the base branch, both for the local branch and the pull request. > **Warning** > Do not use the `nixos-YY.MM` branch, that is a branch pointing to the tested release channel commit - Instead of making manually making and committing the changes, use [`git cherry-pick -x`](https://git-scm.com/docs/git-cherry-pick) for each commit from the pull request you'd like to backport. - Either `git cherry-pick -x ` when the reason for the backport is obvious (such as minor versions, fixes, etc.), otherwise use `git cherry-pickx -xe ` to add a reason for the backport to the commit message. + Either `git cherry-pick -x ` when the reason for the backport is obvious (such as minor versions, fixes, etc.), otherwise use `git cherry-pick -xe ` to add a reason for the backport to the commit message. Here is [an example](https://github.com/nixos/nixpkgs/commit/5688c39af5a6c5f3d646343443683da880eaefb8) of this. > **Warning** @@ -284,11 +297,77 @@ To manually create a backport pull request, follow [the standard pull request pr - When the backport pull request is merged and you have the necessary privileges you can also replace the label `9.needs: port to stable` with `8.has: port to stable` on the original pull request. This way maintainers can keep track of missing backports easier. -### Staging +## How to review pull requests +[pr-review]: #how-to-review-pull-requests + +> **Warning** +> The following section is a draft, and the policy for reviewing is still being discussed in issues such as [#11166](https://github.com/NixOS/nixpkgs/issues/11166) and [#20836](https://github.com/NixOS/nixpkgs/issues/20836). + +The Nixpkgs project receives a fairly high number of contributions via GitHub pull requests. Reviewing and approving these is an important task and a way to contribute to the project. + +The high change rate of Nixpkgs makes any pull request that remains open for too long subject to conflicts that will require extra work from the submitter or the merger. Reviewing pull requests in a timely manner and being responsive to the comments is the key to avoid this issue. GitHub provides sort filters that can be used to see the [most recently](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc) and the [least recently](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-asc) updated pull requests. We highly encourage looking at [this list of ready to merge, unreviewed pull requests](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+review%3Anone+status%3Asuccess+-label%3A%222.status%3A+work-in-progress%22+no%3Aproject+no%3Aassignee+no%3Amilestone). + +When reviewing a pull request, please always be nice and polite. Controversial changes can lead to controversial opinions, but it is important to respect every community member and their work. + +GitHub provides reactions as a simple and quick way to provide feedback to pull requests or any comments. The thumb-down reaction should be used with care and if possible accompanied with some explanation so the submitter has directions to improve their contribution. + +Pull request reviews should include a list of what has been reviewed in a comment, so other reviewers and mergers can know the state of the review. + +All the review template samples provided in this section are generic and meant as examples. Their usage is optional and the reviewer is free to adapt them to their liking. + +To get more information about how to review specific parts of Nixpkgs, refer to the documents linked to in the [overview section][overview]. + +If you consider having enough knowledge and experience in a topic and would like to be a long-term reviewer for related submissions, please contact the current reviewers for that topic. They will give you information about the reviewing process. The main reviewers for a topic can be hard to find as there is no list, but checking past pull requests to see who reviewed or git-blaming the code to see who committed to that topic can give some hints. + +Container system, boot system and library changes are some examples of the pull requests fitting this category. + +## How to merge pull requests +[pr-merge]: #how-to-merge-pull-requests + +The *Nixpkgs committers* are people who have been given +permission to merge. + +It is possible for community members that have enough knowledge and experience on a special topic to contribute by merging pull requests. + +In case the PR is stuck waiting for the original author to apply a trivial +change (a typo, capitalisation change, etc.) and the author allowed the members +to modify the PR, consider applying it yourself. (or commit the existing review +suggestion) You should pay extra attention to make sure the addition doesn't go +against the idea of the original PR and would not be opposed by the author. + + + +Please see the discussion in [GitHub nixpkgs issue #50105](https://github.com/NixOS/nixpkgs/issues/50105) for information on how to proceed to be granted this level of access. + +In a case a contributor definitively leaves the Nix community, they should create an issue or post on [Discourse](https://discourse.nixos.org) with references of packages and modules they maintain so the maintainership can be taken over by other contributors. + +# Flow of merged pull requests + +After a pull requests is merged, it eventually makes it to the [official Hydra CI](https://hydra.nixos.org/). +Hydra regularly evaluates and builds Nixpkgs, updating [the official channels](http://channels.nixos.org/) when specific Hydra jobs succeeded. +See [Nix Channel Status](https://status.nixos.org/) for the current channels and their state. +Here's a brief overview of the main Git branches and what channels they're used for: + +- `master`: The main branch, used for the unstable channels such as `nixpkgs-unstable`, `nixos-unstable` and `nixos-unstable-small`. +- `release-YY.MM` (e.g. `release-23.05`): The NixOS release branches, used for the stable channels such as `nixos-23.05`, `nixos-23.05-small` and `nixpkgs-23.05-darwin`. + +When a channel is updated, a corresponding Git branch is also updated to point to the corresponding commit. +So e.g. the [`nixpkgs-unstable` branch](https://github.com/nixos/nixpkgs/tree/nixpkgs-unstable) corresponds to the Git commit from the [`nixpkgs-unstable` channel](https://channels.nixos.org/nixpkgs-unstable). + +Nixpkgs in its entirety is tied to the NixOS release process, which is documented in the [NixOS Release Wiki](https://nixos.github.io/release-wiki/). + +See [this section][branch] to know when to use the release branches. + +## Staging +[staging]: #staging The staging workflow exists to batch Hydra builds of many packages together. -It works by directing commits that cause [mass rebuilds](#mass-rebuilds) to a separate `staging` branch that isn't directly built by Hydra. +It works by directing commits that cause [mass rebuilds][mass-rebuild] to a separate `staging` branch that isn't directly built by Hydra. Regularly, the `staging` branch is _manually_ merged into a `staging-next` branch to be built by Hydra using the [`nixpkgs:staging-next` jobset](https://hydra.nixos.org/jobset/nixpkgs/staging-next). The `staging-next` branch should then only receive direct commits in order to fix Hydra builds. Once it is verified that there are no major regressions, it is merged into `master` using [a pull requests](https://github.com/NixOS/nixpkgs/pulls?q=head%3Astaging-next). @@ -358,7 +437,7 @@ Here's an overview of the different branches: | --- | --- | --- | --- | | Used for development | :heavy_check_mark: | :heavy_check_mark: | :x: | | Built by Hydra | :heavy_check_mark: | :x: | :heavy_check_mark: | -| [Mass rebuilds](#mass-rebuilds) | :x: | :heavy_check_mark: | :warning: Only to fix Hydra builds | +| [Mass rebuilds][mass-rebuild] | :x: | :heavy_check_mark: | :warning: Only to fix Hydra builds | | Critical security fixes | :heavy_check_mark: for non-mass-rebuilds | :x: | :heavy_check_mark: for mass-rebuilds | | Automatically merged into | `staging-next` | - | `staging` | | Manually merged into | - | `staging-next` | `master` | @@ -368,54 +447,101 @@ The staging workflow is used for all main branches, `master` and `release-YY.MM` - `staging`/`staging-YY.MM` - `staging-next`/`staging-next-YY.MM` -## Reviewing contributions +# Conventions -> **Warning** -> The following section is a draft, and the policy for reviewing is still being discussed in issues such as [#11166](https://github.com/NixOS/nixpkgs/issues/11166) and [#20836](https://github.com/NixOS/nixpkgs/issues/20836). +## Branch conventions + +[branch]: #branch-conventions -The Nixpkgs project receives a fairly high number of contributions via GitHub pull requests. Reviewing and approving these is an important task and a way to contribute to the project. +Most changes should go to the `master` branch, but sometimes other branches should be used instead. +Use the following decision process to figure out which one it should be: -The high change rate of Nixpkgs makes any pull request that remains open for too long subject to conflicts that will require extra work from the submitter or the merger. Reviewing pull requests in a timely manner and being responsive to the comments is the key to avoid this issue. GitHub provides sort filters that can be used to see the [most recently](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc) and the [least recently](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-asc) updated pull requests. We highly encourage looking at [this list of ready to merge, unreviewed pull requests](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+review%3Anone+status%3Asuccess+-label%3A%222.status%3A+work-in-progress%22+no%3Aproject+no%3Aassignee+no%3Amilestone). +Is the change [acceptable for releases][release-acceptable] and do you wish to have the change in the release? +- No: Use the `master` branch, do not backport the pull request. +- Yes: Can the change be implemented the same way on the `master` and release branches? + For example, a packages major version might differ between the `master` and release branches, such that separate security patches are required. + - Yes: Use the `master` branch and [backport the pull request](#backporting-changes). + - No: Create separate pull requests to the `master` and `release-XX.YY` branches. -When reviewing a pull request, please always be nice and polite. Controversial changes can lead to controversial opinions, but it is important to respect every community member and their work. +Furthermore, if the change causes a [mass rebuild][mass-rebuild], use the appropriate staging branch instead: +- Mass rebuilds to `master` should go to `staging` instead. +- Mass rebuilds to `release-XX.YY` should go to `staging-XX.YY` instead. -GitHub provides reactions as a simple and quick way to provide feedback to pull requests or any comments. The thumb-down reaction should be used with care and if possible accompanied with some explanation so the submitter has directions to improve their contribution. +See [this section][staging] for more details about such changes propagate between the branches. -Pull request reviews should include a list of what has been reviewed in a comment, so other reviewers and mergers can know the state of the review. +### Changes acceptable for releases +[release-acceptable]: #changes-acceptable-for-releases -All the review template samples provided in this section are generic and meant as examples. Their usage is optional and the reviewer is free to adapt them to their liking. +Only changes to supported releases may be accepted. +The oldest supported release (`YYMM`) can be found using +``` +nix-instantiate --eval -A lib.trivial.oldestSupportedRelease +``` -To get more information about how to review specific parts of Nixpkgs, refer to the documents linked to in the [overview section](#overview). +The release branches should generally not receive any breaking changes, both for the Nix expressions and derivations. +So these changes are acceptable to backport: +- New packages, modules and functions +- Security fixes +- Package version updates + - Patch versions with fixes + - Minor versions with new functionality, but no breaking changes -If you consider having enough knowledge and experience in a topic and would like to be a long-term reviewer for related submissions, please contact the current reviewers for that topic. They will give you information about the reviewing process. The main reviewers for a topic can be hard to find as there is no list, but checking past pull requests to see who reviewed or git-blaming the code to see who committed to that topic can give some hints. +In addition, major package version updates with breaking changes are also acceptable for: +- Services that would fail without up-to-date client software, such as `spotify`, `steam`, and `discord` +- Security critical applications, such as `firefox` and `chromium` -Container system, boot system and library changes are some examples of the pull requests fitting this category. +### Changes causing mass rebuilds +[mass-rebuild]: #changes-causing-mass-rebuilds -## Merging pull requests +Which changes cause mass rebuilds is not formally defined. +In order to help the decision, CI automatically assigns [`rebuild` labels](https://github.com/NixOS/nixpkgs/labels?q=rebuild) to pull requests based on the number of packages they cause rebuilds for. +As a rule of thumb, if the number of rebuilds is **over 500**, it can be considered a mass rebuild. +To get a sense for what changes are considered mass rebuilds, see [previously merged pull requests to the staging branches](https://github.com/NixOS/nixpkgs/issues?q=base%3Astaging+-base%3Astaging-next+is%3Amerged). -The *Nixpkgs committers* are people who have been given -permission to merge. +## Commit conventions +[commit-conventions]: #commit-conventions -It is possible for community members that have enough knowledge and experience on a special topic to contribute by merging pull requests. +- When changing the bootloader installation process, extra care must be taken. Grub installations cannot be rolled back, hence changes may break people’s installations forever. For any non-trivial change to the bootloader please file a PR asking for review, especially from \@edolstra. -In case the PR is stuck waiting for the original author to apply a trivial -change (a typo, capitalisation change, etc.) and the author allowed the members -to modify the PR, consider applying it yourself. (or commit the existing review -suggestion) You should pay extra attention to make sure the addition doesn't go -against the idea of the original PR and would not be opposed by the author. +- Create a commit for each logical unit. - +- If you have commits `pkg-name: oh, forgot to insert whitespace`: squash commits in this case. Use `git rebase -i`. -Please see the discussion in [GitHub nixpkgs issue #50105](https://github.com/NixOS/nixpkgs/issues/50105) for information on how to proceed to be granted this level of access. +- Format the commit messages in the following way: -In a case a contributor definitively leaves the Nix community, they should create an issue or post on [Discourse](https://discourse.nixos.org) with references of packages and modules they maintain so the maintainership can be taken over by other contributors. + ``` + (pkg-name | nixos/): (from -> to | init at version | refactor | etc) + (Motivation for change. Link to release notes. Additional information.) + ``` + + For consistency, there should not be a period at the end of the commit message's summary line (the first line of the commit message). + + Examples: + + * nginx: init at 2.0.1 + * firefox: 54.0.1 -> 55.0 + + https://www.mozilla.org/en-US/firefox/55.0/releasenotes/ + * nixos/hydra: add bazBaz option + + Dual baz behavior is needed to do foo. + * nixos/nginx: refactor config generation + + The old config generation system used impure shell scripts and could break in specific circumstances (see #1234). + +### Writing good commit messages + +In addition to writing properly formatted commit messages, it's important to include relevant information so other developers can later understand *why* a change was made. While this information usually can be found by digging code, mailing list/Discourse archives, pull request discussions or upstream changes, it may require a lot of work. + +Package version upgrades usually allow for simpler commit messages, including attribute name, old and new version, as well as a reference to the relevant release notes/changelog. Every once in a while a package upgrade requires more extensive changes, and that subsequently warrants a more verbose message. + +Pull requests should not be squash merged in order to keep complete commit messages and GPG signatures intact and must not be when the change doesn't make sense as a single commit. ## Code conventions +[code-conventions]: #code-conventions ### Release notes @@ -622,115 +748,3 @@ Names of files and directories should be in lowercase, with dashes between words If this is done a follow up pull request _should_ be created to change the code to `lib.optional(s)`. - Arguments should be listed in the order they are used, with the exception of `lib`, which always goes first. - -## Commit conventions - - -- When changing the bootloader installation process, extra care must be taken. Grub installations cannot be rolled back, hence changes may break people’s installations forever. For any non-trivial change to the bootloader please file a PR asking for review, especially from \@edolstra. - -- Create a commit for each logical unit. - -- Check for unnecessary whitespace with `git diff --check` before committing. - -- If you have commits `pkg-name: oh, forgot to insert whitespace`: squash commits in this case. Use `git rebase -i`. - -- Format the commit messages in the following way: - - ``` - (pkg-name | nixos/): (from -> to | init at version | refactor | etc) - - (Motivation for change. Link to release notes. Additional information.) - ``` - - For consistency, there should not be a period at the end of the commit message's summary line (the first line of the commit message). - - Examples: - - * nginx: init at 2.0.1 - * firefox: 54.0.1 -> 55.0 - - https://www.mozilla.org/en-US/firefox/55.0/releasenotes/ - * nixos/hydra: add bazBaz option - - Dual baz behavior is needed to do foo. - * nixos/nginx: refactor config generation - - The old config generation system used impure shell scripts and could break in specific circumstances (see #1234). - -### Writing good commit messages - -In addition to writing properly formatted commit messages, it's important to include relevant information so other developers can later understand *why* a change was made. While this information usually can be found by digging code, mailing list/Discourse archives, pull request discussions or upstream changes, it may require a lot of work. - -Package version upgrades usually allow for simpler commit messages, including attribute name, old and new version, as well as a reference to the relevant release notes/changelog. Every once in a while a package upgrade requires more extensive changes, and that subsequently warrants a more verbose message. - -Pull requests should not be squash merged in order to keep complete commit messages and GPG signatures intact and must not be when the change doesn't make sense as a single commit. - -## Pull Request Template - -The pull request template helps determine what steps have been made for a contribution so far, and will help guide maintainers on the status of a change. The motivation section of the PR should include any extra details the title does not address and link any existing issues related to the pull request. - -When a PR is created, it will be pre-populated with some checkboxes detailed below: - -### Tested using sandboxing - -When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of `fetch*` functions and files outside the Nix store. Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [sandbox](https://nixos.org/nix/manual/#conf-sandbox) in Nix manual for details. - -Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for [nixpkgs](https://github.com/NixOS/nixpkgs/) people are asked to test builds with sandboxing enabled (see `Tested using sandboxing` in the pull request template) because in [Hydra](https://nixos.org/hydra/) sandboxing is also used. - -Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing **before** building the package: - -- **Globally enable sandboxing on NixOS**: add the following to `configuration.nix` - - ```nix - nix.useSandbox = true; - ``` - -- **Globally enable sandboxing on non-NixOS platforms**: add the following to: `/etc/nix/nix.conf` - - ```ini - sandbox = true - ``` - -### Built on platform(s) - -Many Nix packages are designed to run on multiple platforms. As such, it’s important to let the maintainer know which platforms your changes have been tested on. It’s not always practical to test a change on all platforms, and is not required for a pull request to be merged. Only check the systems you tested the build on in this section. - -### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) - -Packages with automated tests are much more likely to be merged in a timely fashion because it doesn’t require as much manual testing by the maintainer to verify the functionality of the package. If there are existing tests for the package, they should be run to verify your changes do not break the tests. Tests can only be run on Linux. For more details on writing and running tests, see the [section in the NixOS manual](https://nixos.org/nixos/manual/index.html#sec-nixos-tests). - -### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` - -If you are updating a package’s version, you can use `nixpkgs-review` to make sure all packages that depend on the updated package still compile correctly. The `nixpkgs-review` utility can look for and build all dependencies either based on uncommitted changes with the `wip` option or specifying a GitHub pull request number. - -Review changes from pull request number 12345: - -```ShellSession -nix-shell -p nixpkgs-review --run "nixpkgs-review pr 12345" -``` - -Alternatively, with flakes (and analogously for the other commands below): - -```ShellSession -nix run nixpkgs#nixpkgs-review -- pr 12345 -``` - -Review uncommitted changes: - -```ShellSession -nix-shell -p nixpkgs-review --run "nixpkgs-review wip" -``` - -Review changes from last commit: - -```ShellSession -nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD" -``` - -### Tested execution of all binary files (usually in `./result/bin/`) - -It’s important to test any executables generated by a build when you change or create a package in nixpkgs. This can be done by looking in `./result/bin` and running any files in there, or at a minimum, the main executable for the package. For example, if you make a change to texlive, you probably would only check the binaries associated with the change you made rather than testing all of them. - -### Meets Nixpkgs contribution standards - -The last checkbox is fits the guidelines in this `CONTRIBUTING.md` file. The contributing document has detailed information on standards the Nix community has for commit messages, reviews, licensing of contributions you make to the project, etc... Everyone should read and understand the standards the community has for contributing before submitting a pull request. From e6307807a8c84243b3bb2468660d5422a250b261 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 04:27:12 +0200 Subject: [PATCH 34/42] pkgs/README.md: Minor header and link fixes --- pkgs/README.md | 123 +++++++++++++++++++++++++------------------------ 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/pkgs/README.md b/pkgs/README.md index 055c8e76a5c4..2f8ad026484a 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -13,15 +13,15 @@ See the [CONTRIBUTING.md](../CONTRIBUTING.md) document for more general informat - `release*.nix`, [`make-tarball.nix`](./top-level/make-tarball.nix), [`packages-config.nix`](./top-level/packages-config.nix), [`metrics.nix`](./top-level/metrics.nix), [`nixpkgs-basic-release-checks.nix`](./top-level/nixpkgs-basic-release-checks.nix): Entry-points and utilities used by Hydra for continuous integration - [`development`](./development) - `*-modules`, `*-packages`, `*-pkgs`: Package definitions for nested package sets - - All other directories loosely categorise top-level package definitions, see [category hierarchy](#category-hierarchy) + - All other directories loosely categorise top-level package definitions, see [category hierarchy][categories] - [`build-support`](./build-support): [Builders](https://nixos.org/manual/nixpkgs/stable/#part-builders) - `fetch*`: [Fetchers](https://nixos.org/manual/nixpkgs/stable/#chap-pkgs-fetchers) - [`stdenv`](./stdenv): [Standard environment](https://nixos.org/manual/nixpkgs/stable/#part-stdenv) - [`pkgs-lib`](./pkgs-lib): Definitions for utilities that need packages but are not needed for packages - [`test`](./test): Tests not directly associated with any specific packages -- All other directories loosely categorise top-level packages definitions, see [category hierarchy](#category-hierarchy) +- All other directories loosely categorise top-level packages definitions, see [category hierarchy][categories] -## Quick Start to Adding a Package {#chap-quick-start} +## Quick Start to Adding a Package To add a package to Nixpkgs: @@ -32,7 +32,7 @@ To add a package to Nixpkgs: $ cd nixpkgs ``` -2. Find a good place in the Nixpkgs tree to add the Nix expression for your package. For instance, a library package typically goes into `pkgs/development/libraries/pkgname`, while a web browser goes into `pkgs/applications/networking/browsers/pkgname`. See [](#sec-organisation) for some hints on the tree organisation. Create a directory for your package, e.g. +2. Find a good place in the Nixpkgs tree to add the Nix expression for your package. For instance, a library package typically goes into `pkgs/development/libraries/pkgname`, while a web browser goes into `pkgs/applications/networking/browsers/pkgname`. See the [category hierarchy section][categories] for some hints on the tree organisation. Create a directory for your package, e.g. ```ShellSession $ mkdir pkgs/development/libraries/libfoo @@ -47,35 +47,35 @@ To add a package to Nixpkgs: You can have a look at the existing Nix expressions under `pkgs/` to see how it’s done. Here are some good ones: - - GNU Hello: [`pkgs/applications/misc/hello/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/hello/default.nix). Trivial package, which specifies some `meta` attributes which is good practice. + - GNU Hello: [`pkgs/applications/misc/hello/default.nix`](applications/misc/hello/default.nix). Trivial package, which specifies some `meta` attributes which is good practice. - - GNU cpio: [`pkgs/tools/archivers/cpio/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/archivers/cpio/default.nix). Also a simple package. The generic builder in `stdenv` does everything for you. It has no dependencies beyond `stdenv`. + - GNU cpio: [`pkgs/tools/archivers/cpio/default.nix`](tools/archivers/cpio/default.nix). Also a simple package. The generic builder in `stdenv` does everything for you. It has no dependencies beyond `stdenv`. - - GNU Multiple Precision arithmetic library (GMP): [`pkgs/development/libraries/gmp/5.1.x.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/gmp/5.1.x.nix). Also done by the generic builder, but has a dependency on `m4`. + - GNU Multiple Precision arithmetic library (GMP): [`pkgs/development/libraries/gmp/5.1.x.nix`](development/libraries/gmp/5.1.x.nix). Also done by the generic builder, but has a dependency on `m4`. - - Pan, a GTK-based newsreader: [`pkgs/applications/networking/newsreaders/pan/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix). Has an optional dependency on `gtkspell`, which is only built if `spellCheck` is `true`. + - Pan, a GTK-based newsreader: [`pkgs/applications/networking/newsreaders/pan/default.nix`](applications/networking/newsreaders/pan/default.nix). Has an optional dependency on `gtkspell`, which is only built if `spellCheck` is `true`. - - Apache HTTPD: [`pkgs/servers/http/apache-httpd/2.4.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/http/apache-httpd/2.4.nix). A bunch of optional features, variable substitutions in the configure flags, a post-install hook, and miscellaneous hackery. + - Apache HTTPD: [`pkgs/servers/http/apache-httpd/2.4.nix`](servers/http/apache-httpd/2.4.nix). A bunch of optional features, variable substitutions in the configure flags, a post-install hook, and miscellaneous hackery. - - buildMozillaMach: [`pkgs/applications/networking/browser/firefox/common.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/browsers/firefox/common.nix). A reusable build function for Firefox, Thunderbird and Librewolf. + - buildMozillaMach: [`pkgs/applications/networking/browser/firefox/common.nix`](applications/networking/browsers/firefox/common.nix). A reusable build function for Firefox, Thunderbird and Librewolf. - - JDiskReport, a Java utility: [`pkgs/tools/misc/jdiskreport/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/jdiskreport/default.nix). Nixpkgs doesn’t have a decent `stdenv` for Java yet so this is pretty ad-hoc. + - JDiskReport, a Java utility: [`pkgs/tools/misc/jdiskreport/default.nix`](tools/misc/jdiskreport/default.nix). Nixpkgs doesn’t have a decent `stdenv` for Java yet so this is pretty ad-hoc. - - XML::Simple, a Perl module: [`pkgs/top-level/perl-packages.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/perl-packages.nix) (search for the `XMLSimple` attribute). Most Perl modules are so simple to build that they are defined directly in `perl-packages.nix`; no need to make a separate file for them. + - XML::Simple, a Perl module: [`pkgs/top-level/perl-packages.nix`](top-level/perl-packages.nix) (search for the `XMLSimple` attribute). Most Perl modules are so simple to build that they are defined directly in `perl-packages.nix`; no need to make a separate file for them. - - Adobe Reader: [`pkgs/applications/misc/adobe-reader/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/default.nix). Shows how binary-only packages can be supported. In particular the [builder](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/builder.sh) uses `patchelf` to set the RUNPATH and ELF interpreter of the executables so that the right libraries are found at runtime. + - Adobe Reader: [`pkgs/applications/misc/adobe-reader/default.nix`](applications/misc/adobe-reader/default.nix). Shows how binary-only packages can be supported. In particular the [builder](applications/misc/adobe-reader/builder.sh) uses `patchelf` to set the RUNPATH and ELF interpreter of the executables so that the right libraries are found at runtime. Some notes: - - All [`meta`](#chap-meta) attributes are optional, but it’s still a good idea to provide at least the `description`, `homepage` and [`license`](#sec-meta-license). + - All [`meta`](https://nixos.org/manual/nixpkgs/stable/#chap-meta) attributes are optional, but it’s still a good idea to provide at least the `description`, `homepage` and [`license`](https://nixos.org/manual/nixpkgs/stable/#sec-meta-license). - You can use `nix-prefetch-url url` to get the SHA-256 hash of source distributions. There are similar commands as `nix-prefetch-git` and `nix-prefetch-hg` available in `nix-prefetch-scripts` package. - - A list of schemes for `mirror://` URLs can be found in [`pkgs/build-support/fetchurl/mirrors.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/fetchurl/mirrors.nix). + - A list of schemes for `mirror://` URLs can be found in [`pkgs/build-support/fetchurl/mirrors.nix`](build-support/fetchurl/mirrors.nix). - The exact syntax and semantics of the Nix expression language, including the built-in function, are described in the Nix manual in the [chapter on writing Nix expressions](https://hydra.nixos.org/job/nix/trunk/tarball/latest/download-by-type/doc/manual/#chap-writing-nix-expressions). + The exact syntax and semantics of the Nix expression language, including the built-in function, are [described in the Nix manual](https://nixos.org/manual/nix/stable/language/). -4. Add a call to the function defined in the previous step to [`pkgs/top-level/all-packages.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix) with some descriptive name for the variable, e.g. `libfoo`. +4. Add a call to the function defined in the previous step to [`pkgs/top-level/all-packages.nix`](top-level/all-packages.nix) with some descriptive name for the variable, e.g. `libfoo`. ```ShellSession $ emacs pkgs/top-level/all-packages.nix @@ -100,6 +100,7 @@ To add a package to Nixpkgs: 7. Optionally commit the new package and open a pull request [to nixpkgs](https://github.com/NixOS/nixpkgs/pulls), or use [the Patches category](https://discourse.nixos.org/t/about-the-patches-category/477) on Discourse for sending a patch without a GitHub account. ## Category Hierarchy +[categories]: #category-hierarchy Each package should be stored in its own directory somewhere in the `pkgs/` tree, i.e. in `pkgs/category/subcategory/.../pkgname`. Below are some rules for picking the right category for a package. Many packages fall under several categories; what matters is the _primary_ purpose of a package. For example, the `libxml2` package builds both a library and some tools; but it’s a library foremost, so it goes under `pkgs/development/libraries`. @@ -279,9 +280,9 @@ A (typically large) program with a distinct user interface, primarily used inter - `misc` -## (Conventions) +# Conventions -### Package naming {#sec-package-naming} +## Package naming The key words _must_, _must not_, _required_, _shall_, _shall not_, _should_, _should not_, _recommended_, _may_, and _optional_ in this section are to be interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119). Only _emphasized_ words are to be interpreted in this way. @@ -309,9 +310,10 @@ Example: Given a project had its latest releases `2.2` in November 2021, and `3. - Dashes in the package `pname` _should_ be preserved in new variable names, rather than converted to underscores or camel cased — e.g., `http-parser` instead of `http_parser` or `httpParser`. The hyphenated style is preferred in all three package names. -- If there are multiple versions of a package, this _should_ be reflected in the variable names in `all-packages.nix`, e.g. `json-c_0_9` and `json-c_0_11`. If there is an obvious “default” version, make an attribute like `json-c = json-c_0_9;`. See also [](#sec-versioning) +- If there are multiple versions of a package, this _should_ be reflected in the variable names in `all-packages.nix`, e.g. `json-c_0_9` and `json-c_0_11`. If there is an obvious “default” version, make an attribute like `json-c = json-c_0_9;`. See also [versioning][versioning]. -### Versioning {#sec-versioning} +## Versioning +[versioning]: #versioning Because every version of a package in Nixpkgs creates a potential maintenance burden, old versions of a package should not be kept unless there is a good reason to do so. For instance, Nixpkgs contains several versions of GCC because other packages don’t build with the latest version of GCC. Other examples are having both the latest stable and latest pre-release version of a package, or to keep several major releases of an application that differ significantly in functionality. @@ -319,7 +321,7 @@ If there is only one version of a package, its Nix expression should be named `e All versions of a package _must_ be included in `all-packages.nix` to make sure that they evaluate correctly. -### (Meta attributes) +## Meta attributes * `meta.description` must: * Be short, just one sentence. @@ -336,7 +338,7 @@ All versions of a package _must_ be included in `all-packages.nix` to make sure See the nixpkgs manual for more details on [standard meta-attributes](https://nixos.org/nixpkgs/manual/#sec-standard-meta-attributes). -### Import From Derivation {#ssec-import-from-derivation} +### Import From Derivation Import From Derivation (IFD) is disallowed in Nixpkgs for performance reasons: [Hydra] evaluates the entire package set, and sequential builds during evaluation would increase evaluation times to become impractical. @@ -351,9 +353,9 @@ See also [NixOS Wiki: Import From Derivation]. [NixOS Wiki: Import From Derivation]: https://nixos.wiki/wiki/Import_From_Derivation -## (Sources) +## Sources -### Fetching Sources {#sec-sources} +### Fetching Sources There are multiple ways to fetch a package source in nixpkgs. The general guideline is that you should package reproducible sources with a high degree of availability. Right now there is only one fetcher which has mirroring support and that is `fetchurl`. Note that you should also prefer protocols which have a corresponding proxy environment variable. @@ -398,7 +400,7 @@ It is a practical vector for a denial-of-service attack by pushing large amounts Find the value to put as `hash` by running `nix-shell -p nix-prefetch-github --run "nix-prefetch-github --rev 1f795f9f44607cc5bec70d1300150bfefcef2aae NixOS nix"`. -#### Obtaining source hash {#sec-source-hashes} +#### Obtaining source hash Preferred source hash type is sha256. There are several ways to get it. @@ -429,16 +431,15 @@ Preferred source hash type is sha256. There are several ways to get it. in the package expression, attempt build and extract correct hash from error messages. - ::: {.warning} - You must use one of these four fake hashes and not some arbitrarily-chosen hash. + > **Warning** + > You must use one of these four fake hashes and not some arbitrarily-chosen hash. + > See [here][secure-hashes] - See [](#sec-source-hashes-security). - ::: - - This is last resort method when reconstructing source URL is non-trivial and `nix-prefetch-url -A` isn’t applicable (for example, [one of `kodi` dependencies](https://github.com/NixOS/nixpkgs/blob/d2ab091dd308b99e4912b805a5eb088dd536adb9/pkgs/applications/video/kodi/default.nix#L73)). The easiest way then would be replace hash with a fake one and rebuild. Nix build will fail and error message will contain desired hash. + This is last resort method when reconstructing source URL is non-trivial and `nix-prefetch-url -A` isn’t applicable (for example, [one of `kodi` dependencies](https://github.com/NixOS/nixpkgs/blob/d2ab091dd308b99e4912b805a5eb088dd536adb9/pkgs/applications/video/kodi/default.nix#L73)). The easiest way then would be replace hash with a fake one and rebuild. Nix build will fail and error message will contain desired hash. -#### Obtaining hashes securely {#sec-source-hashes-security} +#### Obtaining hashes securely +[secure-hashes]: #obtaining-hashes-securely Let's say Man-in-the-Middle (MITM) sits close to your network. Then instead of fetching source you can fetch malware, and instead of source hash you get hash of malware. Here are security considerations for this scenario: @@ -450,7 +451,7 @@ Let's say Man-in-the-Middle (MITM) sits close to your network. Then instead of f - `https://` URLs are secure in method 5 *only if* you use one of the listed fake hashes. If you use any other hash, `fetchurl` will pass `--insecure` to `curl` and may then degrade to HTTP in case of TLS certificate expiration. -### Patches {#sec-patches} +### Patches Patches available online should be retrieved using `fetchpatch`. @@ -466,7 +467,7 @@ patches = [ Otherwise, you can add a `.patch` file to the `nixpkgs` repository. In the interest of keeping our maintenance burden to a minimum, only patches that are unique to `nixpkgs` should be added in this way. -If a patch is available online but does not cleanly apply, it can be modified in some fixed ways by using additional optional arguments for `fetchpatch`. Check [](#fetchpatch) for details. +If a patch is available online but does not cleanly apply, it can be modified in some fixed ways by using additional optional arguments for `fetchpatch`. Check [the `fetchpatch` reference](https://nixos.org/manual/nixpkgs/unstable/#fetchpatch) for details. ```nix patches = [ ./0001-changes.patch ]; @@ -495,13 +496,13 @@ If you do need to do create this sort of patch file, one way to do so is with gi $ git diff -a > nixpkgs/pkgs/the/package/0001-changes.patch ``` -## Deprecating/removing packages {#submitting-changes-deprecating-packages} +## Deprecating/removing packages There is currently no policy when to remove a package. Before removing a package, one should try to find a new maintainer or fix smaller issues first. -### Steps to remove a package from Nixpkgs {#steps-to-remove-a-package-from-nixpkgs} +### Steps to remove a package from Nixpkgs We use jbidwatcher as an example for a discontinued project here. @@ -542,7 +543,7 @@ We use jbidwatcher as an example for a discontinued project here. This is how the pull request looks like in this case: [https://github.com/NixOS/nixpkgs/pull/116470](https://github.com/NixOS/nixpkgs/pull/116470) -## Testing changes | Package tests {#sec-package-tests} +## Package tests - update pkg - `nix-env -iA pkg-attribute-name -f ` @@ -570,7 +571,7 @@ The following types of tests exists: Here in the nixpkgs manual we describe mostly _package tests_; for _module tests_ head over to the corresponding [section in the NixOS manual](https://nixos.org/manual/nixos/stable/#sec-nixos-tests). -### Writing inline package tests {#ssec-inline-package-tests-writing} +### Writing inline package tests For very simple tests, they can be written inline: @@ -589,7 +590,8 @@ buildGoModule rec { } ``` -### Writing larger package tests {#ssec-package-tests-writing} +### Writing larger package tests +[larger-package-tests]: #writing-larger-package-tests This is an example using the `phoronix-test-suite` package with the current best practices. @@ -634,7 +636,7 @@ runCommand "${pname}-tests" { meta.timeout = 60; } '' ``` -### Running package tests {#ssec-package-tests-running} +### Running package tests You can run these tests with: @@ -643,19 +645,19 @@ $ cd path/to/nixpkgs $ nix-build -A phoronix-test-suite.tests ``` -### Examples of package tests {#ssec-package-tests-examples} +### Examples of package tests Here are examples of package tests: -- [Jasmin compile test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/jasmin/test-assemble-hello-world/default.nix) -- [Lobster compile test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/lobster/test-can-run-hello-world.nix) -- [Spacy annotation test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/spacy/annotation-test/default.nix) -- [Libtorch test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/science/math/libtorch/test/default.nix) -- [Multiple tests for nanopb](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/nanopb/default.nix) +- [Jasmin compile test](development/compilers/jasmin/test-assemble-hello-world/default.nix) +- [Lobster compile test](development/compilers/lobster/test-can-run-hello-world.nix) +- [Spacy annotation test](development/python-modules/spacy/annotation-test/default.nix) +- [Libtorch test](development/libraries/science/math/libtorch/test/default.nix) +- [Multiple tests for nanopb](development/libraries/nanopb/default.nix) -### Linking NixOS module tests to a package {#ssec-nixos-tests-linking} +### Linking NixOS module tests to a package -Like [package tests](#ssec-package-tests-writing) as shown above, [NixOS module tests](https://nixos.org/manual/nixos/stable/#sec-nixos-tests) can also be linked to a package, so that the tests can be easily run when changing the related package. +Like [package tests][larger-package-tests] as shown above, [NixOS module tests](https://nixos.org/manual/nixos/stable/#sec-nixos-tests) can also be linked to a package, so that the tests can be easily run when changing the related package. For example, assuming we're packaging `nginx`, we can link its module test via `passthru.tests`: @@ -673,9 +675,9 @@ stdenv.mkDerivation { } ``` -## (Reviewing contributions) +## Reviewing contributions -### Package updates {#reviewing-contributions-package-updates} +### Package updates A package update is the most trivial and common type of pull request. These pull requests mainly consist of updating the version part of the package name and the source hash. @@ -729,7 +731,7 @@ Sample template for a package update review is provided below. ##### Comments ``` -### New packages {#reviewing-contributions-new-packages} +### New packages New packages are a common type of pull requests. These pull requests consists in adding a new nix-expression for a package. @@ -774,9 +776,10 @@ Sample template for a new package review is provided below. ##### Comments ``` -## (Security) +## Security -### Submitting security fixes {#submitting-changes-submitting-security-fixes} +### Submitting security fixes +[security-fixes]: #submitting-security-fixes Security fixes are submitted in the same way as other changes and thus the same guidelines apply. @@ -796,9 +799,9 @@ If a security fix applies to both master and a stable release then, similar to r Critical security fixes may by-pass the staging branches and be delivered directly to release branches such as `master` and `release-*`. -### Vulnerability Roundup {#chap-vulnerability-roundup} +### Vulnerability Roundup -#### Issues {#vulnerability-roundup-issues} +#### Issues Vulnerable packages in Nixpkgs are managed using issues. Currently opened ones can be found using the following: @@ -827,7 +830,7 @@ A "Vulnerability roundup" issue usually respects the following format: Note that there can be an extra comment containing links to previously reported (and still open) issues for the same package. -#### Triaging and Fixing {#vulnerability-roundup-triaging-and-fixing} +#### Triaging and Fixing **Note**: An issue can be a "false positive" (i.e. automatically opened, but without the package it refers to being actually vulnerable). If you find such a "false positive", comment on the issue an explanation of why it falls into this category, linking as much information as the necessary to help maintainers double check. @@ -837,7 +840,7 @@ If you are investigating a "true positive": - Find the earliest patched version or a code patch in the CVE details; - Is the issue already patched (version up-to-date or patch applied manually) in Nixpkgs's `master` branch? - **No**: - - [Submit a security fix](#submitting-changes-submitting-security-fixes); - - Once the fix is merged into `master`, [submit the change to the vulnerable release branch(es)](https://nixos.org/manual/nixpkgs/stable/#submitting-changes-stable-release-branches); - - **Yes**: [Backport the change to the vulnerable release branch(es)](https://nixos.org/manual/nixpkgs/stable/#submitting-changes-stable-release-branches). + - [Submit a security fix][security-fixes]; + - Once the fix is merged into `master`, [submit the change to the vulnerable release branch(es)](../CONTRIBUTING.md#how-to-backport-pull-requests); + - **Yes**: [Backport the change to the vulnerable release branch(es)](../CONTRIBUTING.md#how-to-backport-pull-requests). - When the patch has made it into all the relevant branches (`master`, and the vulnerable releases), close the relevant issue(s). From 553daaed7323126e9945679d666f8dee9961e378 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 04:36:45 +0200 Subject: [PATCH 35/42] doc/README.md: Cleanup --- doc/README.md | 126 +++++++++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 69 deletions(-) diff --git a/doc/README.md b/doc/README.md index 19b61233bc28..03df6ad61138 100644 --- a/doc/README.md +++ b/doc/README.md @@ -6,13 +6,9 @@ You can find the [rendered documentation for Nixpkgs `unstable` on nixos.org](ht [Docs for Nixpkgs stable](https://nixos.org/manual/nixpkgs/stable/) are also available. -If you want to contribute to the documentation, [here's how to do it](https://nixos.org/manual/nixpkgs/unstable/#chap-contributing). - If you're only getting started with Nix, go to [nixos.org/learn](https://nixos.org/learn). -## Contributing to this documentation {#chap-contributing} - -The sources of the Nixpkgs manual are in the [doc](https://github.com/NixOS/nixpkgs/tree/master/doc) subdirectory of the Nixpkgs repository. +## Contributing to this documentation You can quickly check your edits with `nix-build`: @@ -23,7 +19,7 @@ $ nix-build doc If the build succeeds, the manual will be in `./result/share/doc/nixpkgs/manual.html`. -### devmode {#sec-contributing-devmode} +### devmode The shell in the manual source directory makes available a command, `devmode`. It is a daemon, that: @@ -31,97 +27,89 @@ It is a daemon, that: 2. HTTP serves the manual, injecting a script that triggers reload on changes 3. opens the manual in the default browser -### Syntax {#sec-contributing-markup} +## Syntax As per [RFC 0072](https://github.com/NixOS/rfcs/pull/72), all new documentation content should be written in [CommonMark](https://commonmark.org/) Markdown dialect. Additional syntax extensions are available, all of which can be used in NixOS option documentation. The following extensions are currently used: -- []{#ssec-contributing-markup-tables} - Tables, using the [GitHub-flavored Markdown syntax](https://github.github.com/gfm/#tables-extension-). +#### Tables -- []{#ssec-contributing-markup-anchors} - Explicitly defined **anchors** on headings, to allow linking to sections. These should be always used, to ensure the anchors can be linked even when the heading text changes, and to prevent conflicts between [automatically assigned identifiers](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/auto_identifiers.md). +Tables, using the [GitHub-flavored Markdown syntax](https://github.github.com/gfm/#tables-extension-). - It uses the widely compatible [header attributes](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/attributes.md) syntax: +#### Anchors - ```markdown - ## Syntax {#sec-contributing-markup} - ``` +Explicitly defined **anchors** on headings, to allow linking to sections. These should be always used, to ensure the anchors can be linked even when the heading text changes, and to prevent conflicts between [automatically assigned identifiers](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/auto_identifiers.md). - ::: {.note} - NixOS option documentation does not support headings in general. - ::: +It uses the widely compatible [header attributes](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/attributes.md) syntax: -- []{#ssec-contributing-markup-anchors-inline} - **Inline anchors**, which allow linking arbitrary place in the text (e.g. individual list items, sentences…). +```markdown +## Syntax {#sec-contributing-markup} +``` - They are defined using a hybrid of the link syntax with the attributes syntax known from headings, called [bracketed spans](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/bracketed_spans.md): +> **Note** +> NixOS option documentation does not support headings in general. - ```markdown - - []{#ssec-gnome-hooks-glib} `glib` setup hook will populate `GSETTINGS_SCHEMAS_PATH` and then `wrapGAppsHook` will prepend it to `XDG_DATA_DIRS`. - ``` +#### Inline Anchors -- []{#ssec-contributing-markup-automatic-links} - If you **omit a link text** for a link pointing to a section, the text will be substituted automatically. For example, `[](#chap-contributing)` will result in [](#chap-contributing). +Allow linking arbitrary place in the text (e.g. individual list items, sentences…). - This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/using/syntax.html#targets-and-cross-referencing). +They are defined using a hybrid of the link syntax with the attributes syntax known from headings, called [bracketed spans](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/bracketed_spans.md): -- []{#ssec-contributing-markup-inline-roles} - If you want to link to a man page, you can use `` {manpage}`nix.conf(5)` ``, which will turn into {manpage}`nix.conf(5)`. The references will turn into links when a mapping exists in {file}`doc/manpage-urls.json`. +```markdown +- []{#ssec-gnome-hooks-glib} `glib` setup hook will populate `GSETTINGS_SCHEMAS_PATH` and then `wrapGAppsHook` will prepend it to `XDG_DATA_DIRS`. +``` - A few markups for other kinds of literals are also available: +#### Automatic links - - `` {command}`rm -rfi` `` turns into {command}`rm -rfi` - - `` {env}`XDG_DATA_DIRS` `` turns into {env}`XDG_DATA_DIRS` - - `` {file}`/etc/passwd` `` turns into {file}`/etc/passwd` - - `` {option}`networking.useDHCP` `` turns into {option}`networking.useDHCP` - - `` {var}`/etc/passwd` `` turns into {var}`/etc/passwd` +If you **omit a link text** for a link pointing to a section, the text will be substituted automatically. For example `[](#chap-contributing)`. - These literal kinds are used mostly in NixOS option documentation. +This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/using/syntax.html#targets-and-cross-referencing). - This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html#roles-an-in-line-extension-point). Though, the feature originates from [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-manpage) with slightly different syntax. +#### Roles -- []{#ssec-contributing-markup-admonitions} - **Admonitions**, set off from the text to bring attention to something. +If you want to link to a man page, you can use `` {manpage}`nix.conf(5)` ``. The references will turn into links when a mapping exists in [`doc/manpage-urls.json`](./manpage-urls.json). - It uses pandoc’s [fenced `div`s syntax](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md): +A few markups for other kinds of literals are also available: - ```markdown - ::: {.warning} - This is a warning - ::: - ``` +- `` {command}`rm -rfi` `` +- `` {env}`XDG_DATA_DIRS` `` +- `` {file}`/etc/passwd` `` +- `` {option}`networking.useDHCP` `` +- `` {var}`/etc/passwd` `` - which renders as +These literal kinds are used mostly in NixOS option documentation. - > ::: {.warning} - > This is a warning. - > ::: +This syntax is taken from [MyST](https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html#roles-an-in-line-extension-point). Though, the feature originates from [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-manpage) with slightly different syntax. - The following are supported: +#### Admonitions - - [`caution`](https://tdg.docbook.org/tdg/5.0/caution.html) - - [`important`](https://tdg.docbook.org/tdg/5.0/important.html) - - [`note`](https://tdg.docbook.org/tdg/5.0/note.html) - - [`tip`](https://tdg.docbook.org/tdg/5.0/tip.html) - - [`warning`](https://tdg.docbook.org/tdg/5.0/warning.html) +Set off from the text to bring attention to something. -- []{#ssec-contributing-markup-definition-lists} - [**Definition lists**](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/definition_lists.md), for defining a group of terms: +It uses pandoc’s [fenced `div`s syntax](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fenced_divs.md): - ```markdown - pear - : green or yellow bulbous fruit +```markdown +::: {.warning} +This is a warning +::: +``` - watermelon - : green fruit with red flesh - ``` +The following are supported: - which renders as +- [`caution`](https://tdg.docbook.org/tdg/5.0/caution.html) +- [`important`](https://tdg.docbook.org/tdg/5.0/important.html) +- [`note`](https://tdg.docbook.org/tdg/5.0/note.html) +- [`tip`](https://tdg.docbook.org/tdg/5.0/tip.html) +- [`warning`](https://tdg.docbook.org/tdg/5.0/warning.html) - > pear - > : green or yellow bulbous fruit - > - > watermelon - > : green fruit with red flesh +#### [Definition lists](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/definition_lists.md) + +For defining a group of terms: + +```markdown +pear +: green or yellow bulbous fruit + +watermelon +: green fruit with red flesh +``` From 15ca783f10e9558f922394f26fb36e508fce8111 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 04:49:15 +0200 Subject: [PATCH 36/42] nixos/README.md: GitHub markdown fixes --- nixos/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nixos/README.md b/nixos/README.md index 6e966e7a65d0..7f66a132fb94 100644 --- a/nixos/README.md +++ b/nixos/README.md @@ -8,9 +8,9 @@ https://nixos.org/nixos and in the manual in doc/manual. You can add new module to your NixOS configuration file (usually it’s `/etc/nixos/configuration.nix`). And do `sudo nixos-rebuild test -I nixpkgs= --fast`. -## (Reviewing contributions) +## Reviewing contributions -### Module updates {#reviewing-contributions-module-updates} +### Module updates Module updates are submissions changing modules in some ways. These often contains changes to the options or introduce new options. @@ -47,7 +47,7 @@ Sample template for a module update review is provided below. ##### Comments ``` -### New modules {#reviewing-contributions-new-modules} +### New modules New modules submissions introduce a new module to NixOS. From d5148f23330dce97d2edd14e1710d4ab4e3f59cb Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 04:49:38 +0200 Subject: [PATCH 37/42] maintainer/README.md: GitHub markdown fixes --- maintainers/README.md | 128 +++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/maintainers/README.md b/maintainers/README.md index 4b691277bde7..e12881851925 100644 --- a/maintainers/README.md +++ b/maintainers/README.md @@ -6,93 +6,93 @@ about a package to assign themselves as a maintainer. When a pull request is made against a package, OfBorg will notify the appropriate maintainer(s). -## (Reviewing contributions) +## Reviewing contributions -### Individual maintainer list {#reviewing-contributions-individual-maintainer-list} +### Individual maintainer list -When adding users to `maintainers/maintainer-list.nix`, the following +When adding users to [`maintainer-list.nix`](./maintainer-list.nix), the following checks should be performed: -- If the user has specified a GPG key, verify that the commit is - signed by their key. +- If the user has specified a GPG key, verify that the commit is + signed by their key. - First, validate that the commit adding the maintainer is signed by - the key the maintainer listed. Check out the pull request and - compare its signing key with the listed key in the commit. + First, validate that the commit adding the maintainer is signed by + the key the maintainer listed. Check out the pull request and + compare its signing key with the listed key in the commit. - If the commit is not signed or it is signed by a different user, ask - them to either recommit using that key or to remove their key - information. + If the commit is not signed or it is signed by a different user, ask + them to either recommit using that key or to remove their key + information. - Given a maintainer entry like this: + Given a maintainer entry like this: - ``` nix - { - example = { - email = "user@example.com"; - name = "Example User"; - keys = [{ - fingerprint = "0000 0000 2A70 6423 0AED 3C11 F04F 7A19 AAA6 3AFE"; - }]; - } - }; - ``` + ``` nix + { + example = { + email = "user@example.com"; + name = "Example User"; + keys = [{ + fingerprint = "0000 0000 2A70 6423 0AED 3C11 F04F 7A19 AAA6 3AFE"; + }]; + } + }; + ``` - First receive their key from a keyserver: + First receive their key from a keyserver: - $ gpg --recv-keys 0xF04F7A19AAA63AFE - gpg: key 0xF04F7A19AAA63AFE: public key "Example " imported - gpg: Total number processed: 1 - gpg: imported: 1 + $ gpg --recv-keys 0xF04F7A19AAA63AFE + gpg: key 0xF04F7A19AAA63AFE: public key "Example " imported + gpg: Total number processed: 1 + gpg: imported: 1 - Then check the commit is signed by that key: + Then check the commit is signed by that key: - $ git log --show-signature - commit b87862a4f7d32319b1de428adb6cdbdd3a960153 - gpg: Signature made Wed Mar 12 13:32:24 2003 +0000 - gpg: using RSA key 000000002A7064230AED3C11F04F7A19AAA63AFE - gpg: Good signature from "Example User - Author: Example User - Date: Wed Mar 12 13:32:24 2003 +0000 + $ git log --show-signature + commit b87862a4f7d32319b1de428adb6cdbdd3a960153 + gpg: Signature made Wed Mar 12 13:32:24 2003 +0000 + gpg: using RSA key 000000002A7064230AED3C11F04F7A19AAA63AFE + gpg: Good signature from "Example User + Author: Example User + Date: Wed Mar 12 13:32:24 2003 +0000 - maintainers: adding example + maintainers: adding example - and validate that there is a `Good signature` and the printed key - matches the user's submitted key. + and validate that there is a `Good signature` and the printed key + matches the user's submitted key. - Note: GitHub's "Verified" label does not display the user's full key - fingerprint, and should not be used for validating the key matches. + Note: GitHub's "Verified" label does not display the user's full key + fingerprint, and should not be used for validating the key matches. -- If the user has specified a `github` account name, ensure they have - also specified a `githubId` and verify the two match. +- If the user has specified a `github` account name, ensure they have + also specified a `githubId` and verify the two match. - Maintainer entries that include a `github` field must also include - their `githubId`. People can and do change their GitHub name - frequently, and the ID is used as the official and stable identity - of the maintainer. + Maintainer entries that include a `github` field must also include + their `githubId`. People can and do change their GitHub name + frequently, and the ID is used as the official and stable identity + of the maintainer. - Given a maintainer entry like this: + Given a maintainer entry like this: - ``` nix - { - example = { - email = "user@example.com"; - name = "Example User"; - github = "ghost"; - githubId = 10137; - } - }; - ``` + ``` nix + { + example = { + email = "user@example.com"; + name = "Example User"; + github = "ghost"; + githubId = 10137; + } + }; + ``` - First, make sure that the listed GitHub handle matches the author of - the commit. + First, make sure that the listed GitHub handle matches the author of + the commit. - Then, visit the URL `https://api.github.com/users/ghost` and - validate that the `id` field matches the provided `githubId`. + Then, visit the URL `https://api.github.com/users/ghost` and + validate that the `id` field matches the provided `githubId`. -### Maintainer teams {#reviewing-contributions-maintainer-teams} +### Maintainer teams -Feel free to create a new maintainer team in `maintainers/team-list.nix` +Feel free to create a new maintainer team in [`team-list.nix`](./team-list.nix) when a group is collectively responsible for a collection of packages. Use taste and personal judgement when deciding if a team is warranted. From aafc9aee385423a10d2ae56ddf8a807c37fbd5d1 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 04:51:20 +0200 Subject: [PATCH 38/42] pkgs/README.md: Remove some mediocre duplicated sentences Also mainly covered in the section below --- pkgs/README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pkgs/README.md b/pkgs/README.md index 2f8ad026484a..4e0cc83ff919 100644 --- a/pkgs/README.md +++ b/pkgs/README.md @@ -545,15 +545,6 @@ This is how the pull request looks like in this case: [https://github.com/NixOS/ ## Package tests -- update pkg - - `nix-env -iA pkg-attribute-name -f ` -- add pkg - - Make sure it’s in `pkgs/top-level/all-packages.nix` - - `nix-env -iA pkg-attribute-name -f ` -- _If you don’t want to install pkg in you profile_. - - `nix-build -A pkg-attribute-name ` and check results in the folder `result`. It will appear in the same directory where you did `nix-build`. -- If you installed your package with `nix-env`, you can run `nix-env -e pkg-name` where `pkg-name` is as reported by `nix-env -q` to uninstall it from your system. - To run the main types of tests locally: - Run package-internal tests with `nix-build --attr pkgs.PACKAGE.passthru.tests` From b0f61e3da26a3bda576852817f1f62fb6894f077 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 05:16:51 +0200 Subject: [PATCH 39/42] CODEOWNERS: Add myself to the newly added files --- .github/CODEOWNERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 45bc58a9def7..303c09abb20a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -63,6 +63,15 @@ /.github/PULL_REQUEST_TEMPLATE.md @infinisil /doc/contributing/ @fricklerhandwerk @infinisil /doc/contributing/contributing-to-documentation.chapter.md @jtojnar @fricklerhandwerk @infinisil +/lib/README.md @infinisil +/doc/README.md @infinisil +/nixos/README.md @infinisil +/pkgs/README.md @infinisil +/maintainers/README.md @infinisil + +# User-facing development documentation +/doc/development.md @infinisil +/doc/development @infinisil # NixOS Internals /nixos/default.nix @infinisil From 237799aa8ecb233e9a19e3d4f332cd1db04d1de0 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 18:23:52 +0200 Subject: [PATCH 40/42] CONTRIBUTING.md: Minor content updates based on reviews MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Contributing without a GitHub account - Mention OfBorg - nix.useSandbox -> nix.settings.sandbox - nixpkgs-review is good for not just version updates Co-authored-by: Rémi NICOLE --- CONTRIBUTING.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 933fb0e2efe2..48bab29c589e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,7 +3,9 @@ This document is for people wanting to contribute to the implementation of Nixpkgs. This involves interacting with implementation changes that are proposed using [GitHub](https://github.com/) [pull requests](https://docs.github.com/pull-requests) to the [Nixpkgs](https://github.com/nixos/nixpkgs/) repository (which you're in right now). -As such, a GitHub account is required, which you can sign up for [here](https://github.com/signup). +As such, a GitHub account is recommended, which you can sign up for [here](https://github.com/signup). +See [here](https://discourse.nixos.org/t/about-the-patches-category/477) for how to contribute without a GitHub account. + Additionally this document assumes that you already know how to use GitHub and Git. If that's not the case, we recommend learning about it first [here](https://docs.github.com/en/get-started/quickstart/hello-world). @@ -91,6 +93,9 @@ This section describes in some detail how changes can be made and proposed with 7. Respond to review comments, potential CI failures and potential merge conflicts by updating the pull request. Always keep the pull request in a mergeable state. + The custom [OfBorg](https://github.com/NixOS/ofborg) CI system will perform various checks to help ensure code quality, whose results you can see at the bottom of the pull request. + See [the OfBorg Readme](https://github.com/NixOS/ofborg#readme) for more details. + - To add new commits, repeat steps 3-4 and push the result using ``` git push @@ -133,7 +138,7 @@ Depending if you use NixOS or other platforms you can use one of the following m - **Globally enable sandboxing on NixOS**: add the following to `configuration.nix` ```nix - nix.useSandbox = true; + nix.settings.sandbox = true; ``` - **Globally enable sandboxing on non-NixOS platforms**: add the following to: `/etc/nix/nix.conf` @@ -152,7 +157,7 @@ Packages with automated tests are much more likely to be merged in a timely fash #### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` -If you are updating a package’s version, you can use `nixpkgs-review` to make sure all packages that depend on the updated package still compile correctly. The `nixpkgs-review` utility can look for and build all dependencies either based on uncommitted changes with the `wip` option or specifying a GitHub pull request number. +If you are modifying a package, you can use `nixpkgs-review` to make sure all packages that depend on the updated package still compile correctly. The `nixpkgs-review` utility can look for and build all dependencies either based on uncommitted changes with the `wip` option or specifying a GitHub pull request number. Review changes from pull request number 12345: From 2ce1e0b2cc287799138439d04dee78af425b5c01 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 14 Aug 2023 18:27:14 +0200 Subject: [PATCH 41/42] CONTRIBUTING.md: Typos and formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix sentence about meeting contributing standards - pkgs -> packages - Use emoji's because GitHub renders the :*: things weird sometimes - Move a dot Co-authored-by: Rémi NICOLE --- CONTRIBUTING.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 48bab29c589e..2154271a6412 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -189,7 +189,7 @@ It’s important to test any executables generated by a build when you change or #### Meets Nixpkgs contribution standards -The last checkbox is fits the guidelines in this `CONTRIBUTING.md` file. The contributing document has detailed information on standards the Nix community has for commit messages, reviews, licensing of contributions you make to the project, etc... Everyone should read and understand the standards the community has for contributing before submitting a pull request. +The last checkbox is about whether it fits the guidelines in this `CONTRIBUTING.md` file. This document has detailed information on standards the Nix community has for commit messages, reviews, licensing of contributions you make to the project, etc... Everyone should read and understand the standards the community has for contributing before submitting a pull request. ### Rebasing between branches (i.e. from master to staging) [rebase]: #rebasing-between-branches-ie-from-master-to-staging @@ -288,7 +288,7 @@ To manually create a backport pull request, follow [the standard pull request pr > **Warning** > Do not use the `nixos-YY.MM` branch, that is a branch pointing to the tested release channel commit -- Instead of making manually making and committing the changes, use [`git cherry-pick -x`](https://git-scm.com/docs/git-cherry-pick) for each commit from the pull request you'd like to backport. +- Instead of manually making and committing the changes, use [`git cherry-pick -x`](https://git-scm.com/docs/git-cherry-pick) for each commit from the pull request you'd like to backport. Either `git cherry-pick -x ` when the reason for the backport is obvious (such as minor versions, fixes, etc.), otherwise use `git cherry-pick -xe ` to add a reason for the backport to the commit message. Here is [an example](https://github.com/nixos/nixpkgs/commit/5688c39af5a6c5f3d646343443683da880eaefb8) of this. @@ -336,8 +336,8 @@ It is possible for community members that have enough knowledge and experience o In case the PR is stuck waiting for the original author to apply a trivial change (a typo, capitalisation change, etc.) and the author allowed the members -to modify the PR, consider applying it yourself. (or commit the existing review -suggestion) You should pay extra attention to make sure the addition doesn't go +to modify the PR, consider applying it yourself (or commit the existing review +suggestion). You should pay extra attention to make sure the addition doesn't go against the idea of the original PR and would not be opposed by the author.