at 18.09-beta 17 kB view raw
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 12 write packages for Nix)</link>. 13 </para> 14 </listitem> 15 <listitem> 16 <para> 17 Fork the repository on GitHub. 18 </para> 19 </listitem> 20 <listitem> 21 <para> 22 Create a branch for your future fix. 23 <itemizedlist> 24 <listitem> 25 <para> 26 You can make branch from a commit of your local 27 <command>nixos-version</command>. That will help you to avoid 28 additional local compilations. Because you will receive packages from 29 binary cache. 30 <itemizedlist> 31 <listitem> 32 <para> 33 For example: <command>nixos-version</command> returns 34 <command>15.05.git.0998212 (Dingo)</command>. So you can do: 35 </para> 36 </listitem> 37 </itemizedlist> 38<screen> 39$ git checkout 0998212 40$ git checkout -b 'fix/pkg-name-update' 41</screen> 42 </para> 43 </listitem> 44 <listitem> 45 <para> 46 Please avoid working directly on the <command>master</command> branch. 47 </para> 48 </listitem> 49 </itemizedlist> 50 </para> 51 </listitem> 52 <listitem> 53 <para> 54 Make commits of logical units. 55 <itemizedlist> 56 <listitem> 57 <para> 58 If you removed pkgs, made some major NixOS changes etc., write about 59 them in 60 <command>nixos/doc/manual/release-notes/rl-unstable.xml</command>. 61 </para> 62 </listitem> 63 </itemizedlist> 64 </para> 65 </listitem> 66 <listitem> 67 <para> 68 Check for unnecessary whitespace with <command>git diff --check</command> 69 before committing. 70 </para> 71 </listitem> 72 <listitem> 73 <para> 74 Format the commit in a following way: 75 </para> 76<programlisting> 77(pkg-name | nixos/&lt;module>): (from -> to | init at version | refactor | etc) 78Additional information. 79</programlisting> 80 <itemizedlist> 81 <listitem> 82 <para> 83 Examples: 84 <itemizedlist> 85 <listitem> 86 <para> 87 <command>nginx: init at 2.0.1</command> 88 </para> 89 </listitem> 90 <listitem> 91 <para> 92 <command>firefox: 54.0.1 -> 55.0</command> 93 </para> 94 </listitem> 95 <listitem> 96 <para> 97 <command>nixos/hydra: add bazBaz option</command> 98 </para> 99 </listitem> 100 <listitem> 101 <para> 102 <command>nixos/nginx: refactor config generation</command> 103 </para> 104 </listitem> 105 </itemizedlist> 106 </para> 107 </listitem> 108 </itemizedlist> 109 </listitem> 110 <listitem> 111 <para> 112 Test your changes. If you work with 113 <itemizedlist> 114 <listitem> 115 <para> 116 nixpkgs: 117 <itemizedlist> 118 <listitem> 119 <para> 120 update pkg -> 121 <itemizedlist> 122 <listitem> 123 <para> 124 <command>nix-env -i pkg-name -f &lt;path to your local nixpkgs 125 folder&gt;</command> 126 </para> 127 </listitem> 128 </itemizedlist> 129 </para> 130 </listitem> 131 <listitem> 132 <para> 133 add pkg -> 134 <itemizedlist> 135 <listitem> 136 <para> 137 Make sure it's in 138 <command>pkgs/top-level/all-packages.nix</command> 139 </para> 140 </listitem> 141 <listitem> 142 <para> 143 <command>nix-env -i pkg-name -f &lt;path to your local nixpkgs 144 folder&gt;</command> 145 </para> 146 </listitem> 147 </itemizedlist> 148 </para> 149 </listitem> 150 <listitem> 151 <para> 152 <emphasis>If you don't want to install pkg in you 153 profile</emphasis>. 154 <itemizedlist> 155 <listitem> 156 <para> 157 <command>nix-build -A pkg-attribute-name &lt;path to your local 158 nixpkgs folder&gt;/default.nix</command> and check results in the 159 folder <command>result</command>. It will appear in the same 160 directory where you did <command>nix-build</command>. 161 </para> 162 </listitem> 163 </itemizedlist> 164 </para> 165 </listitem> 166 <listitem> 167 <para> 168 If you did <command>nix-env -i pkg-name</command> you can do 169 <command>nix-env -e pkg-name</command> to uninstall it from your 170 system. 171 </para> 172 </listitem> 173 </itemizedlist> 174 </para> 175 </listitem> 176 <listitem> 177 <para> 178 NixOS and its modules: 179 <itemizedlist> 180 <listitem> 181 <para> 182 You can add new module to your NixOS configuration file (usually 183 it's <command>/etc/nixos/configuration.nix</command>). And do 184 <command>sudo nixos-rebuild test -I nixpkgs=&lt;path to your local 185 nixpkgs folder&gt; --fast</command>. 186 </para> 187 </listitem> 188 </itemizedlist> 189 </para> 190 </listitem> 191 </itemizedlist> 192 </para> 193 </listitem> 194 <listitem> 195 <para> 196 If you have commits <command>pkg-name: oh, forgot to insert 197 whitespace</command>: squash commits in this case. Use <command>git rebase 198 -i</command>. 199 </para> 200 </listitem> 201 <listitem> 202 <para> 203 Rebase you branch against current <command>master</command>. 204 </para> 205 </listitem> 206 </itemizedlist> 207 </section> 208 <section xml:id="submitting-changes-submitting-changes"> 209 <title>Submitting changes</title> 210 211 <itemizedlist> 212 <listitem> 213 <para> 214 Push your changes to your fork of nixpkgs. 215 </para> 216 </listitem> 217 <listitem> 218 <para> 219 Create pull request: 220 <itemizedlist> 221 <listitem> 222 <para> 223 Write the title in format <command>(pkg-name | nixos/&lt;module>): 224 improvement</command>. 225 <itemizedlist> 226 <listitem> 227 <para> 228 If you update the pkg, write versions <command>from -> to</command>. 229 </para> 230 </listitem> 231 </itemizedlist> 232 </para> 233 </listitem> 234 <listitem> 235 <para> 236 Write in comment if you have tested your patch. Do not rely much on 237 <command>TravisCI</command>. 238 </para> 239 </listitem> 240 <listitem> 241 <para> 242 If you make an improvement, write about your motivation. 243 </para> 244 </listitem> 245 <listitem> 246 <para> 247 Notify maintainers of the package. For example add to the message: 248 <command>cc @jagajaga @domenkozar</command>. 249 </para> 250 </listitem> 251 </itemizedlist> 252 </para> 253 </listitem> 254 </itemizedlist> 255 </section> 256 <section xml:id="submitting-changes-pull-request-template"> 257 <title>Pull Request Template</title> 258 259 <para> 260 The pull request template helps determine what steps have been made for a 261 contribution so far, and will help guide maintainers on the status of a 262 change. The motivation section of the PR should include any extra details 263 the title does not address and link any existing issues related to the pull 264 request. 265 </para> 266 267 <para> 268 When a PR is created, it will be pre-populated with some checkboxes detailed 269 below: 270 </para> 271 272 <section xml:id="submitting-changes-tested-with-sandbox"> 273 <title>Tested using sandboxing</title> 274 275 <para> 276 When sandbox builds are enabled, Nix will setup an isolated environment for 277 each build process. It is used to remove further hidden dependencies set by 278 the build environment to improve reproducibility. This includes access to 279 the network during the build outside of <function>fetch*</function> 280 functions and files outside the Nix store. Depending on the operating 281 system access to other resources are blocked as well (ex. inter process 282 communication is isolated on Linux); see 283 <link 284 xlink:href="https://nixos.org/nix/manual/#description-45">build-use-sandbox</link> 285 in Nix manual for details. 286 </para> 287 288 <para> 289 Sandboxing is not enabled by default in Nix due to a small performance hit 290 on each build. In pull requests for 291 <link 292 xlink:href="https://github.com/NixOS/nixpkgs/">nixpkgs</link> 293 people are asked to test builds with sandboxing enabled (see 294 <literal>Tested using sandboxing</literal> in the pull request template) 295 because 296 in<link 297 xlink:href="https://nixos.org/hydra/">https://nixos.org/hydra/</link> 298 sandboxing is also used. 299 </para> 300 301 <para> 302 Depending if you use NixOS or other platforms you can use one of the 303 following methods to enable sandboxing 304 <emphasis role="bold">before</emphasis> building the package: 305 <itemizedlist> 306 <listitem> 307 <para> 308 <emphasis role="bold">Globally enable sandboxing on NixOS</emphasis>: 309 add the following to <filename>configuration.nix</filename> 310<screen>nix.useSandbox = true;</screen> 311 </para> 312 </listitem> 313 <listitem> 314 <para> 315 <emphasis role="bold">Globally enable sandboxing on non-NixOS 316 platforms</emphasis>: add the following to: 317 <filename>/etc/nix/nix.conf</filename> 318<screen>build-use-sandbox = true</screen> 319 </para> 320 </listitem> 321 </itemizedlist> 322 </para> 323 </section> 324 325 <section xml:id="submitting-changes-platform-diversity"> 326 <title>Built on platform(s)</title> 327 328 <para> 329 Many Nix packages are designed to run on multiple platforms. As such, it's 330 important to let the maintainer know which platforms your changes have been 331 tested on. It's not always practical to test a change on all platforms, and 332 is not required for a pull request to be merged. Only check the systems you 333 tested the build on in this section. 334 </para> 335 </section> 336 337 <section xml:id="submitting-changes-nixos-tests"> 338 <title>Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)</title> 339 340 <para> 341 Packages with automated tests are much more likely to be merged in a timely 342 fashion because it doesn't require as much manual testing by the maintainer 343 to verify the functionality of the package. If there are existing tests for 344 the package, they should be run to verify your changes do not break the 345 tests. Tests only apply to packages with NixOS modules defined and can only 346 be run on Linux. For more details on writing and running tests, see the 347 <link 348 xlink:href="https://nixos.org/nixos/manual/index.html#sec-nixos-tests">section 349 in the NixOS manual</link>. 350 </para> 351 </section> 352 353 <section xml:id="submitting-changes-tested-compilation"> 354 <title>Tested compilation of all pkgs that depend on this change using <command>nox-review</command></title> 355 356 <para> 357 If you are updating a package's version, you can use nox to make sure all 358 packages that depend on the updated package still compile correctly. This 359 can be done using the nox utility. The <command>nox-review</command> 360 utility can look for and build all dependencies either based on uncommited 361 changes with the <literal>wip</literal> option or specifying a github pull 362 request number. 363 </para> 364 365 <para> 366 review uncommitted changes: 367<screen>nix-shell -p nox --run "nox-review wip"</screen> 368 </para> 369 370 <para> 371 review changes from pull request number 12345: 372<screen>nix-shell -p nox --run "nox-review pr 12345"</screen> 373 </para> 374 </section> 375 376 <section xml:id="submitting-changes-tested-execution"> 377 <title>Tested execution of all binary files (usually in <filename>./result/bin/</filename>)</title> 378 379 <para> 380 It's important to test any executables generated by a build when you change 381 or create a package in nixpkgs. This can be done by looking in 382 <filename>./result/bin</filename> and running any files in there, or at a 383 minimum, the main executable for the package. For example, if you make a 384 change to <package>texlive</package>, you probably would only check the 385 binaries associated with the change you made rather than testing all of 386 them. 387 </para> 388 </section> 389 390 <section xml:id="submitting-changes-contribution-standards"> 391 <title>Meets Nixpkgs contribution standards</title> 392 393 <para> 394 The last checkbox is fits 395 <link 396 xlink:href="https://github.com/NixOS/nixpkgs/blob/master/.github/CONTRIBUTING.md">CONTRIBUTING.md</link>. 397 The contributing document has detailed information on standards the Nix 398 community has for commit messages, reviews, licensing of contributions you 399 make to the project, etc... Everyone should read and understand the 400 standards the community has for contributing before submitting a pull 401 request. 402 </para> 403 </section> 404 </section> 405 <section xml:id="submitting-changes-hotfixing-pull-requests"> 406 <title>Hotfixing pull requests</title> 407 408 <itemizedlist> 409 <listitem> 410 <para> 411 Make the appropriate changes in you branch. 412 </para> 413 </listitem> 414 <listitem> 415 <para> 416 Don't create additional commits, do 417 <itemizedlist> 418 <listitem> 419 <para> 420 <command>git rebase -i</command> 421 </para> 422 </listitem> 423 <listitem> 424 <para> 425 <command>git push --force</command> to your branch. 426 </para> 427 </listitem> 428 </itemizedlist> 429 </para> 430 </listitem> 431 </itemizedlist> 432 </section> 433 <section xml:id="submitting-changes-commit-policy"> 434 <title>Commit policy</title> 435 436 <itemizedlist> 437 <listitem> 438 <para> 439 Commits must be sufficiently tested before being merged, both for the 440 master and staging branches. 441 </para> 442 </listitem> 443 <listitem> 444 <para> 445 Hydra builds for master and staging should not be used as testing 446 platform, it's a build farm for changes that have been already tested. 447 </para> 448 </listitem> 449 <listitem> 450 <para> 451 When changing the bootloader installation process, extra care must be 452 taken. Grub installations cannot be rolled back, hence changes may break 453 people's installations forever. For any non-trivial change to the 454 bootloader please file a PR asking for review, especially from @edolstra. 455 </para> 456 </listitem> 457 </itemizedlist> 458 459 <section xml:id="submitting-changes-master-branch"> 460 <title>Master branch</title> 461 462 <itemizedlist> 463 <listitem> 464 <para> 465 It should only see non-breaking commits that do not cause mass rebuilds. 466 </para> 467 </listitem> 468 </itemizedlist> 469 </section> 470 471 <section xml:id="submitting-changes-staging-branch"> 472 <title>Staging branch</title> 473 474 <itemizedlist> 475 <listitem> 476 <para> 477 It's only for non-breaking mass-rebuild commits. That means it's not to 478 be used for testing, and changes must have been well tested already. 479 <link xlink:href="https://web.archive.org/web/20160528180406/http://comments.gmane.org/gmane.linux.distributions.nixos/13447">Read 480 policy here</link>. 481 </para> 482 </listitem> 483 <listitem> 484 <para> 485 If the branch is already in a broken state, please refrain from adding 486 extra new breakages. Stabilize it for a few days, merge into master, then 487 resume development on staging. 488 <link xlink:href="http://hydra.nixos.org/jobset/nixpkgs/staging#tabs-evaluations">Keep 489 an eye on the staging evaluations here</link>. If any fixes for staging 490 happen to be already in master, then master can be merged into staging. 491 </para> 492 </listitem> 493 </itemizedlist> 494 </section> 495 496 <section xml:id="submitting-changes-stable-release-branches"> 497 <title>Stable release branches</title> 498 499 <itemizedlist> 500 <listitem> 501 <para> 502 If you're cherry-picking a commit to a stable release branch, always use 503 <command>git cherry-pick -xe</command> and ensure the message contains a 504 clear description about why this needs to be included in the stable 505 branch. 506 </para> 507 <para> 508 An example of a cherry-picked commit would look like this: 509 </para> 510<screen> 511nixos: Refactor the world. 512 513The original commit message describing the reason why the world was torn apart. 514 515(cherry picked from commit abcdef) 516Reason: I just had a gut feeling that this would also be wanted by people from 517the stone age. 518 </screen> 519 </listitem> 520 </itemizedlist> 521 </section> 522 </section> 523</chapter>