Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 22.05 292 lines 16 kB view raw view rendered
1# Submitting changes {#chap-submitting-changes} 2 3## Making patches {#submitting-changes-making-patches} 4 5- Read [Manual (How to write packages for Nix)](https://nixos.org/nixpkgs/manual/). 6 7- Fork [the Nixpkgs repository](https://github.com/nixos/nixpkgs/) on GitHub. 8 9- Create a branch for your future fix. 10 11 - 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 12 13 ```ShellSession 14 $ nixos-version --hash 15 0998212 16 $ git checkout 0998212 17 $ git checkout -b 'fix/pkg-name-update' 18 ``` 19 20 - Please avoid working directly on the `master` branch. 21 22- Make commits of logical units. 23 24- 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`. 25 26- Check for unnecessary whitespace with `git diff --check` before committing. 27 28- Format the commit in a following way: 29 30 ``` 31 (pkg-name | nixos/<module>): (from -> to | init at version | refactor | etc) 32 Additional information. 33 ``` 34 35 - Examples: 36 - `nginx: init at 2.0.1` 37 - `firefox: 54.0.1 -> 55.0` 38 - `nixos/hydra: add bazBaz option` 39 - `nixos/nginx: refactor config generation` 40 41- Test your changes. If you work with 42 43 - nixpkgs: 44 45 - update pkg 46 - `nix-env -iA pkg-attribute-name -f <path to your local nixpkgs folder>` 47 - add pkg 48 - Make sure it’s in `pkgs/top-level/all-packages.nix` 49 - `nix-env -iA pkg-attribute-name -f <path to your local nixpkgs folder>` 50 - _If you don’t want to install pkg in you profile_. 51 - `nix-build -A pkg-attribute-name <path to your local nixpkgs folder>` and check results in the folder `result`. It will appear in the same directory where you did `nix-build`. 52 - 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. 53 54 - NixOS and its modules: 55 - 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=<path to your local nixpkgs folder> --fast`. 56 57- If you have commits `pkg-name: oh, forgot to insert whitespace`: squash commits in this case. Use `git rebase -i`. 58 59- [Rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) your branch against current `master`. 60 61## Submitting changes {#submitting-changes-submitting-changes} 62 63- Push your changes to your fork of nixpkgs. 64- Create the pull request 65- Follow [the contribution guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#submitting-changes). 66 67## Submitting security fixes {#submitting-changes-submitting-security-fixes} 68 69Security fixes are submitted in the same way as other changes and thus the same guidelines apply. 70 71- If a new version fixing the vulnerability has been released, update the package; 72- 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. 73 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.: 74 75 ```nix 76 (fetchpatch { 77 name = "CVE-2019-11068.patch"; 78 url = "https://gitlab.gnome.org/GNOME/libxslt/commit/e03553605b45c88f0b4b2980adfbbb8f6fca2fd6.patch"; 79 sha256 = "0pkpb4837km15zgg6h57bncp66d5lwrlvkr73h0lanywq7zrwhj8"; 80 }) 81 ``` 82 83If 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. 84 85Critical security fixes may by-pass the staging branches and be delivered directly to release branches such as `master` and `release-*`. 86 87## Deprecating/removing packages {#submitting-changes-deprecating-packages} 88 89There is currently no policy when to remove a package. 90 91Before removing a package, one should try to find a new maintainer or fix smaller issues first. 92 93### Steps to remove a package from Nixpkgs {#steps-to-remove-a-package-from-nixpkgs} 94 95We use jbidwatcher as an example for a discontinued project here. 96 971. Have Nixpkgs checked out locally and up to date. 981. Create a new branch for your change, e.g. `git checkout -b jbidwatcher` 991. Remove the actual package including its directory, e.g. `git rm -rf pkgs/applications/misc/jbidwatcher` 1001. Remove the package from the list of all packages (`pkgs/top-level/all-packages.nix`). 1011. 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.) 102 103 For example in this case: 104 105 ``` 106 jbidwatcher = throw "jbidwatcher was discontinued in march 2021"; # added 2021-03-15 107 ``` 108 109 The throw message should explain in short why the package was removed for users that still have it installed. 110 1111. Test if the changes introduced any issues by running `nix-env -qaP -f . --show-trace`. It should show the list of packages without errors. 1121. Commit the changes. Explain again why the package was removed. If it was declared discontinued upstream, add a link to the source. 113 114 ```ShellSession 115 $ git add pkgs/applications/misc/jbidwatcher/default.nix pkgs/top-level/all-packages.nix pkgs/top-level/aliases.nix 116 $ git commit 117 ``` 118 119 Example commit message: 120 121 ``` 122 jbidwatcher: remove 123 124 project was discontinued in march 2021. the program does not work anymore because ebay changed the login. 125 126 https://web.archive.org/web/20210315205723/http://www.jbidwatcher.com/ 127 ``` 128 1291. Push changes to your GitHub fork with `git push` 1301. Create a pull request against Nixpkgs. Mention the package maintainer. 131 132This is how the pull request looks like in this case: [https://github.com/NixOS/nixpkgs/pull/116470](https://github.com/NixOS/nixpkgs/pull/116470) 133 134## Pull Request Template {#submitting-changes-pull-request-template} 135 136The 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. 137 138When a PR is created, it will be pre-populated with some checkboxes detailed below: 139 140### Tested using sandboxing {#submitting-changes-tested-with-sandbox} 141 142When 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. 143 144Sandboxing 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<https://nixos.org/hydra/> sandboxing is also used. 145 146Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing **before** building the package: 147 148- **Globally enable sandboxing on NixOS**: add the following to `configuration.nix` 149 150 ```nix 151 nix.useSandbox = true; 152 ``` 153 154- **Globally enable sandboxing on non-NixOS platforms**: add the following to: `/etc/nix/nix.conf` 155 156 ```ini 157 sandbox = true 158 ``` 159 160### Built on platform(s) {#submitting-changes-platform-diversity} 161 162Many 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. 163 164### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) {#submitting-changes-nixos-tests} 165 166Packages 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). 167 168### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` {#submitting-changes-tested-compilation} 169 170If 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 uncommited changes with the `wip` option or specifying a github pull request number. 171 172review changes from pull request number 12345: 173 174```ShellSession 175nix run nixpkgs.nixpkgs-review -c nixpkgs-review pr 12345 176``` 177 178review uncommitted changes: 179 180```ShellSession 181nix run nixpkgs.nixpkgs-review -c nixpkgs-review wip 182``` 183 184review changes from last commit: 185 186```ShellSession 187nix run nixpkgs.nixpkgs-review -c nixpkgs-review rev HEAD 188``` 189 190### Tested execution of all binary files (usually in `./result/bin/`) {#submitting-changes-tested-execution} 191 192It’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. 193 194### Meets Nixpkgs contribution standards {#submitting-changes-contribution-standards} 195 196The 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. 197 198## Hotfixing pull requests {#submitting-changes-hotfixing-pull-requests} 199 200- Make the appropriate changes in you branch. 201- Don’t create additional commits, do 202 - `git rebase -i` 203 - `git push --force` to your branch. 204 205## Commit policy {#submitting-changes-commit-policy} 206 207- Commits must be sufficiently tested before being merged, both for the master and staging branches. 208- 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. 209- 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. 210 211```{.graphviz caption="Staging workflow"} 212digraph { 213 "small changes" [shape=none] 214 "mass-rebuilds and other large changes" [shape=none] 215 "critical security fixes" [shape=none] 216 "broken staging-next fixes" [shape=none] 217 218 "small changes" -> master 219 "mass-rebuilds and other large changes" -> staging 220 "critical security fixes" -> master 221 "broken staging-next fixes" -> "staging-next" 222 223 "staging-next" -> master [color="#E85EB0"] [label="stabilization ends"] [fontcolor="#E85EB0"] 224 "staging" -> "staging-next" [color="#E85EB0"] [label="stabilization starts"] [fontcolor="#E85EB0"] 225 226 master -> "staging-next" -> staging [color="#5F5EE8"] [label="every six hours (GitHub Action)"] [fontcolor="#5F5EE8"] 227} 228``` 229 230[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. 231 232 233### Master branch {#submitting-changes-master-branch} 234 235The `master` branch is the main development branch. It should only see non-breaking commits that do not cause mass rebuilds. 236 237### Staging branch {#submitting-changes-staging-branch} 238 239The `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. 240 241### Staging-next branch {#submitting-changes-staging-next-branch} 242 243The `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. 244 245If 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. 246 247### Stable release branches {#submitting-changes-stable-release-branches} 248 249The same staging workflow applies to stable release branches, but the main branch is called `release-*` instead of `master`. 250 251Example branch names: `release-21.11`, `staging-21.11`, `staging-next-21.11`. 252 253Most changes added to the stable release branches are cherry-picked (“backported”) from the `master` and staging branches. 254 255#### Automatically backporting a Pull Request {#submitting-changes-stable-release-branches-automatic-backports} 256 257Assign label `backport <branch>` (e.g. `backport release-21.11`) to the PR and a backport PR is automatically created after the PR is merged. 258 259#### Manually backporting changes {#submitting-changes-stable-release-branches-manual-backports} 260 261Cherry-pick changes via `git cherry-pick -x <original commit>` so that the original commit id is included in the commit message. 262 263Add 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 <original commit>`, 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. 264 265Here is an example of a cherry-picked commit message with good reason description: 266 267``` 268zfs: Keep trying root import until it works 269 270Works around #11003. 271 272(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9) 273 274Reason: several people cannot boot with ZFS on NVMe 275``` 276 277Other examples of reasons are: 278 279- Previously the build would fail due to, e.g., `getaddrinfo` not being defined 280- The previous download links were all broken 281- Crash when starting on some X11 systems 282 283#### Acceptable backport criteria 284 285The 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. 286 287However, many changes are able to be backported, including: 288- New Packages / Modules 289- Security / Patch updates 290- Version updates which include new functionality (but no breaking changes) 291- Services which require a client to be up-to-date regardless. (E.g. `spotify`, `steam`, or `discord`) 292- Security critical applications (E.g. `firefox`)