nixpkgs/doc/contributing/submitting-changes.xml

456 lines
17 KiB
XML
Raw Normal View History

<chapter xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xml:id="chap-submitting-changes">
2018-05-02 01:54:21 +02:00
<title>Submitting changes</title>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-making-patches">
2018-05-02 01:54:21 +02:00
<title>Making patches</title>
2018-05-02 01:54:21 +02:00
<itemizedlist>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
Read <link xlink:href="https://nixos.org/nixpkgs/manual/">Manual (How to write packages for Nix)</link>.
2018-05-02 01:54:21 +02:00
</para>
</listitem>
<listitem>
<para>
Fork <link xlink:href="https://github.com/nixos/nixpkgs/">the Nixpkgs repository</link> on GitHub.
2018-05-02 01:54:21 +02:00
</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. For example
<screen>
<prompt>$ </prompt>nixos-version --hash
0998212
2019-06-17 13:25:50 +02:00
<prompt>$ </prompt>git checkout 0998212
<prompt>$ </prompt>git checkout -b 'fix/pkg-name-update'
</screen>
2018-05-02 01:54:21 +02:00
</para>
</listitem>
<listitem>
<para>
Please avoid working directly on the <command>master</command> branch.
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
<listitem>
2017-08-26 17:21:29 +02:00
<para>
2018-05-02 01:54:21 +02:00
Make commits of logical units.
</para>
</listitem>
<listitem>
<para>
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>.
2017-08-26 17:21:29 +02:00
</para>
2018-05-02 01:54:21 +02:00
</listitem>
<listitem>
2017-08-26 17:21:29 +02:00
<para>
2019-09-18 22:12:54 +02:00
Check for unnecessary whitespace with <command>git diff --check</command> before committing.
2017-08-26 17:21:29 +02:00
</para>
2018-05-02 01:54:21 +02:00
</listitem>
<listitem>
2017-08-26 17:21:29 +02:00
<para>
2018-05-02 01:54:21 +02:00
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>
2017-08-26 17:21:29 +02:00
<listitem>
2018-05-02 01:54:21 +02:00
<para>
<command>nginx: init at 2.0.1</command>
</para>
2017-08-26 17:21:29 +02:00
</listitem>
<listitem>
2018-05-02 01:54:21 +02:00
<para>
<command>firefox: 54.0.1 -> 55.0</command>
</para>
2017-08-26 17:21:29 +02:00
</listitem>
2018-05-02 01:54:21 +02:00
<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>
2017-08-26 17:21:29 +02:00
<para>
2018-05-02 01:54:21 +02:00
Test your changes. If you work with
<itemizedlist>
<listitem>
<para>
nixpkgs:
<itemizedlist>
<listitem>
<para>
update pkg ->
<itemizedlist>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
<command>nix-env -i pkg-name -f &lt;path to your local nixpkgs folder&gt;</command>
2018-05-02 01:54:21 +02:00
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
<listitem>
<para>
add pkg ->
<itemizedlist>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
Make sure it's in <command>pkgs/top-level/all-packages.nix</command>
2018-05-02 01:54:21 +02:00
</para>
</listitem>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
<command>nix-env -i pkg-name -f &lt;path to your local nixpkgs folder&gt;</command>
2018-05-02 01:54:21 +02:00
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
<emphasis>If you don't want to install pkg in you profile</emphasis>.
2018-05-02 01:54:21 +02:00
<itemizedlist>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
<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>.
2018-05-02 01:54:21 +02:00
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
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.
2018-05-02 01:54:21 +02:00
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
<listitem>
<para>
NixOS and its modules:
<itemizedlist>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
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>.
2018-05-02 01:54:21 +02:00
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
</itemizedlist>
2017-08-26 17:21:29 +02:00
</para>
2018-05-02 01:54:21 +02:00
</listitem>
<listitem>
2017-08-26 17:21:29 +02:00
<para>
2019-09-18 22:12:54 +02:00
If you have commits <command>pkg-name: oh, forgot to insert whitespace</command>: squash commits in this case. Use <command>git rebase -i</command>.
2017-08-26 17:21:29 +02:00
</para>
2018-05-02 01:54:21 +02:00
</listitem>
<listitem>
2017-08-26 17:21:29 +02:00
<para>
<link xlink:href="https://git-scm.com/book/en/v2/Git-Branching-Rebasing">Rebase</link> your branch against current <command>master</command>.
2017-08-26 17:21:29 +02:00
</para>
2018-05-02 01:54:21 +02:00
</listitem>
</itemizedlist>
</section>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-submitting-changes">
2018-05-02 01:54:21 +02:00
<title>Submitting changes</title>
<itemizedlist>
<listitem>
2017-08-26 17:21:29 +02:00
<para>
2018-05-02 01:54:21 +02:00
Push your changes to your fork of nixpkgs.
2017-08-26 17:21:29 +02:00
</para>
2018-05-02 01:54:21 +02:00
</listitem>
<listitem>
2017-08-26 17:21:29 +02:00
<para>
Create the pull request
</para>
</listitem>
<listitem>
<para>
Follow <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/.github/CONTRIBUTING.md#submitting-changes">the contribution guidelines</link>.
2017-08-26 17:21:29 +02:00
</para>
2018-05-02 01:54:21 +02:00
</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>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-pull-request-template">
2018-05-02 01:54:21 +02:00
<title>Pull Request Template</title>
<para>
2019-09-18 22:12:54 +02:00
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.
2018-05-02 01:54:21 +02:00
</para>
<para>
2019-09-18 22:12:54 +02:00
When a PR is created, it will be pre-populated with some checkboxes detailed below:
2018-05-02 01:54:21 +02:00
</para>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-tested-with-sandbox">
2018-05-02 01:54:21 +02:00
<title>Tested using sandboxing</title>
<para>
2019-09-18 22:12:54 +02:00
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.
2018-05-02 01:54:21 +02:00
</para>
<para>
2019-09-18 22:12:54 +02:00
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.
2018-05-02 01:54:21 +02:00
</para>
<para>
2019-09-18 22:12:54 +02:00
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:
2018-05-02 01:54:21 +02:00
<itemizedlist>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
<emphasis role="bold">Globally enable sandboxing on NixOS</emphasis>: add the following to <filename>configuration.nix</filename>
2018-05-02 01:54:21 +02:00
<screen>nix.useSandbox = true;</screen>
</para>
</listitem>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
<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>
2018-05-02 01:54:21 +02:00
</para>
</listitem>
</itemizedlist>
</para>
2017-08-26 17:21:29 +02:00
</section>
2018-05-02 01:54:21 +02:00
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-platform-diversity">
2018-05-02 01:54:21 +02:00
<title>Built on platform(s)</title>
<para>
2019-09-18 22:12:54 +02:00
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.
2018-05-02 01:54:21 +02:00
</para>
2017-08-26 17:21:29 +02:00
</section>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-nixos-tests">
2018-05-02 01:54:21 +02:00
<title>Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)</title>
<para>
2019-09-18 22:12:54 +02:00
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>.
2018-05-02 01:54:21 +02:00
</para>
</section>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-tested-compilation">
<title>Tested compilation of all pkgs that depend on this change using <command>nixpkgs-review</command></title>
2018-05-02 01:54:21 +02:00
<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.
2018-05-02 01:54:21 +02:00
</para>
<para>
2019-03-24 21:33:46 +01:00
review changes from pull request number 12345:
<screen>nix run nixpkgs.nixpkgs-review -c nixpkgs-review pr 12345</screen>
2018-05-02 01:54:21 +02:00
</para>
<para>
2019-03-24 21:33:46 +01:00
review uncommitted changes:
<screen>nix run nixpkgs.nixpkgs-review -c nixpkgs-review wip</screen>
2018-05-02 01:54:21 +02:00
</para>
<para>
review changes from last commit:
<screen>nix run nixpkgs.nixpkgs-review -c nixpkgs-review rev HEAD</screen>
</para>
</section>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-tested-execution">
2018-05-02 01:54:21 +02:00
<title>Tested execution of all binary files (usually in <filename>./result/bin/</filename>)</title>
<para>
2019-09-18 22:12:54 +02:00
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.
2018-05-02 01:54:21 +02:00
</para>
</section>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-contribution-standards">
<title>Meets Nixpkgs contribution standards</title>
2018-05-02 01:54:21 +02:00
<para>
2019-09-18 22:12:54 +02:00
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.
2018-05-02 01:54:21 +02:00
</para>
</section>
</section>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-hotfixing-pull-requests">
2018-05-02 01:54:21 +02:00
<title>Hotfixing pull requests</title>
2018-05-02 01:54:21 +02:00
<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>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-commit-policy">
2018-05-02 01:54:21 +02:00
<title>Commit policy</title>
2018-05-02 01:54:21 +02:00
<itemizedlist>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
Commits must be sufficiently tested before being merged, both for the master and staging branches.
2018-05-02 01:54:21 +02:00
</para>
</listitem>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
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.
2018-05-02 01:54:21 +02:00
</para>
</listitem>
<listitem>
<para>
2019-09-18 22:12:54 +02:00
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.
2018-05-02 01:54:21 +02:00
</para>
</listitem>
</itemizedlist>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-master-branch">
2018-05-02 01:54:21 +02:00
<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>
2018-05-02 01:54:21 +02:00
</section>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-staging-branch">
2018-05-02 01:54:21 +02:00
<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>
2018-05-02 01:54:21 +02:00
</section>
2018-09-01 21:06:38 +02:00
<section xml:id="submitting-changes-stable-release-branches">
2018-05-02 01:54:21 +02:00
<title>Stable release branches</title>
<para>
For cherry-picking a commit to a stable release branch (<quote>backporting</quote>), use <literal>git cherry-pick -x &lt;original commit&gt;</literal> so that the original commit id is included in the commit.
</para>
<para>
Add a reason for the backport by using <literal>git cherry-pick -xe &lt;original commit&gt;</literal> instead when it is not obvious from the original commit message. It is not needed when its a minor version update that includes security and bug fixes but dont add new features or when the commit fixes an otherwise broken package.
</para>
<para>
Here is an example of a cherry-picked commit message with good reason description:
</para>
<screen>
zfs: Keep trying root import until it works
Works around #11003.
(cherry picked from commit 98b213a11041af39b39473906b595290e2a4e2f9)
Reason: several people cannot boot with ZFS on NVMe
</screen>
<para>
Other examples of reasons are:
</para>
<itemizedlist spacing="compact">
<listitem>
2018-05-02 01:54:21 +02:00
<para>
Previously the build would fail due to, e.g., <literal>getaddrinfo</literal> not being defined
2018-05-02 01:54:21 +02:00
</para>
</listitem>
<listitem>
2018-05-02 01:54:21 +02:00
<para>
The previous download links were all broken
</para>
</listitem>
<listitem>
<para>
Crash when starting on some X11 systems
2018-05-02 01:54:21 +02:00
</para>
</listitem>
2018-05-02 01:54:21 +02:00
</itemizedlist>
</section>
</section>
</chapter>