summary refs log tree commit diff
path: root/doc/contributing/submitting-changes.xml
blob: f283ae1e68512706c9aa84b0fdf18f2efe6d0bf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
<chapter xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xml:id="chap-submitting-changes">
 <title>Submitting changes</title>
 <section xml:id="submitting-changes-making-patches">
  <title>Making patches</title>

  <itemizedlist>
   <listitem>
    <para>
     Read <link xlink:href="https://nixos.org/nixpkgs/manual/">Manual (How to write packages for Nix)</link>.
    </para>
   </listitem>
   <listitem>
    <para>
     Fork the repository on GitHub.
    </para>
   </listitem>
   <listitem>
    <para>
     Create a branch for your future fix.
     <itemizedlist>
      <listitem>
       <para>
        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.
        <itemizedlist>
         <listitem>
          <para>
           For example: <command>nixos-version</command> returns <command>15.05.git.0998212 (Dingo)</command>. So you can do:
          </para>
         </listitem>
        </itemizedlist>
<screen>
<prompt>$ </prompt>git checkout 0998212
<prompt>$ </prompt>git checkout -b 'fix/pkg-name-update'
</screen>
       </para>
      </listitem>
      <listitem>
       <para>
        Please avoid working directly on the <command>master</command> branch.
       </para>
      </listitem>
     </itemizedlist>
    </para>
   </listitem>
   <listitem>
    <para>
     Make commits of logical units.
     <itemizedlist>
      <listitem>
       <para>
        If you removed pkgs, made some major NixOS changes etc., write about them in <command>nixos/doc/manual/release-notes/rl-unstable.xml</command>.
       </para>
      </listitem>
     </itemizedlist>
    </para>
   </listitem>
   <listitem>
    <para>
     Check for unnecessary whitespace with <command>git diff --check</command> before committing.
    </para>
   </listitem>
   <listitem>
    <para>
     Format the commit in a following way:
    </para>
