lol
at 24.11-pre 755 lines 36 kB view raw view rendered
1# Contributing to Nixpkgs 2 3This document is for people wanting to contribute to the implementation of Nixpkgs. 4This 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). 5 6As such, a GitHub account is recommended, which you can sign up for [here](https://github.com/signup). 7See [here](https://discourse.nixos.org/t/about-the-patches-category/477) for how to contribute without a GitHub account. 8 9Additionally this document assumes that you already know how to use GitHub and Git. 10If that's not the case, we recommend learning about it first [here](https://docs.github.com/en/get-started/quickstart/hello-world). 11 12## Overview 13[overview]: #overview 14 15This file contains general contributing information, but individual parts also have more specific information to them in their respective `README.md` files, linked here: 16- [`lib`](./lib/README.md): Sources and documentation of the [library functions](https://nixos.org/manual/nixpkgs/stable/#chap-functions) 17- [`maintainers`](./maintainers/README.md): Nixpkgs maintainer and team listings, maintainer scripts 18- [`pkgs`](./pkgs/README.md): Package and [builder](https://nixos.org/manual/nixpkgs/stable/#part-builders) definitions 19- [`doc`](./doc/README.md): Sources and infrastructure for the [Nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/) 20- [`nixos`](./nixos/README.md): Implementation of [NixOS](https://nixos.org/manual/nixos/stable/) 21 22# How to's 23 24## How to create pull requests 25[pr-create]: #how-to-create-pull-requests 26 27This section describes in some detail how changes can be made and proposed with pull requests. 28 29> [!Note] 30> Be aware that contributing implies licensing those contributions under the terms of [COPYING](./COPYING), an MIT-like license. 31 320. Set up a local version of Nixpkgs to work with using GitHub and Git 33 1. [Fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository) the [Nixpkgs repository](https://github.com/nixos/nixpkgs/). 34 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. 35 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). 36 371. Figure out the branch that should be used for this change by going through [this section][branch]. 38 If in doubt use `master`, that's where most changes should go. 39 This can be changed later by [rebasing][rebase]. 40 412. Create and switch to a new Git branch, ideally such that: 42 - The name of the branch hints at the change you'd like to implement, e.g. `update-hello`. 43 - The base of the branch includes the most recent changes on the base branch from step 1, we'll assume `master` here. 44 45 ```bash 46 # Make sure you have the latest changes from upstream Nixpkgs 47 git fetch upstream 48 49 # Create and switch to a new branch based off the master branch in Nixpkgs 50 git switch --create update-hello upstream/master 51 ``` 52 53 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: 54 - The commit of the latest `nixpkgs-unstable` channel, available [here](https://channels.nixos.org/nixpkgs-unstable/git-revision). 55 - 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 <nixpkgs/lib>).trivial.revisionWithDefault null'` 56 - If you're using NixOS, the commit of your NixOS installation, available with `nixos-version --revision`. 57 58 Once you have an appropriate commit you can use it instead of `upstream/master` in the above command: 59 ```bash 60 git switch --create update-hello <the desired base commit> 61 ``` 62 633. Make the desired changes in the local Nixpkgs repository using an editor of your choice. 64 Make sure to: 65 - Adhere to both the [general code conventions][code-conventions], and the code conventions specific to the part you're making changes to. 66 See the [overview section][overview] for more specific information. 67 - Test the changes. 68 See the [overview section][overview] for more specific information. 69 - If necessary, document the change. 70 See the [overview section][overview] for more specific information. 71 724. Commit your changes using `git commit`. 73 Make sure to adhere to the [commit conventions](#commit-conventions). 74 75 Repeat the steps 3-4 as many times as necessary. 76 Advance to the next step if all the commits (viewable with `git log`) make sense together. 77 785. Push your commits to your fork of Nixpkgs. 79 ``` 80 git push --set-upstream origin HEAD 81 ``` 82 83 The above command will output a link that allows you to directly quickly do the next step: 84 ``` 85 remote: Create a pull request for 'update-hello' on GitHub by visiting: 86 remote: https://github.com/myUser/nixpkgs/pull/new/update-hello 87 ``` 88 896. [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. 90 Use the branch from step 2 as the pull requests base branch. 91 Go through the [pull request template](#pull-request-template) in the pre-filled default description. 92 937. Respond to review comments, potential CI failures and potential merge conflicts by updating the pull request. 94 Always keep the pull request in a mergeable state. 95 96 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. 97 See [the OfBorg Readme](https://github.com/NixOS/ofborg#readme) for more details. 98 99 - To add new commits, repeat steps 3-4 and push the result using 100 ``` 101 git push 102 ``` 103 104 - To change existing commits you will have to [rewrite Git history](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). 105 Useful Git commands that can help a lot with this are `git commit --patch --amend` and `git rebase --interactive`. 106 With a rewritten history you need to force-push the commits using 107 ``` 108 git push --force-with-lease 109 ``` 110 111 - 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`. 112 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 113 ``` 114 git fetch upstream 115 git rebase upstream/master 116 git push --force-with-lease 117 ``` 118 119 - If you need to change the base branch of the pull request, you can do so by [rebasing][rebase]. 120 1218. If your pull request is merged and [acceptable for releases][release-acceptable] you may [backport][pr-backport] the pull request. 122 123### Pull request template 124[pr-template]: #pull-request-template 125 126The 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. 127 128When a PR is created, it will be pre-populated with some checkboxes detailed below: 129 130#### Tested using sandboxing 131 132When sandbox builds are enabled, Nix will set up an isolated environment for each build process. 133It is used to remove further hidden dependencies set by the build environment to improve reproducibility. 134This includes access to the network during the build outside of `fetch*` functions and files outside the Nix store. 135Depending on the operating system, access to other resources is blocked as well (e.g., inter-process communication is isolated on Linux); see [sandbox](https://nixos.org/manual/nix/stable/command-ref/conf-file#conf-sandbox) in the Nix manual for details. 136 137In 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. 138 139If you are on Linux, sandboxing is enabled by default. 140On other platforms, sandboxing is disabled by default due to a small performance hit on each build. 141 142Please enable sandboxing **before** building the package by adding the following to: `/etc/nix/nix.conf`: 143 144 ```ini 145 sandbox = true 146 ``` 147 148#### Built on platform(s) 149 150Many 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. 151 152#### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) 153 154Packages 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). 155 156#### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` 157 158If 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. 159 160Review changes from pull request number 12345: 161 162```ShellSession 163nix-shell -p nixpkgs-review --run "nixpkgs-review pr 12345" 164``` 165 166Alternatively, with flakes (and analogously for the other commands below): 167 168```ShellSession 169nix run nixpkgs#nixpkgs-review -- pr 12345 170``` 171 172Review uncommitted changes: 173 174```ShellSession 175nix-shell -p nixpkgs-review --run "nixpkgs-review wip" 176``` 177 178Review changes from last commit: 179 180```ShellSession 181nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD" 182``` 183 184#### Tested execution of all binary files (usually in `./result/bin/`) 185 186It’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. 187 188#### Meets Nixpkgs contribution standards 189 190The 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. 191 192### Rebasing between branches (i.e. from master to staging) 193[rebase]: #rebasing-between-branches-ie-from-master-to-staging 194 195From time to time, changes between branches must be rebased, for example, if the 196number of new rebuilds they would cause is too large for the target branch. When 197rebasing, care must be taken to include only the intended changes, otherwise 198many CODEOWNERS will be inadvertently requested for review. To achieve this, 199rebasing should not be performed directly on the target branch, but on the merge 200base between the current and target branch. As an additional precautionary measure, 201you should temporarily mark the PR as draft for the duration of the operation. 202This reduces the probability of mass-pinging people. (OfBorg might still 203request a couple of persons for reviews though.) 204 205In the following example, we assume that the current branch, called `feature`, 206is based on `master`, and we rebase it onto the merge base between 207`master` and `staging` so that the PR can eventually be retargeted to 208`staging` without causing a mess. The example uses `upstream` as the remote for `NixOS/nixpkgs.git` 209while `origin` is the remote you are pushing to. 210 211 212```console 213# Rebase your commits onto the common merge base 214git rebase --onto upstream/staging... upstream/master 215# Force push your changes 216git push origin feature --force-with-lease 217``` 218 219The syntax `upstream/staging...` is equivalent to `upstream/staging...HEAD` and 220stands for the merge base between `upstream/staging` and `HEAD` (hence between 221`upstream/staging` and `upstream/master`). 222 223Then change the base branch in the GitHub PR using the *Edit* button in the upper 224right corner, and switch from `master` to `staging`. *After* the PR has been 225retargeted it might be necessary to do a final rebase onto the target branch, to 226resolve any outstanding merge conflicts. 227 228```console 229# Rebase onto target branch 230git rebase upstream/staging 231# Review and fixup possible conflicts 232git status 233# Force push your changes 234git push origin feature --force-with-lease 235``` 236 237#### Something went wrong and a lot of people were pinged 238 239It happens. Remember to be kind, especially to new contributors. 240There is no way back, so the pull request should be closed and locked 241(if possible). The changes should be re-submitted in a new PR, in which the people 242originally involved in the conversation need to manually be pinged again. 243No further discussion should happen on the original PR, as a lot of people 244are now subscribed to it. 245 246The following message (or a version thereof) might be left when closing to 247describe the situation, since closing and locking without any explanation 248is kind of rude: 249 250```markdown 251It looks like you accidentally mass-pinged a bunch of people, which are now subscribed 252and getting notifications for everything in this pull request. Unfortunately, they 253cannot be automatically unsubscribed from the issue (removing review request does not 254unsubscribe), therefore development cannot continue in this pull request anymore. 255 256Please open a new pull request with your changes, link back to this one and ping the 257people actually involved in here over there. 258 259In order to avoid this in the future, there are instructions for how to properly 260rebase between branches in our [contribution guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#rebasing-between-branches-ie-from-master-to-staging). 261Setting your pull request to draft prior to rebasing is strongly recommended. 262In draft status, you can preview the list of people that are about to be requested 263for review, which allows you to sidestep this issue. 264This is not a bulletproof method though, as OfBorg still does review requests even on draft PRs. 265``` 266 267## How to backport pull requests 268[pr-backport]: #how-to-backport-pull-requests 269 270Once 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. 271 272### Automatically backporting changes 273 274> [!Note] 275> You have to be a [Nixpkgs maintainer](./maintainers) to automatically create a backport pull request. 276 277Add the [`backport release-YY.MM` label](https://github.com/NixOS/nixpkgs/labels?q=backport) to the pull request on the `master` branch. 278This will cause [a GitHub Action](.github/workflows/backport.yml) to open a pull request to the `release-YY.MM` branch a few minutes later. 279This can be done on both open or already merged pull requests. 280 281### Manually backporting changes 282 283To manually create a backport pull request, follow [the standard pull request process][pr-create], with these notable differences: 284 285- Use `release-YY.MM` for the base branch, both for the local branch and the pull request. 286 287> [!Warning] 288> Do not use the `nixos-YY.MM` branch, that is a branch pointing to the tested release channel commit 289 290- 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. 291 Either `git cherry-pick -x <commit>` when the reason for the backport is obvious (such as minor versions, fixes, etc.), otherwise use `git cherry-pick -xe <commit>` to add a reason for the backport to the commit message. 292 Here is [an example](https://github.com/nixos/nixpkgs/commit/5688c39af5a6c5f3d646343443683da880eaefb8) of this. 293 294> [!Warning] 295> Ensure the commits exists on the master branch. 296> 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. 297 298- In the pull request description, link to the original pull request to `master`. 299 The pull request title should include `[YY.MM]` matching the release you're backporting to. 300 301- 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. 302 This way maintainers can keep track of missing backports easier. 303 304## How to review pull requests 305[pr-review]: #how-to-review-pull-requests 306 307> [!Warning] 308> 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). 309 310The 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. 311 312The 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). 313 314When 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. 315 316GitHub 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. 317 318Pull 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. 319 320All 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. 321 322To get more information about how to review specific parts of Nixpkgs, refer to the documents linked to in the [overview section][overview]. 323 324If a pull request contains documentation changes that might require feedback from the documentation team, ping [@NixOS/documentation-team](https://github.com/orgs/nixos/teams/documentation-team) on the pull request. 325 326If 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. 327 328Container system, boot system and library changes are some examples of the pull requests fitting this category. 329 330## How to merge pull requests 331[pr-merge]: #how-to-merge-pull-requests 332 333The *Nixpkgs committers* are people who have been given 334permission to merge. 335 336It is possible for community members that have enough knowledge and experience on a special topic to contribute by merging pull requests. 337 338In case the PR is stuck waiting for the original author to apply a trivial 339change (a typo, capitalisation change, etc.) and the author allowed the members 340to modify the PR, consider applying it yourself (or commit the existing review 341suggestion). You should pay extra attention to make sure the addition doesn't go 342against the idea of the original PR and would not be opposed by the author. 343 344<!-- 345The following paragraphs about how to deal with unactive contributors is just a proposition and should be modified to what the community agrees to be the right policy. 346 347Please note that contributors with commit rights unactive for more than three months will have their commit rights revoked. 348--> 349 350Please 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. 351 352In 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. 353 354# Flow of merged pull requests 355 356After a pull request is merged, it eventually makes it to the [official Hydra CI](https://hydra.nixos.org/). 357Hydra regularly evaluates and builds Nixpkgs, updating [the official channels](https://channels.nixos.org/) when specific Hydra jobs succeeded. 358See [Nix Channel Status](https://status.nixos.org/) for the current channels and their state. 359Here's a brief overview of the main Git branches and what channels they're used for: 360 361- `master`: The main branch, used for the unstable channels such as `nixpkgs-unstable`, `nixos-unstable` and `nixos-unstable-small`. 362- `release-YY.MM` (e.g. `release-24.05`): The NixOS release branches, used for the stable channels such as `nixos-24.05`, `nixos-24.05-small` and `nixpkgs-24.05-darwin`. 363 364When a channel is updated, a corresponding Git branch is also updated to point to the corresponding commit. 365So 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). 366 367Nixpkgs in its entirety is tied to the NixOS release process, which is documented in the [NixOS Release Wiki](https://nixos.github.io/release-wiki/). 368 369See [this section][branch] to know when to use the release branches. 370 371## Staging 372[staging]: #staging 373 374The staging workflow exists to batch Hydra builds of many packages together. 375 376It works by directing commits that cause [mass rebuilds][mass-rebuild] to a separate `staging` branch that isn't directly built by Hydra. 377Regularly, 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). 378The `staging-next` branch should then only receive direct commits in order to fix Hydra builds. 379Once it is verified that there are no major regressions, it is merged into `master` using [a pull request](https://github.com/NixOS/nixpkgs/pulls?q=head%3Astaging-next). 380This is done manually in order to ensure it's a good use of Hydra's computing resources. 381By keeping the `staging-next` branch separate from `staging`, this batching does not block developers from merging changes into `staging`. 382 383In 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`. 384This is implemented using GitHub workflows [here](.github/workflows/periodic-merge-6h.yml) and [here](.github/workflows/periodic-merge-24h.yml). 385 386> [!Note] 387> Changes must be sufficiently tested before being merged into any branch. 388> Hydra builds should not be used as testing platform. 389 390Here is a Git history diagram showing the flow of commits between the three branches: 391```mermaid 392%%{init: { 393 'theme': 'base', 394 'themeVariables': { 395 'gitInv0': '#ff0000', 396 'gitInv1': '#ff0000', 397 'git2': '#ff4444', 398 'commitLabelFontSize': '15px' 399 }, 400 'gitGraph': { 401 'showCommitLabel':true, 402 'mainBranchName': 'master', 403 'rotateCommitLabel': true 404 } 405} }%% 406gitGraph 407 commit id:" " 408 branch staging-next 409 branch staging 410 411 checkout master 412 checkout staging 413 checkout master 414 commit id:" " 415 checkout staging-next 416 merge master id:"automatic" 417 checkout staging 418 merge staging-next id:"automatic " 419 420 checkout staging-next 421 merge staging type:HIGHLIGHT id:"manual" 422 commit id:"fixup" 423 424 checkout master 425 checkout staging 426 checkout master 427 commit id:" " 428 checkout staging-next 429 merge master id:"automatic " 430 checkout staging 431 merge staging-next id:"automatic " 432 433 checkout staging-next 434 commit id:"fixup " 435 checkout master 436 merge staging-next type:HIGHLIGHT id:"manual (PR)" 437``` 438 439 440Here's an overview of the different branches: 441 442| branch | `master` | `staging-next` | `staging` | 443| --- | --- | --- | --- | 444| Used for development | ✔️ | ❌ | ✔️ | 445| Built by Hydra | ✔️ | ✔️ | ❌ | 446| [Mass rebuilds][mass-rebuild] | ❌ | ⚠️ Only to fix Hydra builds | ✔️ | 447| Critical security fixes | ✔️ for non-mass-rebuilds | ✔️ for mass-rebuilds | ❌ | 448| Automatically merged into | `staging-next` | `staging` | - | 449| Manually merged into | - | `master` | `staging-next` | 450 451The staging workflow is used for all main branches, `master` and `release-YY.MM`, with corresponding names: 452- `master`/`release-YY.MM` 453- `staging`/`staging-YY.MM` 454- `staging-next`/`staging-next-YY.MM` 455 456# Conventions 457 458## Branch conventions 459<!-- This section is relevant to both contributors and reviewers --> 460[branch]: #branch-conventions 461 462Most changes should go to the `master` branch, but sometimes other branches should be used instead. 463Use the following decision process to figure out which one it should be: 464 465Is the change [acceptable for releases][release-acceptable] and do you wish to have the change in the release? 466- No: Use the `master` branch, do not backport the pull request. 467- Yes: Can the change be implemented the same way on the `master` and release branches? 468 For example, a packages major version might differ between the `master` and release branches, such that separate security patches are required. 469 - Yes: Use the `master` branch and [backport the pull request](#how-to-backport-pull-requests). 470 - No: Create separate pull requests to the `master` and `release-XX.YY` branches. 471 472Furthermore, if the change causes a [mass rebuild][mass-rebuild], use the appropriate staging branch instead: 473- Mass rebuilds to `master` should go to `staging` instead. 474- Mass rebuilds to `release-XX.YY` should go to `staging-XX.YY` instead. 475 476See [this section][staging] for more details about such changes propagate between the branches. 477 478### Changes acceptable for releases 479[release-acceptable]: #changes-acceptable-for-releases 480 481Only changes to supported releases may be accepted. 482The oldest supported release (`YYMM`) can be found using 483``` 484nix-instantiate --eval -A lib.trivial.oldestSupportedRelease 485``` 486 487The release branches should generally only receive backwards-compatible changes, both for the Nix expressions and derivations. 488Here are some examples of backwards-compatible changes that are okay to backport: 489- ✔️ New packages, modules and functions 490- ✔️ Security fixes 491- ✔️ Package version updates 492 - ✔️ Patch versions with fixes 493 - ✔️ Minor versions with new functionality, but no breaking changes 494 495In addition, major package version updates with breaking changes are also acceptable for: 496- ✔️ Services that would fail without up-to-date client software, such as `spotify`, `steam`, and `discord` 497- ✔️ Security critical applications, such as `firefox` and `chromium` 498 499### Changes causing mass rebuilds 500[mass-rebuild]: #changes-causing-mass-rebuilds 501 502Which changes cause mass rebuilds is not formally defined. 503In 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. 504As a rule of thumb, if the number of rebuilds is **over 500**, it can be considered a mass rebuild. 505To 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). 506 507## Commit conventions 508[commit-conventions]: #commit-conventions 509 510- Create a commit for each logical unit. 511 512- Check for unnecessary whitespace with `git diff --check` before committing. 513 514- If you have commits `pkg-name: oh, forgot to insert whitespace`: squash commits in this case. Use `git rebase -i`. 515 See [Squashing Commits](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_squashing) for additional information. 516 517- 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). 518 519- When adding yourself as maintainer in the same pull request, make a separate 520 commit with the message `maintainers: add <handle>`. 521 Add the commit before those making changes to the package or module. 522 See [Nixpkgs Maintainers](./maintainers/README.md) for details. 523 524- Make sure you read about any commit conventions specific to the area you're touching. See: 525 - [Commit conventions](./pkgs/README.md#commit-conventions) for changes to `pkgs`. 526 - [Commit conventions](./lib/README.md#commit-conventions) for changes to `lib`. 527 - [Commit conventions](./nixos/README.md#commit-conventions) for changes to `nixos`. 528 - [Commit conventions](./doc/README.md#commit-conventions) for changes to `doc`, the Nixpkgs manual. 529 530### Writing good commit messages 531 532In 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. 533 534Package 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. 535 536Pull 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. 537 538## Code conventions 539[code-conventions]: #code-conventions 540 541### Release notes 542 543If you removed packages 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). 544 545### File naming and organisation 546 547Names 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`. 548 549### Syntax 550 551- Use 2 spaces of indentation per indentation level in Nix expressions, 4 spaces in shell scripts. 552 553- 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. 554 555- Use `lowerCamelCase` for variable names, not `UpperCamelCase`. Note, this rule does not apply to package attribute names, which instead follow the rules in [package naming](./pkgs/README.md#package-naming). 556 557- Function calls with attribute set arguments are written as 558 559 ```nix 560 foo { 561 arg = <...>; 562 } 563 ``` 564 565 not 566 567 ```nix 568 foo 569 { 570 arg = <...>; 571 } 572 ``` 573 574 Also fine is 575 576 ```nix 577 foo { arg = <...>; } 578 ``` 579 580 if it's a short call. 581 582- In attribute sets or lists that span multiple lines, the attribute names or list elements should be aligned: 583 584 ```nix 585 { 586 # A long list. 587 list = [ 588 elem1 589 elem2 590 elem3 591 ]; 592 593 # A long attribute set. 594 attrs = { 595 attr1 = short_expr; 596 attr2 = 597 if true then big_expr else big_expr; 598 }; 599 600 # Combined 601 listOfAttrs = [ 602 { 603 attr1 = 3; 604 attr2 = "fff"; 605 } 606 { 607 attr1 = 5; 608 attr2 = "ggg"; 609 } 610 ]; 611 } 612 ``` 613 614- Short lists or attribute sets can be written on one line: 615 616 ```nix 617 { 618 # A short list. 619 list = [ elem1 elem2 elem3 ]; 620 621 # A short set. 622 attrs = { x = 1280; y = 1024; }; 623 } 624 ``` 625 626- Breaking in the middle of a function argument can give hard-to-read code, like 627 628 ```nix 629 someFunction { x = 1280; 630 y = 1024; } otherArg 631 yetAnotherArg 632 ``` 633 634 (especially if the argument is very large, spanning multiple lines). 635 636 Better: 637 638 ```nix 639 someFunction 640 { x = 1280; y = 1024; } 641 otherArg 642 yetAnotherArg 643 ``` 644 645 or 646 647 ```nix 648 let res = { x = 1280; y = 1024; }; 649 in someFunction res otherArg yetAnotherArg 650 ``` 651 652- The bodies of functions, asserts, and withs are not indented to prevent a lot of superfluous indentation levels, i.e. 653 654 ```nix 655 { arg1, arg2 }: 656 assert system == "i686-linux"; 657 stdenv.mkDerivation { /* ... */ } 658 ``` 659 660 not 661 662 ```nix 663 { arg1, arg2 }: 664 assert system == "i686-linux"; 665 stdenv.mkDerivation { /* ... */ } 666 ``` 667 668- Function formal arguments are written as: 669 670 ```nix 671 { arg1, arg2, arg3 }: { /* ... */ } 672 ``` 673 674 but if they don't fit on one line they're written as: 675 676 ```nix 677 { arg1, arg2, arg3 678 , arg4 679 # Some comment... 680 , argN 681 }: { } 682 ``` 683 684- Functions should list their expected arguments as precisely as possible. That is, write 685 686 ```nix 687 { stdenv, fetchurl, perl }: <...> 688 ``` 689 690 instead of 691 692 ```nix 693 args: with args; <...> 694 ``` 695 696 or 697 698 ```nix 699 { stdenv, fetchurl, perl, ... }: <...> 700 ``` 701 702 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: 703 704 ```nix 705 { stdenv, doCoverageAnalysis ? false, ... } @ args: 706 707 stdenv.mkDerivation (args // { 708 foo = if doCoverageAnalysis then "bla" else ""; 709 }) 710 ``` 711 712 instead of 713 714 ```nix 715 args: 716 717 args.stdenv.mkDerivation (args // { 718 foo = if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else ""; 719 }) 720 ``` 721 722- Unnecessary string conversions should be avoided. Do 723 724 ```nix 725 { 726 rev = version; 727 } 728 ``` 729 730 instead of 731 732 ```nix 733 { 734 rev = "${version}"; 735 } 736 ``` 737 738- Building lists conditionally _should_ be done with `lib.optional(s)` instead of using `if cond then [ ... ] else null` or `if cond then [ ... ] else [ ]`. 739 740 ```nix 741 { 742 buildInputs = lib.optional stdenv.isDarwin iconv; 743 } 744 ``` 745 746 instead of 747 748 ```nix 749 { 750 buildInputs = if stdenv.isDarwin then [ iconv ] else null; 751 } 752 ``` 753 754 As an exception, an explicit conditional expression with null can be used when fixing a important bug without triggering a mass rebuild. 755 If this is done a follow up pull request _should_ be created to change the code to `lib.optional(s)`.