1<chapter xmlns="http://docbook.org/ns/docbook"
2 xmlns:xlink="http://www.w3.org/1999/xlink"
3 xml:id="chap-submitting-changes">
4 <title>Submitting changes</title>
5 <section xml:id="submitting-changes-making-patches">
6 <title>Making patches</title>
7
8 <itemizedlist>
9 <listitem>
10 <para>
11 Read <link xlink:href="https://nixos.org/nixpkgs/manual/">Manual (How to write packages for Nix)</link>.
12 </para>
13 </listitem>
14 <listitem>
15 <para>
16 Fork <link xlink:href="https://github.com/nixos/nixpkgs/">the Nixpkgs repository</link> on GitHub.
17 </para>
18 </listitem>
19 <listitem>
20 <para>
21 Create a branch for your future fix.
22 <itemizedlist>
23 <listitem>
24 <para>
25 You can make branch from a commit of your local <command>nixos-version</command>. That will help you to avoid additional local compilations. Because you will receive packages from binary cache. For example
26<screen>
27<prompt>$ </prompt>nixos-version --hash
280998212
29<prompt>$ </prompt>git checkout 0998212
30<prompt>$ </prompt>git checkout -b 'fix/pkg-name-update'
31</screen>
32 </para>
33 </listitem>
34 <listitem>
35 <para>
36 Please avoid working directly on the <command>master</command> branch.
37 </para>
38 </listitem>
39 </itemizedlist>
40 </para>
41 </listitem>
42 <listitem>
43 <para>
44 Make commits of logical units.
45 </para>
46 </listitem>
47 <listitem>
48 <para>
49 If you removed pkgs or made some major NixOS changes, write about it in the release notes for the next stable release. For example <command>nixos/doc/manual/release-notes/rl-2003.xml</command>.
50 </para>
51 </listitem>
52 <listitem>
53 <para>
54 Check for unnecessary whitespace with <command>git diff --check</command> before committing.
55 </para>
56 </listitem>
57 <listitem>
58 <para>
59 Format the commit in a following way:
60 </para>
61<programlisting>
62(pkg-name | nixos/<module>): (from -> to | init at version | refactor | etc)
63Additional information.
64</programlisting>
65 <itemizedlist>
66 <listitem>
67 <para>
68 Examples:
69 <itemizedlist>
70 <listitem>
71 <para>
72 <command>nginx: init at 2.0.1</command>
73 </para>
74 </listitem>
75 <listitem>
76 <para>
77 <command>firefox: 54.0.1 -> 55.0</command>
78 </para>
79 </listitem>
80 <listitem>
81 <para>
82 <command>nixos/hydra: add bazBaz option</command>
83 </para>
84 </listitem>
85 <listitem>
86 <para>
87 <command>nixos/nginx: refactor config generation</command>
88 </para>
89 </listitem>
90 </itemizedlist>
91 </para>
92 </listitem>
93 </itemizedlist>
94 </listitem>
95 <listitem>
96 <para>
97 Test your changes. If you work with
98 <itemizedlist>
99 <listitem>
100 <para>
101 nixpkgs:
102 <itemizedlist>
103 <listitem>
104 <para>
105 update pkg ->
106 <itemizedlist>
107 <listitem>
108 <para>
109 <command>nix-env -i pkg-name -f <path to your local nixpkgs folder></command>
110 </para>
111 </listitem>
112 </itemizedlist>
113 </para>
114 </listitem>
115 <listitem>
116 <para>
117 add pkg ->
118 <itemizedlist>
119 <listitem>
120 <para>
121 Make sure it's in <command>pkgs/top-level/all-packages.nix</command>
122 </para>
123 </listitem>
124 <listitem>
125 <para>
126 <command>nix-env -i pkg-name -f <path to your local nixpkgs folder></command>
127 </para>
128 </listitem>
129 </itemizedlist>
130 </para>
131 </listitem>
132 <listitem>
133 <para>
134 <emphasis>If you don't want to install pkg in you profile</emphasis>.
135 <itemizedlist>
136 <listitem>
137 <para>
138 <command>nix-build -A pkg-attribute-name <path to your local nixpkgs folder>/default.nix</command> and check results in the folder <command>result</command>. It will appear in the same directory where you did <command>nix-build</command>.
139 </para>
140 </listitem>
141 </itemizedlist>
142 </para>
143 </listitem>
144 <listitem>
145 <para>
146 If you did <command>nix-env -i pkg-name</command> you can do <command>nix-env -e pkg-name</command> to uninstall it from your system.
147 </para>
148 </listitem>
149 </itemizedlist>
150 </para>
151 </listitem>
152 <listitem>
153 <para>
154 NixOS and its modules:
155 <itemizedlist>
156 <listitem>
157 <para>
158 You can add new module to your NixOS configuration file (usually it's <command>/etc/nixos/configuration.nix</command>). And do <command>sudo nixos-rebuild test -I nixpkgs=<path to your local nixpkgs folder> --fast</command>.
159 </para>
160 </listitem>
161 </itemizedlist>
162 </para>
163 </listitem>
164 </itemizedlist>
165 </para>
166 </listitem>
167 <listitem>
168 <para>
169 If you have commits <command>pkg-name: oh, forgot to insert whitespace</command>: squash commits in this case. Use <command>git rebase -i</command>.
170 </para>
171 </listitem>
172 <listitem>
173 <para>
174 <link xlink:href="https://git-scm.com/book/en/v2/Git-Branching-Rebasing">Rebase</link> your branch against current <command>master</command>.
175 </para>
176 </listitem>
177 </itemizedlist>
178 </section>
179 <section xml:id="submitting-changes-submitting-changes">
180 <title>Submitting changes</title>
181
182 <itemizedlist>
183 <listitem>
184 <para>
185 Push your changes to your fork of nixpkgs.
186 </para>
187 </listitem>
188 <listitem>
189 <para>
190 Create the pull request
191 </para>
192 </listitem>
193 <listitem>
194 <para>
195 Follow <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/.github/CONTRIBUTING.md#submitting-changes">the contribution guidelines</link>.
196 </para>
197 </listitem>
198 </itemizedlist>
199 </section>
200 <section xml:id="submitting-changes-submitting-security-fixes">
201 <title>Submitting security fixes</title>
202
203 <para>
204 Security fixes are submitted in the same way as other changes and thus the same guidelines apply.
205 </para>
206
207 <para>
208 If the security fix comes in the form of a patch and a CVE is available, then the name of the patch should be the CVE identifier, so e.g. <literal>CVE-2019-13636.patch</literal> in the case of a patch that is included in the Nixpkgs tree. If a patch is fetched the name needs to be set as well, e.g.:
209 </para>
210
211<programlisting>
212(fetchpatch {
213 name = "CVE-2019-11068.patch";
214 url = "https://gitlab.gnome.org/GNOME/libxslt/commit/e03553605b45c88f0b4b2980adfbbb8f6fca2fd6.patch";
215 sha256 = "0pkpb4837km15zgg6h57bncp66d5lwrlvkr73h0lanywq7zrwhj8";
216})
217</programlisting>
218
219 <para>
220 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.
221 </para>
222
223 <para>
224 Critical security fixes may by-pass the staging branches and be delivered directly to release branches such as <literal>master</literal> and <literal>release-*</literal>.
225 </para>
226 </section>
227 <section xml:id="submitting-changes-pull-request-template">
228 <title>Pull Request Template</title>
229
230 <para>
231 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.
232 </para>
233
234 <para>
235 When a PR is created, it will be pre-populated with some checkboxes detailed below:
236 </para>
237
238 <section xml:id="submitting-changes-tested-with-sandbox">
239 <title>Tested using sandboxing</title>
240
241 <para>
242 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 <function>fetch*</function> 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 <link
243 xlink:href="https://nixos.org/nix/manual/#conf-sandbox">sandbox</link> in Nix manual for details.
244 </para>
245
246 <para>
247 Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for <link
248 xlink:href="https://github.com/NixOS/nixpkgs/">nixpkgs</link> people are asked to test builds with sandboxing enabled (see <literal>Tested using sandboxing</literal> in the pull request template) because in<link
249 xlink:href="https://nixos.org/hydra/">https://nixos.org/hydra/</link> sandboxing is also used.
250 </para>
251
252 <para>
253 Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing <emphasis role="bold">before</emphasis> building the package:
254 <itemizedlist>
255 <listitem>
256 <para>
257 <emphasis role="bold">Globally enable sandboxing on NixOS</emphasis>: add the following to <filename>configuration.nix</filename>
258<screen>nix.useSandbox = true;</screen>
259 </para>
260 </listitem>
261 <listitem>
262 <para>
263 <emphasis role="bold">Globally enable sandboxing on non-NixOS platforms</emphasis>: add the following to: <filename>/etc/nix/nix.conf</filename>
264<screen>sandbox = true</screen>
265 </para>
266 </listitem>
267 </itemizedlist>
268 </para>
269 </section>
270
271 <section xml:id="submitting-changes-platform-diversity">
272 <title>Built on platform(s)</title>
273
274 <para>
275 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.
276 </para>
277 </section>
278
279 <section xml:id="submitting-changes-nixos-tests">
280 <title>Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)</title>
281
282 <para>
283 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 only apply to packages with NixOS modules defined and can only be run on Linux. For more details on writing and running tests, see the <link
284 xlink:href="https://nixos.org/nixos/manual/index.html#sec-nixos-tests">section in the NixOS manual</link>.
285 </para>
286 </section>
287
288 <section xml:id="submitting-changes-tested-compilation">
289 <title>Tested compilation of all pkgs that depend on this change using <command>nixpkgs-review</command></title>
290
291 <para>
292 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 <command>nixpkgs-review</command> utility can look for and build all dependencies either based on uncommited changes with the <literal>wip</literal> option or specifying a github pull request number.
293 </para>
294
295 <para>
296 review changes from pull request number 12345:
297 <screen>nix run nixpkgs.nixpkgs-review -c nixpkgs-review pr 12345</screen>
298 </para>
299
300 <para>
301 review uncommitted changes:
302 <screen>nix run nixpkgs.nixpkgs-review -c nixpkgs-review wip</screen>
303 </para>
304
305 <para>
306 review changes from last commit:
307 <screen>nix run nixpkgs.nixpkgs-review -c nixpkgs-review rev HEAD</screen>
308 </para>
309 </section>
310
311 <section xml:id="submitting-changes-tested-execution">
312 <title>Tested execution of all binary files (usually in <filename>./result/bin/</filename>)</title>
313
314 <para>
315 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 <filename>./result/bin</filename> and running any files in there, or at a minimum, the main executable for the package. For example, if you make a change to <package>texlive</package>, you probably would only check the binaries associated with the change you made rather than testing all of them.
316 </para>
317 </section>
318
319 <section xml:id="submitting-changes-contribution-standards">
320 <title>Meets Nixpkgs contribution standards</title>
321
322 <para>
323 The last checkbox is fits <link
324 xlink:href="https://github.com/NixOS/nixpkgs/blob/master/.github/CONTRIBUTING.md">CONTRIBUTING.md</link>. 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.
325 </para>
326 </section>
327 </section>
328 <section xml:id="submitting-changes-hotfixing-pull-requests">
329 <title>Hotfixing pull requests</title>
330
331 <itemizedlist>
332 <listitem>
333 <para>
334 Make the appropriate changes in you branch.
335 </para>
336 </listitem>
337 <listitem>
338 <para>
339 Don't create additional commits, do
340 <itemizedlist>
341 <listitem>
342 <para>
343 <command>git rebase -i</command>
344 </para>
345 </listitem>
346 <listitem>
347 <para>
348 <command>git push --force</command> to your branch.
349 </para>
350 </listitem>
351 </itemizedlist>
352 </para>
353 </listitem>
354 </itemizedlist>
355 </section>
356 <section xml:id="submitting-changes-commit-policy">
357 <title>Commit policy</title>
358
359 <itemizedlist>
360 <listitem>
361 <para>
362 Commits must be sufficiently tested before being merged, both for the master and staging branches.
363 </para>
364 </listitem>
365 <listitem>
366 <para>
367 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.
368 </para>
369 </listitem>
370 <listitem>
371 <para>
372 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.
373 </para>
374 </listitem>
375 </itemizedlist>
376
377 <section xml:id="submitting-changes-master-branch">
378 <title>Master branch</title>
379 <para>
380 The <literal>master</literal> branch is the main development branch.
381 It should only see non-breaking commits that do not cause mass rebuilds.
382 </para>
383 </section>
384
385 <section xml:id="submitting-changes-staging-branch">
386 <title>Staging branch</title>
387 <para>
388 The <literal>staging</literal> branch is a development branch where mass-rebuilds go.
389 It should only see non-breaking mass-rebuild commits.
390 That means it is not to be used for testing, and changes must have been well tested already.
391 If the branch is already in a broken state, please refrain from adding extra new breakages.
392 </para>
393 </section>
394
395 <section xml:id="submitting-changes-staging-next-branch">
396 <title>Staging-next branch</title>
397 <para>
398 The <literal>staging-next</literal> branch is for stabilizing mass-rebuilds submitted to the <literal>staging</literal> branch prior to merging them into <literal>master</literal>.
399 Mass-rebuilds should go via the <literal>staging</literal> branch.
400 It should only see non-breaking commits that are fixing issues blocking it from being merged into the <literal>master </literal> branch.
401 </para>
402 <para>
403 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.
404 </para>
405 </section>
406
407 <section xml:id="submitting-changes-stable-release-branches">
408 <title>Stable release branches</title>
409
410 <para>
411 For cherry-picking a commit to a stable release branch (<quote>backporting</quote>), use <literal>git cherry-pick -x <original commit></literal> so that the original commit id is included in the commit.
412 </para>
413
414 <para>
415 Add a reason for the backport by using <literal>git cherry-pick -xe <original commit></literal> 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.
416 </para>
417
418 <para>
419 Here is an example of a cherry-picked commit message with good reason description:
420 </para>
421
422<screen>
423zfs: Keep trying root import until it works
424
425Works around #11003.
426
427(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9)
428
429Reason: several people cannot boot with ZFS on NVMe
430</screen>
431
432 <para>
433 Other examples of reasons are:
434 </para>
435
436 <itemizedlist spacing="compact">
437 <listitem>
438 <para>
439 Previously the build would fail due to, e.g., <literal>getaddrinfo</literal> not being defined
440 </para>
441 </listitem>
442 <listitem>
443 <para>
444 The previous download links were all broken
445 </para>
446 </listitem>
447 <listitem>
448 <para>
449 Crash when starting on some X11 systems
450 </para>
451 </listitem>
452 </itemizedlist>
453 </section>
454 </section>
455</chapter>