<programlisting>
(pkg-name | nixos/&lt;module>): (from -> to | init at version | refactor | etc)
Additional information.
</programlisting>
    <itemizedlist>
     <listitem>
      <para>
       Examples:
       <itemizedlist>
        <listitem>
         <para>
          <command>nginx: init at 2.0.1</command>
         </para>
        </listitem>
        <listitem>
         <para>
          <command>firefox: 54.0.1 -> 55.0</command>
         </para>
        </listitem>
        <listitem>
         <para>
          <command>nixos/hydra: add bazBaz option</command>
         </para>
        </listitem>
        <listitem>
         <para>
          <command>nixos/nginx: refactor config generation</command>
         </para>
        </listitem>
       </itemizedlist>
      </para>
     </listitem>
    </itemizedlist>
   </listitem>
   <listitem>
    <para>
     Test your changes. If you work with
     <itemizedlist>
      <listitem>
       <para>
        nixpkgs:
        <itemizedlist>
         <listitem>
          <para>
           update pkg ->
           <itemizedlist>
            <listitem>
             <para>
              <command>nix-env -i pkg-name -f &lt;path to your local nixpkgs folder&gt;</command>
             </para>
            </listitem>
           </itemizedlist>
          </para>
         </listitem>
         <listitem>
          <para>
           add pkg ->
           <itemizedlist>
            <listitem>
             <para>
              Make sure it's in <command>pkgs/top-level/all-packages.nix</command>
             </para>
            </listitem>
            <listitem>
             <para>
              <command>nix-env -i pkg-name -f &lt;path to your local nixpkgs folder&gt;</command>
             </para>
            </listitem>
           </itemizedlist>
          </para>
         </listitem>
         <listitem>
          <para>
           <emphasis>If you don't want to install pkg in you profile</emphasis>.
           <itemizedlist>
            <listitem>
             <para>
              <command>nix-build -A pkg-attribute-name &lt;path to your local nixpkgs folder&gt;/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>.
             </para>
            </listitem>
           </itemizedlist>
          </para>
         </listitem>
         <listitem>
          <para>
           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.
          </para>
         </listitem>
        </itemizedlist>
       </para>
      </listitem>
      <listitem>
       <para>
        NixOS and its modules:
        <itemizedlist>
         <listitem>
          <para>
           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=&lt;path to your local nixpkgs folder&gt; --fast</command>.
          </para>
         </listitem>
        </itemizedlist>
       </para>
      </listitem>
     </itemizedlist>
    </para>
   </listitem>
   <listitem>
    <para>
     If you have commits <command>pkg-name: oh, forgot to insert whitespace</command>: squash commits in this case. Use <command>git rebase -i</command>.
    </para>
   </listitem>
   <listitem>
    <para>
     Rebase you branch against current <command>master</command>.
    </para>
   </listitem>
  </itemizedlist>
 </section>
 <section xml:id="submitting-changes-submitting-changes">
  <title>Submitting changes</title>

  <itemizedlist>
   <listitem>
    <para>
     Push your changes to your fork of nixpkgs.
    </para>
   </listitem>
   <listitem>
    <para>
     Create pull request:
     <itemizedlist>
      <listitem>
       <para>
        Write the title in format <command>(pkg-name | nixos/&lt;module>): improvement</command>.
        <itemizedlist>
         <listitem>
          <para>
           If you update the pkg, write versions <command>from -> to</command>.
          </para>
         </listitem>
        </itemizedlist>
       </para>
      </listitem>
      <listitem>
       <para>
        Write in comment if you have tested your patch. Do not rely much on <command>TravisCI</command>.
       </para>
      </listitem>
      <listitem>
       <para>
        If you make an improvement, write about your motivation.
       </para>
      </listitem>
      <listitem>
       <para>
        Notify maintainers of the package. For example add to the message: <command>cc @jagajaga @domenkozar</command>.
       </para>
      </listitem>
     </itemizedlist>
    </para>
   </listitem>
  </itemizedlist>
 </section>
 <section xml:id="submitting-changes-submitting-security-fixes">
  <title>Submitting security fixes</title>

  <para>
   Security fixes are submitted in the same way as other changes and thus the same guidelines apply.
  </para>

  <para>
   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.:
  </para>

<programlisting>
   (fetchpatch {
     name = "CVE-2019-11068.patch";
     url = "https://gitlab.gnome.org/GNOME/libxslt/commit/e03553605b45c88f0b4b2980adfbbb8f6fca2fd6.patch";
     sha256 = "0pkpb4837km15zgg6h57bncp66d5lwrlvkr73h0lanywq7zrwhj8";
   })
  </programlisting>

  <para>
   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.
  </para>

  <para>
   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>.
  </para>
 </section>
 <section xml:id="submitting-changes-pull-request-template">
  <title>Pull Request Template</title>

  <para>
   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.
  </para>

  <para>
   When a PR is created, it will be pre-populated with some checkboxes detailed below:
  </para>

  <section xml:id="submitting-changes-tested-with-sandbox">
   <title>Tested using sandboxing</title>

   <para>
    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
      xlink:href="https://nixos.org/nix/manual/#conf-sandbox">sandbox</link> in Nix manual for details.
   </para>

   <para>
    Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for <link
        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
        xlink:href="https://nixos.org/hydra/">https://nixos.org/hydra/</link> sandboxing is also used.
   </para>

   <para>
    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:
    <itemizedlist>
     <listitem>
      <para>
       <emphasis role="bold">Globally enable sandboxing on NixOS</emphasis>: add the following to <filename>configuration.nix</filename>
<screen>nix.useSandbox = true;</screen>
      </para>
     </listitem>
     <listitem>
      <para>
       <emphasis role="bold">Globally enable sandboxing on non-NixOS platforms</emphasis>: add the following to: <filename>/etc/nix/nix.conf</filename>
