From ddbf4c1bac20f6061d4b42a901545eaf345067df Mon Sep 17 00:00:00 2001 From: Frederik Rietdijk Date: Wed, 30 Oct 2019 10:27:47 +0100 Subject: nixpkgs manual: move contributing chapters into one folder --- doc/contributing/coding-conventions.xml | 903 +++++++++++++++++++++ doc/contributing/contributing-to-documentation.xml | 30 + doc/contributing/quick-start.xml | 153 ++++ doc/contributing/reviewing-contributions.xml | 536 ++++++++++++ doc/contributing/submitting-changes.xml | 429 ++++++++++ 5 files changed, 2051 insertions(+) create mode 100644 doc/contributing/coding-conventions.xml create mode 100644 doc/contributing/contributing-to-documentation.xml create mode 100644 doc/contributing/quick-start.xml create mode 100644 doc/contributing/reviewing-contributions.xml create mode 100644 doc/contributing/submitting-changes.xml (limited to 'doc/contributing') diff --git a/doc/contributing/coding-conventions.xml b/doc/contributing/coding-conventions.xml new file mode 100644 index 00000000000..799f1479467 --- /dev/null +++ b/doc/contributing/coding-conventions.xml @@ -0,0 +1,903 @@ + + Coding conventions +
+ Syntax + + + + + Use 2 spaces of indentation per indentation level in Nix expressions, 4 spaces in shell scripts. + + + + + Do not use tab characters, i.e. configure your editor to use soft tabs. For instance, use (setq-default indent-tabs-mode nil) in Emacs. Everybody has different tab settings so it’s asking for trouble. + + + + + Use lowerCamelCase for variable names, not UpperCamelCase. Note, this rule does not apply to package attribute names, which instead follow the rules in . + + + + + Function calls with attribute set arguments are written as + +foo { + arg = ...; +} + + not + +foo +{ + arg = ...; +} + + Also fine is + +foo { arg = ...; } + + if it's a short call. + + + + + In attribute sets or lists that span multiple lines, the attribute names or list elements should be aligned: + +# A long list. +list = [ + elem1 + elem2 + elem3 +]; + +# A long attribute set. +attrs = { + attr1 = short_expr; + attr2 = + if true then big_expr else big_expr; +}; + +# Combined +listOfAttrs = [ + { + attr1 = 3; + attr2 = "fff"; + } + { + attr1 = 5; + attr2 = "ggg"; + } +]; + + + + + + Short lists or attribute sets can be written on one line: + +# A short list. +list = [ elem1 elem2 elem3 ]; + +# A short set. +attrs = { x = 1280; y = 1024; }; + + + + + + Breaking in the middle of a function argument can give hard-to-read code, like + +someFunction { x = 1280; + y = 1024; } otherArg + yetAnotherArg + + (especially if the argument is very large, spanning multiple lines). + + + Better: + +someFunction + { x = 1280; y = 1024; } + otherArg + yetAnotherArg + + or + +let res = { x = 1280; y = 1024; }; +in someFunction res otherArg yetAnotherArg + + + + + + The bodies of functions, asserts, and withs are not indented to prevent a lot of superfluous indentation levels, i.e. + +{ arg1, arg2 }: +assert system == "i686-linux"; +stdenv.mkDerivation { ... + + not + +{ arg1, arg2 }: + assert system == "i686-linux"; + stdenv.mkDerivation { ... + + + + + + Function formal arguments are written as: + +{ arg1, arg2, arg3 }: + + but if they don't fit on one line they're written as: + +{ arg1, arg2, arg3 +, arg4, ... +, # Some comment... + argN +}: + + + + + + Functions should list their expected arguments as precisely as possible. That is, write + +{ stdenv, fetchurl, perl }: ... + + instead of + +args: with args; ... + + or + +{ stdenv, fetchurl, perl, ... }: ... + + + + For functions that are truly generic in the number of arguments (such as wrappers around mkDerivation) that have some required arguments, you should write them using an @-pattern: + +{ stdenv, doCoverageAnalysis ? false, ... } @ args: + +stdenv.mkDerivation (args // { + ... if doCoverageAnalysis then "bla" else "" ... +}) + + instead of + +args: + +args.stdenv.mkDerivation (args // { + ... if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else "" ... +}) + + + + +
+
+ Package naming + + + The key words must, must not, required, shall, shall not, should, should not, recommended, may, and optional in this section are to be interpreted as described in RFC 2119. Only emphasized words are to be interpreted in this way. + + + + In Nixpkgs, there are generally three different names associated with a package: + + + + The name attribute of the derivation (excluding the version part). This is what most users see, in particular when using nix-env. + + + + + The variable name used for the instantiated package in all-packages.nix, and when passing it as a dependency to other functions. Typically this is called the package attribute name. This is what Nix expression authors see. It can also be used when installing using nix-env -iA. + + + + + The filename for (the directory containing) the Nix expression. + + + + Most of the time, these are the same. For instance, the package e2fsprogs has a name attribute "e2fsprogs-version", is bound to the variable name e2fsprogs in all-packages.nix, and the Nix expression is in pkgs/os-specific/linux/e2fsprogs/default.nix. + + + + There are a few naming guidelines: + + + + The name attribute should be identical to the upstream package name. + + + + + The name attribute must not contain uppercase letters — e.g., "mplayer-1.0rc2" instead of "MPlayer-1.0rc2". + + + + + The version part of the name attribute must start with a digit (following a dash) — e.g., "hello-0.3.1rc2". + + + + + If a package is not a release but a commit from a repository, then the version part of the name must be the date of that (fetched) commit. The date must be in "YYYY-MM-DD" format. Also append "unstable" to the name - e.g., "pkgname-unstable-2014-09-23". + + + + + Dashes in the package name should be preserved in new variable names, rather than converted to underscores or camel cased — e.g., http-parser instead of http_parser or httpParser. The hyphenated style is preferred in all three package names. + + + + + If there are multiple versions of a package, this should be reflected in the variable names in all-packages.nix, e.g. json-c-0-9 and json-c-0-11. If there is an obvious “default” version, make an attribute like json-c = json-c-0-9;. See also + + + + +
+
+ File naming and organisation + + + Names of files and directories should be in lowercase, with dashes between words — not in camel case. For instance, it should be all-packages.nix, not allPackages.nix or AllPackages.nix. + + +
+ Hierarchy + + + Each package should be stored in its own directory somewhere in the pkgs/ tree, i.e. in pkgs/category/subcategory/.../pkgname. Below are some rules for picking the right category for a package. Many packages fall under several categories; what matters is the primary purpose of a package. For example, the libxml2 package builds both a library and some tools; but it’s a library foremost, so it goes under pkgs/development/libraries. + + + + When in doubt, consider refactoring the pkgs/ tree, e.g. creating new categories or splitting up an existing category. + + + + + + If it’s used to support software development: + + + + + + If it’s a library used by other packages: + + + + development/libraries (e.g. libxml2) + + + + + + If it’s a compiler: + + + + development/compilers (e.g. gcc) + + + + + + If it’s an interpreter: + + + + development/interpreters (e.g. guile) + + + + + + If it’s a (set of) development tool(s): + + + + + + If it’s a parser generator (including lexers): + + + + development/tools/parsing (e.g. bison, flex) + + + + + + If it’s a build manager: + + + + development/tools/build-managers (e.g. gnumake) + + + + + + Else: + + + + development/tools/misc (e.g. binutils) + + + + + + + + + Else: + + + + development/misc + + + + + + + + + If it’s a (set of) tool(s): + + + + (A tool is a relatively small program, especially one intended to be used non-interactively.) + + + + + If it’s for networking: + + + + tools/networking (e.g. wget) + + + + + + If it’s for text processing: + + + + tools/text (e.g. diffutils) + + + + + + If it’s a system utility, i.e., something related or essential to the operation of a system: + + + + tools/system (e.g. cron) + + + + + + If it’s an archiver (which may include a compression function): + + + + tools/archivers (e.g. zip, tar) + + + + + + If it’s a compression program: + + + + tools/compression (e.g. gzip, bzip2) + + + + + + If it’s a security-related program: + + + + tools/security (e.g. nmap, gnupg) + + + + + + Else: + + + + tools/misc + + + + + + + + + If it’s a shell: + + + + shells (e.g. bash) + + + + + + If it’s a server: + + + + + + If it’s a web server: + + + + servers/http (e.g. apache-httpd) + + + + + + If it’s an implementation of the X Windowing System: + + + + servers/x11 (e.g. xorg — this includes the client libraries and programs) + + + + + + Else: + + + + servers/misc + + + + + + + + + If it’s a desktop environment: + + + + desktops (e.g. kde, gnome, enlightenment) + + + + + + If it’s a window manager: + + + + applications/window-managers (e.g. awesome, stumpwm) + + + + + + If it’s an application: + + + + A (typically large) program with a distinct user interface, primarily used interactively. + + + + + If it’s a version management system: + + + + applications/version-management (e.g. subversion) + + + + + + If it’s for video playback / editing: + + + + applications/video (e.g. vlc) + + + + + + If it’s for graphics viewing / editing: + + + + applications/graphics (e.g. gimp) + + + + + + If it’s for networking: + + + + + + If it’s a mailreader: + + + + applications/networking/mailreaders (e.g. thunderbird) + + + + + + If it’s a newsreader: + + + + applications/networking/newsreaders (e.g. pan) + + + + + + If it’s a web browser: + + + + applications/networking/browsers (e.g. firefox) + + + + + + Else: + + + + applications/networking/misc + + + + + + + + + Else: + + + + applications/misc + + + + + + + + + If it’s data (i.e., does not have a straight-forward executable semantics): + + + + + + If it’s a font: + + + + data/fonts + + + + + + If it’s related to SGML/XML processing: + + + + + + If it’s an XML DTD: + + + + data/sgml+xml/schemas/xml-dtd (e.g. docbook) + + + + + + If it’s an XSLT stylesheet: + + + + (Okay, these are executable...) + + + data/sgml+xml/stylesheets/xslt (e.g. docbook-xsl) + + + + + + + + + + + + If it’s a game: + + + + games + + + + + + Else: + + + + misc + + + + +
+ +
+ Versioning + + + Because every version of a package in Nixpkgs creates a potential maintenance burden, old versions of a package should not be kept unless there is a good reason to do so. For instance, Nixpkgs contains several versions of GCC because other packages don’t build with the latest version of GCC. Other examples are having both the latest stable and latest pre-release version of a package, or to keep several major releases of an application that differ significantly in functionality. + + + + If there is only one version of a package, its Nix expression should be named e2fsprogs/default.nix. If there are multiple versions, this should be reflected in the filename, e.g. e2fsprogs/1.41.8.nix and e2fsprogs/1.41.9.nix. The version in the filename should leave out unnecessary detail. For instance, if we keep the latest Firefox 2.0.x and 3.5.x versions in Nixpkgs, they should be named firefox/2.0.nix and firefox/3.5.nix, respectively (which, at a given point, might contain versions 2.0.0.20 and 3.5.4). If a version requires many auxiliary files, you can use a subdirectory for each version, e.g. firefox/2.0/default.nix and firefox/3.5/default.nix. + + + + All versions of a package must be included in all-packages.nix to make sure that they evaluate correctly. + +
+
+
+ Fetching Sources + + + There are multiple ways to fetch a package source in nixpkgs. The general guideline is that you should package reproducible sources with a high degree of availability. Right now there is only one fetcher which has mirroring support and that is fetchurl. Note that you should also prefer protocols which have a corresponding proxy environment variable. + + + + You can find many source fetch helpers in pkgs/build-support/fetch*. + + + + In the file pkgs/top-level/all-packages.nix you can find fetch helpers, these have names on the form fetchFrom*. The intention of these are to provide snapshot fetches but using the same api as some of the version controlled fetchers from pkgs/build-support/. As an example going from bad to good: + + + + Bad: Uses git:// which won't be proxied. + +src = fetchgit { + url = "git://github.com/NixOS/nix.git"; + rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae"; + sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg"; +} + + + + + + Better: This is ok, but an archive fetch will still be faster. + +src = fetchgit { + url = "https://github.com/NixOS/nix.git"; + rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae"; + sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg"; +} + + + + + + Best: Fetches a snapshot archive and you get the rev you want. + +src = fetchFromGitHub { + owner = "NixOS"; + repo = "nix"; + rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae"; + sha256 = "1i2yxndxb6yc9l6c99pypbd92lfq5aac4klq7y2v93c9qvx2cgpc"; +} + + Find the value to put as sha256 by running nix run -f '<nixpkgs>' nix-prefetch-github -c nix-prefetch-github --rev 1f795f9f44607cc5bec70d1300150bfefcef2aae NixOS nix or nix-prefetch-url --unpack https://github.com/NixOS/nix/archive/1f795f9f44607cc5bec70d1300150bfefcef2aae.tar.gz. + + + + +
+
+ Obtaining source hash + + + Preferred source hash type is sha256. There are several ways to get it. + + + + + + Prefetch URL (with nix-prefetch-XXX URL, where XXX is one of url, git, hg, cvs, bzr, svn). Hash is printed to stdout. + + + + + Prefetch by package source (with nix-prefetch-url '<nixpkgs>' -A PACKAGE.src, where PACKAGE is package attribute name). Hash is printed to stdout. + + + This works well when you've upgraded existing package version and want to find out new hash, but is useless if package can't be accessed by attribute or package has multiple sources (.srcs, architecture-dependent sources, etc). + + + + + Upstream provided hash: use it when upstream provides sha256 or sha512 (when upstream provides md5, don't use it, compute sha256 instead). + + + A little nuance is that nix-prefetch-* tools produce hash encoded with base32, but upstream usually provides hexadecimal (base16) encoding. Fetchers understand both formats. Nixpkgs does not standardize on any one format. + + + You can convert between formats with nix-hash, for example: + +$ nix-hash --type sha256 --to-base32 HASH + + + + + + Extracting hash from local source tarball can be done with sha256sum. Use nix-prefetch-url file:///path/to/tarball if you want base32 hash. + + + + + Fake hash: set fake hash in package expression, perform build and extract correct hash from error Nix prints. + + + For package updates it is enough to change one symbol to make hash fake. For new packages, you can use lib.fakeSha256, lib.fakeSha512 or any other fake hash. + + + This is last resort method when reconstructing source URL is non-trivial and nix-prefetch-url -A isn't applicable (for example, one of kodi dependencies). The easiest way then would be replace hash with a fake one and rebuild. Nix build will fail and error message will contain desired hash. + + + + This method has security problems. Check below for details. + + + + + +
+ Obtaining hashes securely + + + Let's say Man-in-the-Middle (MITM) sits close to your network. Then instead of fetching source you can fetch malware, and instead of source hash you get hash of malware. Here are security considerations for this scenario: + + + + + + http:// URLs are not secure to prefetch hash from; + + + + + hashes from upstream (in method 3) should be obtained via secure protocol; + + + + + https:// URLs are secure in methods 1, 2, 3; + + + + + https:// URLs are not secure in method 5. When obtaining hashes with fake hash method, TLS checks are disabled. So refetch source hash from several different networks to exclude MITM scenario. Alternatively, use fake hash method to make Nix error, but instead of extracting hash from error, extract https:// URL and prefetch it with method 1. + + + +
+
+
+ Patches + + + Patches available online should be retrieved using fetchpatch. + + + + +patches = [ + (fetchpatch { + name = "fix-check-for-using-shared-freetype-lib.patch"; + url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=8f5d285"; + sha256 = "1f0k043rng7f0rfl9hhb89qzvvksqmkrikmm38p61yfx51l325xr"; + }) +]; + + + + + Otherwise, you can add a .patch file to the nixpkgs repository. In the interest of keeping our maintenance burden to a minimum, only patches that are unique to nixpkgs should be added in this way. + + + + +patches = [ ./0001-changes.patch ]; + + + + + If you do need to do create this sort of patch file, one way to do so is with git: + + + + Move to the root directory of the source code you're patching. + +$ cd the/program/source + + + + + If a git repository is not already present, create one and stage all of the source files. + +$ git init +$ git add . + + + + + Edit some files to make whatever changes need to be included in the patch. + + + + + Use git to create a diff, and pipe the output to a patch file: + +$ git diff > nixpkgs/pkgs/the/package/0001-changes.patch + + + + +
+
diff --git a/doc/contributing/contributing-to-documentation.xml b/doc/contributing/contributing-to-documentation.xml new file mode 100644 index 00000000000..b0266043775 --- /dev/null +++ b/doc/contributing/contributing-to-documentation.xml @@ -0,0 +1,30 @@ + + Contributing to this documentation + + The DocBook sources of the Nixpkgs manual are in the doc subdirectory of the Nixpkgs repository. + + + You can quickly check your edits with make: + + +$ cd /path/to/nixpkgs/doc +$ nix-shell +[nix-shell]$ make + + + If you experience problems, run make debug to help understand the docbook errors. + + + After making modifications to the manual, it's important to build it before committing. You can do that as follows: + +$ cd /path/to/nixpkgs/doc +$ nix-shell +[nix-shell]$ make clean +[nix-shell]$ nix-build . + + If the build succeeds, the manual will be in ./result/share/doc/nixpkgs/manual.html. + + diff --git a/doc/contributing/quick-start.xml b/doc/contributing/quick-start.xml new file mode 100644 index 00000000000..80514cba490 --- /dev/null +++ b/doc/contributing/quick-start.xml @@ -0,0 +1,153 @@ + + Quick Start to Adding a Package + + To add a package to Nixpkgs: + + + + Checkout the Nixpkgs source tree: + +$ git clone https://github.com/NixOS/nixpkgs +$ cd nixpkgs + + + + + Find a good place in the Nixpkgs tree to add the Nix expression for your package. For instance, a library package typically goes into pkgs/development/libraries/pkgname, while a web browser goes into pkgs/applications/networking/browsers/pkgname. See for some hints on the tree organisation. Create a directory for your package, e.g. + +$ mkdir pkgs/development/libraries/libfoo + + + + + In the package directory, create a Nix expression — a piece of code that describes how to build the package. In this case, it should be a function that is called with the package dependencies as arguments, and returns a build of the package in the Nix store. The expression should usually be called default.nix. + +$ emacs pkgs/development/libraries/libfoo/default.nix +$ git add pkgs/development/libraries/libfoo/default.nix + + + You can have a look at the existing Nix expressions under pkgs/ to see how it’s done. Here are some good ones: + + + + GNU Hello: pkgs/applications/misc/hello/default.nix. Trivial package, which specifies some meta attributes which is good practice. + + + + + GNU cpio: pkgs/tools/archivers/cpio/default.nix. Also a simple package. The generic builder in stdenv does everything for you. It has no dependencies beyond stdenv. + + + + + GNU Multiple Precision arithmetic library (GMP): pkgs/development/libraries/gmp/5.1.x.nix. Also done by the generic builder, but has a dependency on m4. + + + + + Pan, a GTK-based newsreader: pkgs/applications/networking/newsreaders/pan/default.nix. Has an optional dependency on gtkspell, which is only built if spellCheck is true. + + + + + Apache HTTPD: pkgs/servers/http/apache-httpd/2.4.nix. A bunch of optional features, variable substitutions in the configure flags, a post-install hook, and miscellaneous hackery. + + + + + Thunderbird: pkgs/applications/networking/mailreaders/thunderbird/default.nix. Lots of dependencies. + + + + + JDiskReport, a Java utility: pkgs/tools/misc/jdiskreport/default.nix (and the builder). Nixpkgs doesn’t have a decent stdenv for Java yet so this is pretty ad-hoc. + + + + + XML::Simple, a Perl module: pkgs/top-level/perl-packages.nix (search for the XMLSimple attribute). Most Perl modules are so simple to build that they are defined directly in perl-packages.nix; no need to make a separate file for them. + + + + + Adobe Reader: pkgs/applications/misc/adobe-reader/default.nix. Shows how binary-only packages can be supported. In particular the builder uses patchelf to set the RUNPATH and ELF interpreter of the executables so that the right libraries are found at runtime. + + + + + + Some notes: + + + + All meta attributes are optional, but it’s still a good idea to provide at least the description, homepage and license. + + + + + You can use nix-prefetch-url url to get the SHA-256 hash of source distributions. There are similar commands as nix-prefetch-git and nix-prefetch-hg available in nix-prefetch-scripts package. + + + + + A list of schemes for mirror:// URLs can be found in pkgs/build-support/fetchurl/mirrors.nix. + + + + + + The exact syntax and semantics of the Nix expression language, including the built-in function, are described in the Nix manual in the chapter on writing Nix expressions. + + + + + Add a call to the function defined in the previous step to pkgs/top-level/all-packages.nix with some descriptive name for the variable, e.g. libfoo. + +$ emacs pkgs/top-level/all-packages.nix + + + The attributes in that file are sorted by category (like “Development / Libraries”) that more-or-less correspond to the directory structure of Nixpkgs, and then by attribute name. + + + + + To test whether the package builds, run the following command from the root of the nixpkgs source tree: + +$ nix-build -A libfoo + where libfoo should be the variable name defined in the previous step. You may want to add the flag to keep the temporary build directory in case something fails. If the build succeeds, a symlink ./result to the package in the Nix store is created. + + + + + If you want to install the package into your profile (optional), do + +$ nix-env -f . -iA libfoo + + + + + Optionally commit the new package and open a pull request to nixpkgs, or use the Patches category on Discourse for sending a patch without a GitHub account. + + + + + diff --git a/doc/contributing/reviewing-contributions.xml b/doc/contributing/reviewing-contributions.xml new file mode 100644 index 00000000000..ed8f379c460 --- /dev/null +++ b/doc/contributing/reviewing-contributions.xml @@ -0,0 +1,536 @@ + + Reviewing contributions + + + The following section is a draft, and the policy for reviewing is still being discussed in issues such as #11166 and #20836 . + + + + The Nixpkgs project receives a fairly high number of contributions via GitHub pull requests. Reviewing and approving these is an important task and a way to contribute to the project. + + + The high change rate of Nixpkgs makes any pull request that remains open for too long subject to conflicts that will require extra work from the submitter or the merger. Reviewing pull requests in a timely manner and being responsive to the comments is the key to avoid this issue. GitHub provides sort filters that can be used to see the most recently and the least recently updated pull requests. We highly encourage looking at this list of ready to merge, unreviewed pull requests. + + + When reviewing a pull request, please always be nice and polite. Controversial changes can lead to controversial opinions, but it is important to respect every community member and their work. + + + GitHub provides reactions as a simple and quick way to provide feedback to pull requests or any comments. The thumb-down reaction should be used with care and if possible accompanied with some explanation so the submitter has directions to improve their contribution. + + + pull request reviews should include a list of what has been reviewed in a comment, so other reviewers and mergers can know the state of the review. + + + All the review template samples provided in this section are generic and meant as examples. Their usage is optional and the reviewer is free to adapt them to their liking. + +
+ Package updates + + + A package update is the most trivial and common type of pull request. These pull requests mainly consist of updating the version part of the package name and the source hash. + + + + It can happen that non-trivial updates include patches or more complex changes. + + + + Reviewing process: + + + + + + Add labels to the pull request. (Requires commit rights) + + + + + 8.has: package (update) and any topic label that fit the updated package. + + + + + + + Ensure that the package versioning fits the guidelines. + + + + + Ensure that the commit text fits the guidelines. + + + + + Ensure that the package maintainers are notified. + + + + + CODEOWNERS will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers. + + + + + + + Ensure that the meta field information is correct. + + + + + License can change with version updates, so it should be checked to match the upstream license. + + + + + If the package has no maintainer, a maintainer must be set. This can be the update submitter or a community member that accepts to take maintainership of the package. + + + + + + + Ensure that the code contains no typos. + + + + + Building the package locally. + + + + + pull requests are often targeted to the master or staging branch, and building the pull request locally when it is submitted can trigger many source builds. + + + It is possible to rebase the changes on nixos-unstable or nixpkgs-unstable for easier review by running the following commands from a nixpkgs clone. + +$ git fetch origin nixos-unstable +$ git fetch origin pull/PRNUMBER/head +$ git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD + + + + + Fetching the nixos-unstable branch. + + + + + Fetching the pull request changes, PRNUMBER is the number at the end of the pull request title and BASEBRANCH the base branch of the pull request. + + + + + Rebasing the pull request changes to the nixos-unstable branch. + + + + + + + + The nix-review tool can be used to review a pull request content in a single command. PRNUMBER should be replaced by the number at the end of the pull request title. You can also provide the full github pull request url. + + +$ nix-shell -p nix-review --run "nix-review pr PRNUMBER" + + + + + + + Running every binary. + + + + + + Sample template for a package update review + +##### Reviewed points + +- [ ] package name fits guidelines +- [ ] package version fits guidelines +- [ ] package build on ARCHITECTURE +- [ ] executables tested on ARCHITECTURE +- [ ] all depending packages build + +##### Possible improvements + +##### Comments + + + +
+
+ New packages + + + New packages are a common type of pull requests. These pull requests consists in adding a new nix-expression for a package. + + + + Reviewing process: + + + + + + Add labels to the pull request. (Requires commit rights) + + + + + 8.has: package (new) and any topic label that fit the new package. + + + + + + + Ensure that the package versioning is fitting the guidelines. + + + + + Ensure that the commit name is fitting the guidelines. + + + + + Ensure that the meta field contains correct information. + + + + + License must be checked to be fitting upstream license. + + + + + Platforms should be set or the package will not get binary substitutes. + + + + + A maintainer must be set. This can be the package submitter or a community member that accepts to take maintainership of the package. + + + + + + + Ensure that the code contains no typos. + + + + + Ensure the package source. + + + + + Mirrors urls should be used when available. + + + + + The most appropriate function should be used (e.g. packages from GitHub should use fetchFromGitHub). + + + + + + + Building the package locally. + + + + + Running every binary. + + + + + + Sample template for a new package review + +##### Reviewed points + +- [ ] package path fits guidelines +- [ ] package name fits guidelines +- [ ] package version fits guidelines +- [ ] package build on ARCHITECTURE +- [ ] executables tested on ARCHITECTURE +- [ ] `meta.description` is set and fits guidelines +- [ ] `meta.license` fits upstream license +- [ ] `meta.platforms` is set +- [ ] `meta.maintainers` is set +- [ ] build time only dependencies are declared in `nativeBuildInputs` +- [ ] source is fetched using the appropriate function +- [ ] phases are respected +- [ ] patches that are remotely available are fetched with `fetchpatch` + +##### Possible improvements + +##### Comments + + + +
+
+ Module updates + + + Module updates are submissions changing modules in some ways. These often contains changes to the options or introduce new options. + + + + Reviewing process + + + + + + Add labels to the pull request. (Requires commit rights) + + + + + 8.has: module (update) and any topic label that fit the module. + + + + + + + Ensure that the module maintainers are notified. + + + + + CODEOWNERS will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers. + + + + + + + Ensure that the module tests, if any, are succeeding. + + + + + Ensure that the introduced options are correct. + + + + + Type should be appropriate (string related types differs in their merging capabilities, optionSet and string types are deprecated). + + + + + Description, default and example should be provided. + + + + + + + Ensure that option changes are backward compatible. + + + + + mkRenamedOptionModule and mkAliasOptionModule functions provide way to make option changes backward compatible. + + + + + + + Ensure that removed options are declared with mkRemovedOptionModule + + + + + Ensure that changes that are not backward compatible are mentioned in release notes. + + + + + Ensure that documentations affected by the change is updated. + + + + + + Sample template for a module update review + +##### Reviewed points + +- [ ] changes are backward compatible +- [ ] removed options are declared with `mkRemovedOptionModule` +- [ ] changes that are not backward compatible are documented in release notes +- [ ] module tests succeed on ARCHITECTURE +- [ ] options types are appropriate +- [ ] options description is set +- [ ] options example is provided +- [ ] documentation affected by the changes is updated + +##### Possible improvements + +##### Comments + + + +
+
+ New modules + + + New modules submissions introduce a new module to NixOS. + + + + + + Add labels to the pull request. (Requires commit rights) + + + + + 8.has: module (new) and any topic label that fit the module. + + + + + + + Ensure that the module tests, if any, are succeeding. + + + + + Ensure that the introduced options are correct. + + + + + Type should be appropriate (string related types differs in their merging capabilities, optionSet and string types are deprecated). + + + + + Description, default and example should be provided. + + + + + + + Ensure that module meta field is present + + + + + Maintainers should be declared in meta.maintainers. + + + + + Module documentation should be declared with meta.doc. + + + + + + + Ensure that the module respect other modules functionality. + + + + + For example, enabling a module should not open firewall ports by default. + + + + + + + + Sample template for a new module review + +##### Reviewed points + +- [ ] module path fits the guidelines +- [ ] module tests succeed on ARCHITECTURE +- [ ] options have appropriate types +- [ ] options have default +- [ ] options have example +- [ ] options have descriptions +- [ ] No unneeded package is added to environment.systemPackages +- [ ] meta.maintainers is set +- [ ] module documentation is declared in meta.doc + +##### Possible improvements + +##### Comments + + + +
+
+ Other submissions + + + Other type of submissions requires different reviewing steps. + + + + If you consider having enough knowledge and experience in a topic and would like to be a long-term reviewer for related submissions, please contact the current reviewers for that topic. They will give you information about the reviewing process. The main reviewers for a topic can be hard to find as there is no list, but checking past pull requests to see who reviewed or git-blaming the code to see who committed to that topic can give some hints. + + + + Container system, boot system and library changes are some examples of the pull requests fitting this category. + +
+
+ Merging pull requests + + + It is possible for community members that have enough knowledge and experience on a special topic to contribute by merging pull requests. + + + + TODO: add the procedure to request merging rights. + + + + + + In a case a contributor definitively leaves the Nix community, they should create an issue or post on Discourse with references of packages and modules they maintain so the maintainership can be taken over by other contributors. + +
+
diff --git a/doc/contributing/submitting-changes.xml b/doc/contributing/submitting-changes.xml new file mode 100644 index 00000000000..2c7defb8174 --- /dev/null +++ b/doc/contributing/submitting-changes.xml @@ -0,0 +1,429 @@ + + Submitting changes +
+ Making patches + + + + + Read Manual (How to write packages for Nix). + + + + + Fork the repository on GitHub. + + + + + Create a branch for your future fix. + + + + 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: nixos-version returns 15.05.git.0998212 (Dingo). So you can do: + + + + +$ git checkout 0998212 +$ git checkout -b 'fix/pkg-name-update' + + + + + + Please avoid working directly on the master branch. + + + + + + + + Make commits of logical units. + + + + If you removed pkgs, made some major NixOS changes etc., write about them in nixos/doc/manual/release-notes/rl-unstable.xml. + + + + + + + + Check for unnecessary whitespace with git diff --check before committing. + + + + + Format the commit in a following way: + + +(pkg-name | nixos/<module>): (from -> to | init at version | refactor | etc) +Additional information. + + + + + Examples: + + + + nginx: init at 2.0.1 + + + + + firefox: 54.0.1 -> 55.0 + + + + + nixos/hydra: add bazBaz option + + + + + nixos/nginx: refactor config generation + + + + + + + + + + Test your changes. If you work with + + + + nixpkgs: + + + + update pkg -> + + + + nix-env -i pkg-name -f <path to your local nixpkgs folder> + + + + + + + + add pkg -> + + + + Make sure it's in pkgs/top-level/all-packages.nix + + + + + nix-env -i pkg-name -f <path to your local nixpkgs folder> + + + + + + + + If you don't want to install pkg in you profile. + + + + 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. + + + + + + + + If you did nix-env -i pkg-name you can do nix-env -e pkg-name to uninstall it from your system. + + + + + + + + NixOS and its modules: + + + + 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. + + + + + + + + + + + If you have commits pkg-name: oh, forgot to insert whitespace: squash commits in this case. Use git rebase -i. + + + + + Rebase you branch against current master. + + + +
+
+ Submitting changes + + + + + Push your changes to your fork of nixpkgs. + + + + + Create pull request: + + + + Write the title in format (pkg-name | nixos/<module>): improvement. + + + + If you update the pkg, write versions from -> to. + + + + + + + + Write in comment if you have tested your patch. Do not rely much on TravisCI. + + + + + If you make an improvement, write about your motivation. + + + + + Notify maintainers of the package. For example add to the message: cc @jagajaga @domenkozar. + + + + + + +
+
+ Pull Request Template + + + 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. + + + + When a PR is created, it will be pre-populated with some checkboxes detailed below: + + +
+ Tested using sandboxing + + + 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 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 in Nix manual for details. + + + + Sandboxing is not enabled by default in Nix due to a small performance hit on each build. In pull requests for nixpkgs people are asked to test builds with sandboxing enabled (see Tested using sandboxing in the pull request template) because inhttps://nixos.org/hydra/ sandboxing is also used. + + + + Depending if you use NixOS or other platforms you can use one of the following methods to enable sandboxing before building the package: + + + + Globally enable sandboxing on NixOS: add the following to configuration.nix +nix.useSandbox = true; + + + + + Globally enable sandboxing on non-NixOS platforms: add the following to: /etc/nix/nix.conf +sandbox = true + + + + +
+ +
+ Built on platform(s) + + + 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. + +
+ +
+ Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) + + + 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 section in the NixOS manual. + +
+ +
+ Tested compilation of all pkgs that depend on this change using <command>nix-review</command> + + + If you are updating a package's version, you can use nix-review to make sure all packages that depend on the updated package still compile correctly. The nix-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. + + + + review changes from pull request number 12345: +nix-shell -p nix-review --run "nix-review pr 12345" + + + + review uncommitted changes: +nix-shell -p nix-review --run "nix-review wip" + +
+ +
+ Tested execution of all binary files (usually in <filename>./result/bin/</filename>) + + + 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 ./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. + +
+ +
+ Meets Nixpkgs contribution standards + + + The last checkbox is fits 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. + +
+
+
+ Hotfixing pull requests + + + + + Make the appropriate changes in you branch. + + + + + Don't create additional commits, do + + + + git rebase -i + + + + + git push --force to your branch. + + + + + + +
+
+ Commit policy + + + + + Commits must be sufficiently tested before being merged, both for the master and staging branches. + + + + + 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. + + + + + 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. + + + + +
+ Master branch + + + + + It should only see non-breaking commits that do not cause mass rebuilds. + + + +
+ +
+ Staging branch + + + + + It's only for non-breaking mass-rebuild commits. That means it's not to be used for testing, and changes must have been well tested already. Read policy here. + + + + + If the branch is already in a broken state, please refrain from adding extra new breakages. Stabilize it for a few days, merge into master, then resume development on staging. Keep an eye on the staging evaluations here. If any fixes for staging happen to be already in master, then master can be merged into staging. + + + +
+ +
+ Stable release branches + + + + + If you're cherry-picking a commit to a stable release branch, always use git cherry-pick -xe and ensure the message contains a clear description about why this needs to be included in the stable branch. + + + An example of a cherry-picked commit would look like this: + + +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. + + + +
+
+
-- cgit 1.4.1