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 -i pkg-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 -i pkg-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>/default.nix` and check results in the folder `result`. It will appear in the same directory where you did `nix-build`. 52 - If you did `nix-env -i pkg-name` you can do `nix-env -e pkg-name` 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/.github/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 ```nix 75 (fetchpatch { 76 name = "CVE-2019-11068.patch"; 77 url = "https://gitlab.gnome.org/GNOME/libxslt/commit/e03553605b45c88f0b4b2980adfbbb8f6fca2fd6.patch"; 78 sha256 = "0pkpb4837km15zgg6h57bncp66d5lwrlvkr73h0lanywq7zrwhj8"; 79 }) 80 ``` 81 82If 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. 83 84Critical security fixes may by-pass the staging branches and be delivered directly to release branches such as `master` and `release-*`. 85 86## Deprecating/removing packages {#submitting-changes-deprecating-packages} 87 88There is currently no policy when to remove a package. 89 90Before removing a package, one should try to find a new maintainer or fix smaller issues first. 91 92### Steps to remove a package from Nixpkgs 93 94We use jbidwatcher as an example for a discontinued project here. 95 961. Have Nixpkgs checked out locally and up to date. 971. Create a new branch for your change, e.g. `git checkout -b jbidwatcher` 981. Remove the actual package including its directory, e.g. `rm -rf pkgs/applications/misc/jbidwatcher` 991. Remove the package from the list of all packages (`pkgs/top-level/all-packages.nix`). 1001. Add an alias for the package name in `pkgs/top-level/aliases.nix` (There is also `pkgs/misc/vim-plugins/aliases.nix`. Package sets typically do not have aliases, so we can't add them there.) 101 102 For example in this case: 103 ``` 104 jbidwatcher = throw "jbidwatcher was discontinued in march 2021"; # added 2021-03-15 105 ``` 106 107 The throw message should explain in short why the package was removed for users that still have it installed. 108 1091. Test if the changes introduced any issues by running `nix-env -qaP -f . --show-trace`. It should show the list of packages without errors. 1101. Commit the changes. Explain again why the package was removed. If it was declared discontinued upstream, add a link to the source. 111 112 ```ShellSession 113 $ git add pkgs/applications/misc/jbidwatcher/default.nix pkgs/top-level/all-packages.nix pkgs/top-level/aliases.nix 114 $ git commit 115 ``` 116 117 Example commit message: 118 119 ``` 120 jbidwatcher: remove 121 122 project was discontinued in march 2021. the program does not work anymore because ebay changed the login. 123 124 https://web.archive.org/web/20210315205723/http://www.jbidwatcher.com/ 125 ``` 126 1271. Push changes to your GitHub fork with `git push` 1281. Create a pull request against Nixpkgs. Mention the package maintainer. 129 130This is how the pull request looks like in this case: [https://github.com/NixOS/nixpkgs/pull/116470](https://github.com/NixOS/nixpkgs/pull/116470) 131 132## Pull Request Template {#submitting-changes-pull-request-template} 133 134The 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. 135 136When a PR is created, it will be pre-populated with some checkboxes detailed below: 137 138### Tested using sandboxing {#submitting-changes-tested-with-sandbox} 139 140When 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. 141 142Sandboxing 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. 143 144Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing **before** building the package: 145 146- **Globally enable sandboxing on NixOS**: add the following to `configuration.nix` 147 148 ```nix 149 nix.useSandbox = true; 150 ``` 151 152- **Globally enable sandboxing on non-NixOS platforms**: add the following to: `/etc/nix/nix.conf` 153 154 ```ini 155 sandbox = true 156 ``` 157 158### Built on platform(s) {#submitting-changes-platform-diversity} 159 160Many 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. 161 162### Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) {#submitting-changes-nixos-tests} 163 164Packages 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). 165 166### Tested compilation of all pkgs that depend on this change using `nixpkgs-review` {#submitting-changes-tested-compilation} 167 168If 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. 169 170review changes from pull request number 12345: 171 172```ShellSession 173nix run nixpkgs.nixpkgs-review -c nixpkgs-review pr 12345 174``` 175 176review uncommitted changes: 177 178```ShellSession 179nix run nixpkgs.nixpkgs-review -c nixpkgs-review wip 180``` 181 182review changes from last commit: 183 184```ShellSession 185nix run nixpkgs.nixpkgs-review -c nixpkgs-review rev HEAD 186``` 187 188### Tested execution of all binary files (usually in `./result/bin/`) {#submitting-changes-tested-execution} 189 190It’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. 191 192### Meets Nixpkgs contribution standards {#submitting-changes-contribution-standards} 193 194The last checkbox is fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/.github/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. 195 196## Hotfixing pull requests {#submitting-changes-hotfixing-pull-requests} 197 198- Make the appropriate changes in you branch. 199- Don’t create additional commits, do 200 - `git rebase -i` 201 - `git push --force` to your branch. 202 203## Commit policy {#submitting-changes-commit-policy} 204 205- Commits must be sufficiently tested before being merged, both for the master and staging branches. 206- 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. 207- 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. 208 209```{.graphviz caption="Staging workflow"} 210digraph { 211 "small changes" [shape=none] 212 "mass-rebuilds and other large changes" [shape=none] 213 "critical security fixes" [shape=none] 214 "broken staging-next fixes" [shape=none] 215 216 "small changes" -> master 217 "mass-rebuilds and other large changes" -> staging 218 "critical security fixes" -> master 219 "broken staging-next fixes" -> "staging-next" 220 221 "staging-next" -> master [color="#E85EB0"] [label="stabilization ends"] [fontcolor="#E85EB0"] 222 "staging" -> "staging-next" [color="#E85EB0"] [label="stabilization starts"] [fontcolor="#E85EB0"] 223 224 master -> "staging-next" -> staging [color="#5F5EE8"] [label="every six hours (GitHub Action)"] [fontcolor="#5F5EE8"] 225} 226``` 227 228[This GitHub Action](https://github.com/NixOS/nixpkgs/blob/master/.github/workflows/merge-staging.yml) brings changes from `master` to `staging-next` and from `staging-next` to `staging` every 6 hours. 229 230 231### Master branch {#submitting-changes-master-branch} 232 233The `master` branch is the main development branch. It should only see non-breaking commits that do not cause mass rebuilds. 234 235### Staging branch {#submitting-changes-staging-branch} 236 237The `staging` branch is a development branch where mass-rebuilds go. 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. 238 239### Staging-next branch {#submitting-changes-staging-next-branch} 240 241The `staging-next` branch is for stabilizing mass-rebuilds submitted to the `staging` branch prior to merging them into `master`. Mass-rebuilds should go via the `staging` branch. It should only see non-breaking commits that are fixing issues blocking it from being merged into the `master ` branch. 242 243If 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. 244 245### Stable release branches {#submitting-changes-stable-release-branches} 246 247For cherry-picking a commit to a stable release branch (“backporting”), use `git cherry-pick -x <original commit>` so that the original commit id is included in the commit. 248 249Add a reason for the backport by using `git cherry-pick -xe <original commit>` instead when it is not obvious from the original commit message. It is not needed when it's a minor version update that includes security and bug fixes but don't add new features or when the commit fixes an otherwise broken package. 250 251Here is an example of a cherry-picked commit message with good reason description: 252 253``` 254zfs: Keep trying root import until it works 255 256Works around #11003. 257 258(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9) 259 260Reason: several people cannot boot with ZFS on NVMe 261``` 262 263Other examples of reasons are: 264 265- Previously the build would fail due to, e.g., `getaddrinfo` not being defined 266- The previous download links were all broken 267- Crash when starting on some X11 systems