<screen>sandbox = true</screen>
      </para>
     </listitem>
    </itemizedlist>
   </para>
  </section>

  <section xml:id="submitting-changes-platform-diversity">
   <title>Built on platform(s)</title>

   <para>
    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.
   </para>
  </section>

  <section xml:id="submitting-changes-nixos-tests">
   <title>Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)</title>

   <para>
    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
        xlink:href="https://nixos.org/nixos/manual/index.html#sec-nixos-tests">section in the NixOS manual</link>.
   </para>
  </section>

  <section xml:id="submitting-changes-tested-compilation">
   <title>Tested compilation of all pkgs that depend on this change using <command>nixpkgs-review</command></title>

   <para>
    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.
   </para>

   <para>
    review changes from pull request number 12345:
    <screen>nix run nixpkgs.nixpkgs-review -c nixpkgs-review pr 12345</screen>
   </para>

   <para>
    review uncommitted changes:
    <screen>nix run nixpkgs.nixpkgs-review -c nixpkgs-review wip</screen>
   </para>

   <para>
    review changes from last commit:
    <screen>nix run nixpkgs.nixpkgs-review -c nixpkgs-review rev HEAD</screen>
   </para>
  </section>

  <section xml:id="submitting-changes-tested-execution">
   <title>Tested execution of all binary files (usually in <filename>./result/bin/</filename>)</title>

   <para>
    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.
   </para>
  </section>

  <section xml:id="submitting-changes-contribution-standards">
   <title>Meets Nixpkgs contribution standards</title>

   <para>
    The last checkbox is fits <link
        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.
   </para>
  </section>
 </section>
 <section xml:id="submitting-changes-hotfixing-pull-requests">
  <title>Hotfixing pull requests</title>

  <itemizedlist>
   <listitem>
    <para>
     Make the appropriate changes in you branch.
    </para>
   </listitem>
   <listitem>
    <para>
     Don't create additional commits, do
     <itemizedlist>
      <listitem>
       <para>
        <command>git rebase -i</command>
       </para>
      </listitem>
      <listitem>
       <para>
        <command>git push --force</command> to your branch.
       </para>
      </listitem>
     </itemizedlist>
    </para>
   </listitem>
  </itemizedlist>
 </section>
 <section xml:id="submitting-changes-commit-policy">
  <title>Commit policy</title>

  <itemizedlist>
   <listitem>
    <para>
     Commits must be sufficiently tested before being merged, both for the master and staging branches.
    </para>
   </listitem>
   <listitem>
    <para>
     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.
    </para>
   </listitem>
   <listitem>
    <para>
     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.
    </para>
   </listitem>
  </itemizedlist>

  <section xml:id="submitting-changes-master-branch">
   <title>Master branch</title>
   <para>
    The <literal>master</literal> branch is the main development branch.
    It should only see non-breaking commits that do not cause mass rebuilds.
   </para>
  </section>

  <section xml:id="submitting-changes-staging-branch">
   <title>Staging branch</title>
   <para>
    The <literal>staging</literal> 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.
   </para>
  </section>

  <section xml:id="submitting-changes-staging-next-branch">
   <title>Staging-next branch</title>
   <para>
    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>.
    Mass-rebuilds should go via the <literal>staging</literal> branch.
    It should only see non-breaking commits that are fixing issues blocking it from being merged into the <literal>master </literal> branch.
   </para>
   <para>
    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.
   </para>
  </section>

  <section xml:id="submitting-changes-stable-release-branches">
   <title>Stable release branches</title>

   <itemizedlist>
    <listitem>
     <para>
      If you're cherry-picking a commit to a stable release branch (“backporting”), always use <command>git cherry-pick -xe</command> and ensure the message contains a clear description about why this needs to be included in the stable branch.
     </para>
     <para>
      An example of a cherry-picked commit would look like this:
     </para>
<screen>
nixos: Refactor the world.

The original commit message describing the reason why the world was torn apart.

(cherry picked from commit abcdef)
Reason: I just had a gut feeling that this would also be wanted by people from
the stone age.
</screen>
    </listitem>
   </itemizedlist>
  </section>
 </section>
</chapter>