···11+# Coding conventions {#chap-conventions}
22+33+## Syntax {#sec-syntax}
44+55+- Use 2 spaces of indentation per indentation level in Nix expressions, 4 spaces in shell scripts.
66+77+- 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.
88+99+- Use `lowerCamelCase` for variable names, not `UpperCamelCase`. Note, this rule does not apply to package attribute names, which instead follow the rules in <xref linkend="sec-package-naming"/>.
1010+1111+- Function calls with attribute set arguments are written as
1212+1313+ ```nix
1414+ foo {
1515+ arg = ...;
1616+ }
1717+ ```
1818+1919+ not
2020+2121+ ```nix
2222+ foo
2323+ {
2424+ arg = ...;
2525+ }
2626+ ```
2727+2828+ Also fine is
2929+3030+ ```nix
3131+ foo { arg = ...; }
3232+ ```
3333+3434+ if it's a short call.
3535+3636+- In attribute sets or lists that span multiple lines, the attribute names or list elements should be aligned:
3737+3838+ ```nix
3939+ # A long list.
4040+ list = [
4141+ elem1
4242+ elem2
4343+ elem3
4444+ ];
4545+4646+ # A long attribute set.
4747+ attrs = {
4848+ attr1 = short_expr;
4949+ attr2 =
5050+ if true then big_expr else big_expr;
5151+ };
5252+5353+ # Combined
5454+ listOfAttrs = [
5555+ {
5656+ attr1 = 3;
5757+ attr2 = "fff";
5858+ }
5959+ {
6060+ attr1 = 5;
6161+ attr2 = "ggg";
6262+ }
6363+ ];
6464+ ```
6565+6666+- Short lists or attribute sets can be written on one line:
6767+6868+ ```nix
6969+ # A short list.
7070+ list = [ elem1 elem2 elem3 ];
7171+7272+ # A short set.
7373+ attrs = { x = 1280; y = 1024; };
7474+ ```
7575+7676+- Breaking in the middle of a function argument can give hard-to-read code, like
7777+7878+ ```nix
7979+ someFunction { x = 1280;
8080+ y = 1024; } otherArg
8181+ yetAnotherArg
8282+ ```
8383+8484+ (especially if the argument is very large, spanning multiple lines).
8585+8686+ Better:
8787+8888+ ```nix
8989+ someFunction
9090+ { x = 1280; y = 1024; }
9191+ otherArg
9292+ yetAnotherArg
9393+ ```
9494+9595+ or
9696+9797+ ```nix
9898+ let res = { x = 1280; y = 1024; };
9999+ in someFunction res otherArg yetAnotherArg
100100+ ```
101101+102102+- The bodies of functions, asserts, and withs are not indented to prevent a lot of superfluous indentation levels, i.e.
103103+104104+ ```nix
105105+ { arg1, arg2 }:
106106+ assert system == "i686-linux";
107107+ stdenv.mkDerivation { ...
108108+ ```
109109+110110+ not
111111+112112+ ```nix
113113+ { arg1, arg2 }:
114114+ assert system == "i686-linux";
115115+ stdenv.mkDerivation { ...
116116+ ```
117117+118118+- Function formal arguments are written as:
119119+120120+ ```nix
121121+ { arg1, arg2, arg3 }:
122122+ ```
123123+124124+ but if they don't fit on one line they're written as:
125125+126126+ ```nix
127127+ { arg1, arg2, arg3
128128+ , arg4, ...
129129+ , # Some comment...
130130+ argN
131131+ }:
132132+ ```
133133+134134+- Functions should list their expected arguments as precisely as possible. That is, write
135135+136136+ ```nix
137137+ { stdenv, fetchurl, perl }: ...
138138+ ```
139139+140140+ instead of
141141+142142+ ```nix
143143+ args: with args; ...
144144+ ```
145145+146146+ or
147147+148148+ ```nix
149149+ { stdenv, fetchurl, perl, ... }: ...
150150+ ```
151151+152152+ 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:
153153+154154+ ```nix
155155+ { stdenv, doCoverageAnalysis ? false, ... } @ args:
156156+157157+ stdenv.mkDerivation (args // {
158158+ ... if doCoverageAnalysis then "bla" else "" ...
159159+ })
160160+ ```
161161+162162+ instead of
163163+164164+ ```nix
165165+ args:
166166+167167+ args.stdenv.mkDerivation (args // {
168168+ ... if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else "" ...
169169+ })
170170+ ```
171171+172172+- Arguments should be listed in the order they are used, with the exception of `lib`, which always goes first.
173173+174174+- Prefer using the top-level `lib` over its alias `stdenv.lib`. `lib` is unrelated to `stdenv`, and so `stdenv.lib` should only be used as a convenience alias when developing to avoid having to modify the function inputs just to test something out.
175175+176176+## Package naming {#sec-package-naming}
177177+178178+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](https://tools.ietf.org/html/rfc2119). Only _emphasized_ words are to be interpreted in this way.
179179+180180+In Nixpkgs, there are generally three different names associated with a package:
181181+182182+- The `name` attribute of the derivation (excluding the version part). This is what most users see, in particular when using `nix-env`.
183183+184184+- 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`.
185185+186186+- The filename for (the directory containing) the Nix expression.
187187+188188+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`.
189189+190190+There are a few naming guidelines:
191191+192192+- The `name` attribute _should_ be identical to the upstream package name.
193193+194194+- The `name` attribute _must not_ contain uppercase letters — e.g., `"mplayer-1.0rc2"` instead of `"MPlayer-1.0rc2"`.
195195+196196+- The version part of the `name` attribute _must_ start with a digit (following a dash) — e.g., `"hello-0.3.1rc2"`.
197197+198198+- 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"`.
199199+200200+- 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.
201201+202202+- 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 <xref linkend="sec-versioning" />
203203+204204+## File naming and organisation {#sec-organisation}
205205+206206+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`.
207207+208208+### Hierarchy {#sec-hierarchy}
209209+210210+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`.
211211+212212+When in doubt, consider refactoring the `pkgs/` tree, e.g. creating new categories or splitting up an existing category.
213213+214214+**If it’s used to support _software development_:**
215215+216216+- **If it’s a _library_ used by other packages:**
217217+218218+ - `development/libraries` (e.g. `libxml2`)
219219+220220+- **If it’s a _compiler_:**
221221+222222+ - `development/compilers` (e.g. `gcc`)
223223+224224+- **If it’s an _interpreter_:**
225225+226226+ - `development/interpreters` (e.g. `guile`)
227227+228228+- **If it’s a (set of) development _tool(s)_:**
229229+230230+ - **If it’s a _parser generator_ (including lexers):**
231231+232232+ - `development/tools/parsing` (e.g. `bison`, `flex`)
233233+234234+ - **If it’s a _build manager_:**
235235+236236+ - `development/tools/build-managers` (e.g. `gnumake`)
237237+238238+ - **Else:**
239239+240240+ - `development/tools/misc` (e.g. `binutils`)
241241+242242+- **Else:**
243243+244244+ - `development/misc`
245245+246246+**If it’s a (set of) _tool(s)_:**
247247+248248+(A tool is a relatively small program, especially one intended to be used non-interactively.)
249249+250250+- **If it’s for _networking_:**
251251+252252+ - `tools/networking` (e.g. `wget`)
253253+254254+- **If it’s for _text processing_:**
255255+256256+ - `tools/text` (e.g. `diffutils`)
257257+258258+- **If it’s a _system utility_, i.e., something related or essential to the operation of a system:**
259259+260260+ - `tools/system` (e.g. `cron`)
261261+262262+- **If it’s an _archiver_ (which may include a compression function):**
263263+264264+ - `tools/archivers` (e.g. `zip`, `tar`)
265265+266266+- **If it’s a _compression_ program:**
267267+268268+ - `tools/compression` (e.g. `gzip`, `bzip2`)
269269+270270+- **If it’s a _security_-related program:**
271271+272272+ - `tools/security` (e.g. `nmap`, `gnupg`)
273273+274274+- **Else:**
275275+276276+ - `tools/misc`
277277+278278+**If it’s a _shell_:**
279279+280280+- `shells` (e.g. `bash`)
281281+282282+**If it’s a _server_:**
283283+284284+- **If it’s a web server:**
285285+286286+ - `servers/http` (e.g. `apache-httpd`)
287287+288288+- **If it’s an implementation of the X Windowing System:**
289289+290290+ - `servers/x11` (e.g. `xorg` — this includes the client libraries and programs)
291291+292292+- **Else:**
293293+294294+ - `servers/misc`
295295+296296+**If it’s a _desktop environment_:**
297297+298298+- `desktops` (e.g. `kde`, `gnome`, `enlightenment`)
299299+300300+**If it’s a _window manager_:**
301301+302302+- `applications/window-managers` (e.g. `awesome`, `stumpwm`)
303303+304304+**If it’s an _application_:**
305305+306306+A (typically large) program with a distinct user interface, primarily used interactively.
307307+308308+- **If it’s a _version management system_:**
309309+310310+ - `applications/version-management` (e.g. `subversion`)
311311+312312+- **If it’s a _terminal emulator_:**
313313+314314+ - `applications/terminal-emulators` (e.g. `alacritty` or `rxvt` or `termite`)
315315+316316+- **If it’s for _video playback / editing_:**
317317+318318+ - `applications/video` (e.g. `vlc`)
319319+320320+- **If it’s for _graphics viewing / editing_:**
321321+322322+ - `applications/graphics` (e.g. `gimp`)
323323+324324+- **If it’s for _networking_:**
325325+326326+ - **If it’s a _mailreader_:**
327327+328328+ - `applications/networking/mailreaders` (e.g. `thunderbird`)
329329+330330+ - **If it’s a _newsreader_:**
331331+332332+ - `applications/networking/newsreaders` (e.g. `pan`)
333333+334334+ - **If it’s a _web browser_:**
335335+336336+ - `applications/networking/browsers` (e.g. `firefox`)
337337+338338+ - **Else:**
339339+340340+ - `applications/networking/misc`
341341+342342+- **Else:**
343343+344344+ - `applications/misc`
345345+346346+**If it’s _data_ (i.e., does not have a straight-forward executable semantics):**
347347+348348+- **If it’s a _font_:**
349349+350350+ - `data/fonts`
351351+352352+- **If it’s an _icon theme_:**
353353+354354+ - `data/icons`
355355+356356+- **If it’s related to _SGML/XML processing_:**
357357+358358+ - **If it’s an _XML DTD_:**
359359+360360+ - `data/sgml+xml/schemas/xml-dtd` (e.g. `docbook`)
361361+362362+ - **If it’s an _XSLT stylesheet_:**
363363+364364+ (Okay, these are executable...)
365365+366366+ - `data/sgml+xml/stylesheets/xslt` (e.g. `docbook-xsl`)
367367+368368+- **If it’s a _theme_ for a _desktop environment_, a _window manager_ or a _display manager_:**
369369+370370+ - `data/themes`
371371+372372+**If it’s a _game_:**
373373+374374+- `games`
375375+376376+**Else:**
377377+378378+- `misc`
379379+380380+### Versioning {#sec-versioning}
381381+382382+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.
383383+384384+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`.
385385+386386+All versions of a package _must_ be included in `all-packages.nix` to make sure that they evaluate correctly.
387387+388388+## Fetching Sources {#sec-sources}
389389+390390+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.
391391+392392+You can find many source fetch helpers in `pkgs/build-support/fetch*`.
393393+394394+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:
395395+396396+- Bad: Uses `git://` which won't be proxied.
397397+398398+ ```nix
399399+ src = fetchgit {
400400+ url = "git://github.com/NixOS/nix.git";
401401+ rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
402402+ sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg";
403403+ }
404404+ ```
405405+406406+- Better: This is ok, but an archive fetch will still be faster.
407407+408408+ ```nix
409409+ src = fetchgit {
410410+ url = "https://github.com/NixOS/nix.git";
411411+ rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
412412+ sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg";
413413+ }
414414+ ```
415415+416416+- Best: Fetches a snapshot archive and you get the rev you want.
417417+418418+ ```nix
419419+ src = fetchFromGitHub {
420420+ owner = "NixOS";
421421+ repo = "nix";
422422+ rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
423423+ sha256 = "1i2yxndxb6yc9l6c99pypbd92lfq5aac4klq7y2v93c9qvx2cgpc";
424424+ }
425425+ ```
426426+427427+ 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`.
428428+429429+## Obtaining source hash {#sec-source-hashes}
430430+431431+Preferred source hash type is sha256. There are several ways to get it.
432432+433433+1. Prefetch URL (with `nix-prefetch-XXX URL`, where `XXX` is one of `url`, `git`, `hg`, `cvs`, `bzr`, `svn`). Hash is printed to stdout.
434434+435435+2. Prefetch by package source (with `nix-prefetch-url '<nixpkgs>' -A PACKAGE.src`, where `PACKAGE` is package attribute name). Hash is printed to stdout.
436436+437437+ 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).
438438+439439+3. Upstream provided hash: use it when upstream provides `sha256` or `sha512` (when upstream provides `md5`, don't use it, compute `sha256` instead).
440440+441441+ 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.
442442+443443+ You can convert between formats with nix-hash, for example:
444444+445445+ ```ShellSession
446446+ $ nix-hash --type sha256 --to-base32 HASH
447447+ ```
448448+449449+4. Extracting hash from local source tarball can be done with `sha256sum`. Use `nix-prefetch-url file:///path/to/tarball` if you want base32 hash.
450450+451451+5. Fake hash: set fake hash in package expression, perform build and extract correct hash from error Nix prints.
452452+453453+ 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.
454454+455455+ 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](https://github.com/NixOS/nixpkgs/blob/d2ab091dd308b99e4912b805a5eb088dd536adb9/pkgs/applications/video/kodi/default.nix#L73")). 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.
456456+457457+::: warning
458458+This method has security problems. Check below for details.
459459+:::
460460+461461+### Obtaining hashes securely {#sec-source-hashes-security}
462462+463463+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:
464464+465465+- `http://` URLs are not secure to prefetch hash from;
466466+467467+- hashes from upstream (in method 3) should be obtained via secure protocol;
468468+469469+- `https://` URLs are secure in methods 1, 2, 3;
470470+471471+- `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.
472472+473473+## Patches {#sec-patches}
474474+475475+Patches available online should be retrieved using `fetchpatch`.
476476+477477+```nix
478478+patches = [
479479+ (fetchpatch {
480480+ name = "fix-check-for-using-shared-freetype-lib.patch";
481481+ url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=8f5d285";
482482+ sha256 = "1f0k043rng7f0rfl9hhb89qzvvksqmkrikmm38p61yfx51l325xr";
483483+ })
484484+];
485485+```
486486+487487+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.
488488+489489+```nix
490490+patches = [ ./0001-changes.patch ];
491491+```
492492+493493+If you do need to do create this sort of patch file, one way to do so is with git:
494494+495495+1. Move to the root directory of the source code you're patching.
496496+497497+ ```ShellSession
498498+ $ cd the/program/source
499499+ ```
500500+501501+2. If a git repository is not already present, create one and stage all of the source files.
502502+503503+ ```ShellSession
504504+ $ git init
505505+ $ git add .
506506+ ```
507507+508508+3. Edit some files to make whatever changes need to be included in the patch.
509509+510510+4. Use git to create a diff, and pipe the output to a patch file:
511511+512512+ ```ShellSession
513513+ $ git diff > nixpkgs/pkgs/the/package/0001-changes.patch
514514+ ```
-943
doc/contributing/coding-conventions.xml
···11-<chapter xmlns="http://docbook.org/ns/docbook"
22- xmlns:xlink="http://www.w3.org/1999/xlink"
33- xml:id="chap-conventions">
44- <title>Coding conventions</title>
55- <section xml:id="sec-syntax">
66- <title>Syntax</title>
77-88- <itemizedlist>
99- <listitem>
1010- <para>
1111- Use 2 spaces of indentation per indentation level in Nix expressions, 4 spaces in shell scripts.
1212- </para>
1313- </listitem>
1414- <listitem>
1515- <para>
1616- Do not use tab characters, i.e. configure your editor to use soft tabs. For instance, use <literal>(setq-default indent-tabs-mode nil)</literal> in Emacs. Everybody has different tab settings so it’s asking for trouble.
1717- </para>
1818- </listitem>
1919- <listitem>
2020- <para>
2121- Use <literal>lowerCamelCase</literal> for variable names, not <literal>UpperCamelCase</literal>. Note, this rule does not apply to package attribute names, which instead follow the rules in <xref linkend="sec-package-naming"/>.
2222- </para>
2323- </listitem>
2424- <listitem>
2525- <para>
2626- Function calls with attribute set arguments are written as
2727-<programlisting>
2828-foo {
2929- arg = ...;
3030-}
3131-</programlisting>
3232- not
3333-<programlisting>
3434-foo
3535-{
3636- arg = ...;
3737-}
3838-</programlisting>
3939- Also fine is
4040-<programlisting>
4141-foo { arg = ...; }
4242-</programlisting>
4343- if it's a short call.
4444- </para>
4545- </listitem>
4646- <listitem>
4747- <para>
4848- In attribute sets or lists that span multiple lines, the attribute names or list elements should be aligned:
4949-<programlisting>
5050-# A long list.
5151-list = [
5252- elem1
5353- elem2
5454- elem3
5555-];
5656-5757-# A long attribute set.
5858-attrs = {
5959- attr1 = short_expr;
6060- attr2 =
6161- if true then big_expr else big_expr;
6262-};
6363-6464-# Combined
6565-listOfAttrs = [
6666- {
6767- attr1 = 3;
6868- attr2 = "fff";
6969- }
7070- {
7171- attr1 = 5;
7272- attr2 = "ggg";
7373- }
7474-];
7575-</programlisting>
7676- </para>
7777- </listitem>
7878- <listitem>
7979- <para>
8080- Short lists or attribute sets can be written on one line:
8181-<programlisting>
8282-# A short list.
8383-list = [ elem1 elem2 elem3 ];
8484-8585-# A short set.
8686-attrs = { x = 1280; y = 1024; };
8787-</programlisting>
8888- </para>
8989- </listitem>
9090- <listitem>
9191- <para>
9292- Breaking in the middle of a function argument can give hard-to-read code, like
9393-<programlisting>
9494-someFunction { x = 1280;
9595- y = 1024; } otherArg
9696- yetAnotherArg
9797-</programlisting>
9898- (especially if the argument is very large, spanning multiple lines).
9999- </para>
100100- <para>
101101- Better:
102102-<programlisting>
103103-someFunction
104104- { x = 1280; y = 1024; }
105105- otherArg
106106- yetAnotherArg
107107-</programlisting>
108108- or
109109-<programlisting>
110110-let res = { x = 1280; y = 1024; };
111111-in someFunction res otherArg yetAnotherArg
112112-</programlisting>
113113- </para>
114114- </listitem>
115115- <listitem>
116116- <para>
117117- The bodies of functions, asserts, and withs are not indented to prevent a lot of superfluous indentation levels, i.e.
118118-<programlisting>
119119-{ arg1, arg2 }:
120120-assert system == "i686-linux";
121121-stdenv.mkDerivation { ...
122122-</programlisting>
123123- not
124124-<programlisting>
125125-{ arg1, arg2 }:
126126- assert system == "i686-linux";
127127- stdenv.mkDerivation { ...
128128-</programlisting>
129129- </para>
130130- </listitem>
131131- <listitem>
132132- <para>
133133- Function formal arguments are written as:
134134-<programlisting>
135135-{ arg1, arg2, arg3 }:
136136-</programlisting>
137137- but if they don't fit on one line they're written as:
138138-<programlisting>
139139-{ arg1, arg2, arg3
140140-, arg4, ...
141141-, # Some comment...
142142- argN
143143-}:
144144-</programlisting>
145145- </para>
146146- </listitem>
147147- <listitem>
148148- <para>
149149- Functions should list their expected arguments as precisely as possible. That is, write
150150-<programlisting>
151151-{ stdenv, fetchurl, perl }: <replaceable>...</replaceable>
152152-</programlisting>
153153- instead of
154154-<programlisting>
155155-args: with args; <replaceable>...</replaceable>
156156-</programlisting>
157157- or
158158-<programlisting>
159159-{ stdenv, fetchurl, perl, ... }: <replaceable>...</replaceable>
160160-</programlisting>
161161- </para>
162162- <para>
163163- For functions that are truly generic in the number of arguments (such as wrappers around <varname>mkDerivation</varname>) that have some required arguments, you should write them using an <literal>@</literal>-pattern:
164164-<programlisting>
165165-{ stdenv, doCoverageAnalysis ? false, ... } @ args:
166166-167167-stdenv.mkDerivation (args // {
168168- <replaceable>...</replaceable> if doCoverageAnalysis then "bla" else "" <replaceable>...</replaceable>
169169-})
170170-</programlisting>
171171- instead of
172172-<programlisting>
173173-args:
174174-175175-args.stdenv.mkDerivation (args // {
176176- <replaceable>...</replaceable> if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else "" <replaceable>...</replaceable>
177177-})
178178-</programlisting>
179179- </para>
180180- </listitem>
181181- <listitem>
182182- <para>
183183- Arguments should be listed in the order they are used, with the exception of <varname>lib</varname>, which always goes first.
184184- </para>
185185- </listitem>
186186- <listitem>
187187- <para>
188188- Prefer using the top-level <varname>lib</varname> over its alias <literal>stdenv.lib</literal>. <varname>lib</varname> is unrelated to <varname>stdenv</varname>, and so <literal>stdenv.lib</literal> should only be used as a convenience alias when developing to avoid having to modify the function inputs just to test something out.
189189- </para>
190190- </listitem>
191191- </itemizedlist>
192192- </section>
193193- <section xml:id="sec-package-naming">
194194- <title>Package naming</title>
195195-196196- <para>
197197- The key words <emphasis>must</emphasis>, <emphasis>must not</emphasis>, <emphasis>required</emphasis>, <emphasis>shall</emphasis>, <emphasis>shall not</emphasis>, <emphasis>should</emphasis>, <emphasis>should not</emphasis>, <emphasis>recommended</emphasis>, <emphasis>may</emphasis>, and <emphasis>optional</emphasis> in this section are to be interpreted as described in <link xlink:href="https://tools.ietf.org/html/rfc2119">RFC 2119</link>. Only <emphasis>emphasized</emphasis> words are to be interpreted in this way.
198198- </para>
199199-200200- <para>
201201- In Nixpkgs, there are generally three different names associated with a package:
202202- <itemizedlist>
203203- <listitem>
204204- <para>
205205- The <varname>name</varname> attribute of the derivation (excluding the version part). This is what most users see, in particular when using <command>nix-env</command>.
206206- </para>
207207- </listitem>
208208- <listitem>
209209- <para>
210210- The variable name used for the instantiated package in <filename>all-packages.nix</filename>, and when passing it as a dependency to other functions. Typically this is called the <emphasis>package attribute name</emphasis>. This is what Nix expression authors see. It can also be used when installing using <command>nix-env -iA</command>.
211211- </para>
212212- </listitem>
213213- <listitem>
214214- <para>
215215- The filename for (the directory containing) the Nix expression.
216216- </para>
217217- </listitem>
218218- </itemizedlist>
219219- Most of the time, these are the same. For instance, the package <literal>e2fsprogs</literal> has a <varname>name</varname> attribute <literal>"e2fsprogs-<replaceable>version</replaceable>"</literal>, is bound to the variable name <varname>e2fsprogs</varname> in <filename>all-packages.nix</filename>, and the Nix expression is in <filename>pkgs/os-specific/linux/e2fsprogs/default.nix</filename>.
220220- </para>
221221-222222- <para>
223223- There are a few naming guidelines:
224224- <itemizedlist>
225225- <listitem>
226226- <para>
227227- The <literal>name</literal> attribute <emphasis>should</emphasis> be identical to the upstream package name.
228228- </para>
229229- </listitem>
230230- <listitem>
231231- <para>
232232- The <literal>name</literal> attribute <emphasis>must not</emphasis> contain uppercase letters — e.g., <literal>"mplayer-1.0rc2"</literal> instead of <literal>"MPlayer-1.0rc2"</literal>.
233233- </para>
234234- </listitem>
235235- <listitem>
236236- <para>
237237- The version part of the <literal>name</literal> attribute <emphasis>must</emphasis> start with a digit (following a dash) — e.g., <literal>"hello-0.3.1rc2"</literal>.
238238- </para>
239239- </listitem>
240240- <listitem>
241241- <para>
242242- If a package is not a release but a commit from a repository, then the version part of the name <emphasis>must</emphasis> be the date of that (fetched) commit. The date <emphasis>must</emphasis> be in <literal>"YYYY-MM-DD"</literal> format. Also append <literal>"unstable"</literal> to the name - e.g., <literal>"pkgname-unstable-2014-09-23"</literal>.
243243- </para>
244244- </listitem>
245245- <listitem>
246246- <para>
247247- Dashes in the package name <emphasis>should</emphasis> be preserved in new variable names, rather than converted to underscores or camel cased — e.g., <varname>http-parser</varname> instead of <varname>http_parser</varname> or <varname>httpParser</varname>. The hyphenated style is preferred in all three package names.
248248- </para>
249249- </listitem>
250250- <listitem>
251251- <para>
252252- If there are multiple versions of a package, this <emphasis>should</emphasis> be reflected in the variable names in <filename>all-packages.nix</filename>, e.g. <varname>json-c-0-9</varname> and <varname>json-c-0-11</varname>. If there is an obvious “default” version, make an attribute like <literal>json-c = json-c-0-9;</literal>. See also <xref linkend="sec-versioning" />
253253- </para>
254254- </listitem>
255255- </itemizedlist>
256256- </para>
257257- </section>
258258- <section xml:id="sec-organisation">
259259- <title>File naming and organisation</title>
260260-261261- <para>
262262- Names of files and directories should be in lowercase, with dashes between words — not in camel case. For instance, it should be <filename>all-packages.nix</filename>, not <filename>allPackages.nix</filename> or <filename>AllPackages.nix</filename>.
263263- </para>
264264-265265- <section xml:id="sec-hierarchy">
266266- <title>Hierarchy</title>
267267-268268- <para>
269269- Each package should be stored in its own directory somewhere in the <filename>pkgs/</filename> tree, i.e. in <filename>pkgs/<replaceable>category</replaceable>/<replaceable>subcategory</replaceable>/<replaceable>...</replaceable>/<replaceable>pkgname</replaceable></filename>. Below are some rules for picking the right category for a package. Many packages fall under several categories; what matters is the <emphasis>primary</emphasis> purpose of a package. For example, the <literal>libxml2</literal> package builds both a library and some tools; but it’s a library foremost, so it goes under <filename>pkgs/development/libraries</filename>.
270270- </para>
271271-272272- <para>
273273- When in doubt, consider refactoring the <filename>pkgs/</filename> tree, e.g. creating new categories or splitting up an existing category.
274274- </para>
275275-276276- <variablelist>
277277- <varlistentry>
278278- <term>
279279- If it’s used to support <emphasis>software development</emphasis>:
280280- </term>
281281- <listitem>
282282- <variablelist>
283283- <varlistentry>
284284- <term>
285285- If it’s a <emphasis>library</emphasis> used by other packages:
286286- </term>
287287- <listitem>
288288- <para>
289289- <filename>development/libraries</filename> (e.g. <filename>libxml2</filename>)
290290- </para>
291291- </listitem>
292292- </varlistentry>
293293- <varlistentry>
294294- <term>
295295- If it’s a <emphasis>compiler</emphasis>:
296296- </term>
297297- <listitem>
298298- <para>
299299- <filename>development/compilers</filename> (e.g. <filename>gcc</filename>)
300300- </para>
301301- </listitem>
302302- </varlistentry>
303303- <varlistentry>
304304- <term>
305305- If it’s an <emphasis>interpreter</emphasis>:
306306- </term>
307307- <listitem>
308308- <para>
309309- <filename>development/interpreters</filename> (e.g. <filename>guile</filename>)
310310- </para>
311311- </listitem>
312312- </varlistentry>
313313- <varlistentry>
314314- <term>
315315- If it’s a (set of) development <emphasis>tool(s)</emphasis>:
316316- </term>
317317- <listitem>
318318- <variablelist>
319319- <varlistentry>
320320- <term>
321321- If it’s a <emphasis>parser generator</emphasis> (including lexers):
322322- </term>
323323- <listitem>
324324- <para>
325325- <filename>development/tools/parsing</filename> (e.g. <filename>bison</filename>, <filename>flex</filename>)
326326- </para>
327327- </listitem>
328328- </varlistentry>
329329- <varlistentry>
330330- <term>
331331- If it’s a <emphasis>build manager</emphasis>:
332332- </term>
333333- <listitem>
334334- <para>
335335- <filename>development/tools/build-managers</filename> (e.g. <filename>gnumake</filename>)
336336- </para>
337337- </listitem>
338338- </varlistentry>
339339- <varlistentry>
340340- <term>
341341- Else:
342342- </term>
343343- <listitem>
344344- <para>
345345- <filename>development/tools/misc</filename> (e.g. <filename>binutils</filename>)
346346- </para>
347347- </listitem>
348348- </varlistentry>
349349- </variablelist>
350350- </listitem>
351351- </varlistentry>
352352- <varlistentry>
353353- <term>
354354- Else:
355355- </term>
356356- <listitem>
357357- <para>
358358- <filename>development/misc</filename>
359359- </para>
360360- </listitem>
361361- </varlistentry>
362362- </variablelist>
363363- </listitem>
364364- </varlistentry>
365365- <varlistentry>
366366- <term>
367367- If it’s a (set of) <emphasis>tool(s)</emphasis>:
368368- </term>
369369- <listitem>
370370- <para>
371371- (A tool is a relatively small program, especially one intended to be used non-interactively.)
372372- </para>
373373- <variablelist>
374374- <varlistentry>
375375- <term>
376376- If it’s for <emphasis>networking</emphasis>:
377377- </term>
378378- <listitem>
379379- <para>
380380- <filename>tools/networking</filename> (e.g. <filename>wget</filename>)
381381- </para>
382382- </listitem>
383383- </varlistentry>
384384- <varlistentry>
385385- <term>
386386- If it’s for <emphasis>text processing</emphasis>:
387387- </term>
388388- <listitem>
389389- <para>
390390- <filename>tools/text</filename> (e.g. <filename>diffutils</filename>)
391391- </para>
392392- </listitem>
393393- </varlistentry>
394394- <varlistentry>
395395- <term>
396396- If it’s a <emphasis>system utility</emphasis>, i.e., something related or essential to the operation of a system:
397397- </term>
398398- <listitem>
399399- <para>
400400- <filename>tools/system</filename> (e.g. <filename>cron</filename>)
401401- </para>
402402- </listitem>
403403- </varlistentry>
404404- <varlistentry>
405405- <term>
406406- If it’s an <emphasis>archiver</emphasis> (which may include a compression function):
407407- </term>
408408- <listitem>
409409- <para>
410410- <filename>tools/archivers</filename> (e.g. <filename>zip</filename>, <filename>tar</filename>)
411411- </para>
412412- </listitem>
413413- </varlistentry>
414414- <varlistentry>
415415- <term>
416416- If it’s a <emphasis>compression</emphasis> program:
417417- </term>
418418- <listitem>
419419- <para>
420420- <filename>tools/compression</filename> (e.g. <filename>gzip</filename>, <filename>bzip2</filename>)
421421- </para>
422422- </listitem>
423423- </varlistentry>
424424- <varlistentry>
425425- <term>
426426- If it’s a <emphasis>security</emphasis>-related program:
427427- </term>
428428- <listitem>
429429- <para>
430430- <filename>tools/security</filename> (e.g. <filename>nmap</filename>, <filename>gnupg</filename>)
431431- </para>
432432- </listitem>
433433- </varlistentry>
434434- <varlistentry>
435435- <term>
436436- Else:
437437- </term>
438438- <listitem>
439439- <para>
440440- <filename>tools/misc</filename>
441441- </para>
442442- </listitem>
443443- </varlistentry>
444444- </variablelist>
445445- </listitem>
446446- </varlistentry>
447447- <varlistentry>
448448- <term>
449449- If it’s a <emphasis>shell</emphasis>:
450450- </term>
451451- <listitem>
452452- <para>
453453- <filename>shells</filename> (e.g. <filename>bash</filename>)
454454- </para>
455455- </listitem>
456456- </varlistentry>
457457- <varlistentry>
458458- <term>
459459- If it’s a <emphasis>server</emphasis>:
460460- </term>
461461- <listitem>
462462- <variablelist>
463463- <varlistentry>
464464- <term>
465465- If it’s a web server:
466466- </term>
467467- <listitem>
468468- <para>
469469- <filename>servers/http</filename> (e.g. <filename>apache-httpd</filename>)
470470- </para>
471471- </listitem>
472472- </varlistentry>
473473- <varlistentry>
474474- <term>
475475- If it’s an implementation of the X Windowing System:
476476- </term>
477477- <listitem>
478478- <para>
479479- <filename>servers/x11</filename> (e.g. <filename>xorg</filename> — this includes the client libraries and programs)
480480- </para>
481481- </listitem>
482482- </varlistentry>
483483- <varlistentry>
484484- <term>
485485- Else:
486486- </term>
487487- <listitem>
488488- <para>
489489- <filename>servers/misc</filename>
490490- </para>
491491- </listitem>
492492- </varlistentry>
493493- </variablelist>
494494- </listitem>
495495- </varlistentry>
496496- <varlistentry>
497497- <term>
498498- If it’s a <emphasis>desktop environment</emphasis>:
499499- </term>
500500- <listitem>
501501- <para>
502502- <filename>desktops</filename> (e.g. <filename>kde</filename>, <filename>gnome</filename>, <filename>enlightenment</filename>)
503503- </para>
504504- </listitem>
505505- </varlistentry>
506506- <varlistentry>
507507- <term>
508508- If it’s a <emphasis>window manager</emphasis>:
509509- </term>
510510- <listitem>
511511- <para>
512512- <filename>applications/window-managers</filename> (e.g. <filename>awesome</filename>, <filename>stumpwm</filename>)
513513- </para>
514514- </listitem>
515515- </varlistentry>
516516- <varlistentry>
517517- <term>
518518- If it’s an <emphasis>application</emphasis>:
519519- </term>
520520- <listitem>
521521- <para>
522522- A (typically large) program with a distinct user interface, primarily used interactively.
523523- </para>
524524- <variablelist>
525525- <varlistentry>
526526- <term>
527527- If it’s a <emphasis>version management system</emphasis>:
528528- </term>
529529- <listitem>
530530- <para>
531531- <filename>applications/version-management</filename> (e.g. <filename>subversion</filename>)
532532- </para>
533533- </listitem>
534534- </varlistentry>
535535- <varlistentry>
536536- <term>
537537- If it’s a <emphasis>terminal emulator</emphasis>:
538538- </term>
539539- <listitem>
540540- <para>
541541- <filename>applications/terminal-emulators</filename> (e.g. <filename>alacritty</filename> or <filename>rxvt</filename> or <filename>termite</filename>)
542542- </para>
543543- </listitem>
544544- </varlistentry>
545545- <varlistentry>
546546- <term>
547547- If it’s for <emphasis>video playback / editing</emphasis>:
548548- </term>
549549- <listitem>
550550- <para>
551551- <filename>applications/video</filename> (e.g. <filename>vlc</filename>)
552552- </para>
553553- </listitem>
554554- </varlistentry>
555555- <varlistentry>
556556- <term>
557557- If it’s for <emphasis>graphics viewing / editing</emphasis>:
558558- </term>
559559- <listitem>
560560- <para>
561561- <filename>applications/graphics</filename> (e.g. <filename>gimp</filename>)
562562- </para>
563563- </listitem>
564564- </varlistentry>
565565- <varlistentry>
566566- <term>
567567- If it’s for <emphasis>networking</emphasis>:
568568- </term>
569569- <listitem>
570570- <variablelist>
571571- <varlistentry>
572572- <term>
573573- If it’s a <emphasis>mailreader</emphasis>:
574574- </term>
575575- <listitem>
576576- <para>
577577- <filename>applications/networking/mailreaders</filename> (e.g. <filename>thunderbird</filename>)
578578- </para>
579579- </listitem>
580580- </varlistentry>
581581- <varlistentry>
582582- <term>
583583- If it’s a <emphasis>newsreader</emphasis>:
584584- </term>
585585- <listitem>
586586- <para>
587587- <filename>applications/networking/newsreaders</filename> (e.g. <filename>pan</filename>)
588588- </para>
589589- </listitem>
590590- </varlistentry>
591591- <varlistentry>
592592- <term>
593593- If it’s a <emphasis>web browser</emphasis>:
594594- </term>
595595- <listitem>
596596- <para>
597597- <filename>applications/networking/browsers</filename> (e.g. <filename>firefox</filename>)
598598- </para>
599599- </listitem>
600600- </varlistentry>
601601- <varlistentry>
602602- <term>
603603- Else:
604604- </term>
605605- <listitem>
606606- <para>
607607- <filename>applications/networking/misc</filename>
608608- </para>
609609- </listitem>
610610- </varlistentry>
611611- </variablelist>
612612- </listitem>
613613- </varlistentry>
614614- <varlistentry>
615615- <term>
616616- Else:
617617- </term>
618618- <listitem>
619619- <para>
620620- <filename>applications/misc</filename>
621621- </para>
622622- </listitem>
623623- </varlistentry>
624624- </variablelist>
625625- </listitem>
626626- </varlistentry>
627627- <varlistentry>
628628- <term>
629629- If it’s <emphasis>data</emphasis> (i.e., does not have a straight-forward executable semantics):
630630- </term>
631631- <listitem>
632632- <variablelist>
633633- <varlistentry>
634634- <term>
635635- If it’s a <emphasis>font</emphasis>:
636636- </term>
637637- <listitem>
638638- <para>
639639- <filename>data/fonts</filename>
640640- </para>
641641- </listitem>
642642- </varlistentry>
643643- <varlistentry>
644644- <term>
645645- If it’s an <emphasis>icon theme</emphasis>:
646646- </term>
647647- <listitem>
648648- <para>
649649- <filename>data/icons</filename>
650650- </para>
651651- </listitem>
652652- </varlistentry>
653653- <varlistentry>
654654- <term>
655655- If it’s related to <emphasis>SGML/XML processing</emphasis>:
656656- </term>
657657- <listitem>
658658- <variablelist>
659659- <varlistentry>
660660- <term>
661661- If it’s an <emphasis>XML DTD</emphasis>:
662662- </term>
663663- <listitem>
664664- <para>
665665- <filename>data/sgml+xml/schemas/xml-dtd</filename> (e.g. <filename>docbook</filename>)
666666- </para>
667667- </listitem>
668668- </varlistentry>
669669- <varlistentry>
670670- <term>
671671- If it’s an <emphasis>XSLT stylesheet</emphasis>:
672672- </term>
673673- <listitem>
674674- <para>
675675- (Okay, these are executable...)
676676- </para>
677677- <para>
678678- <filename>data/sgml+xml/stylesheets/xslt</filename> (e.g. <filename>docbook-xsl</filename>)
679679- </para>
680680- </listitem>
681681- </varlistentry>
682682- </variablelist>
683683- </listitem>
684684- </varlistentry>
685685- <varlistentry>
686686- <term>
687687- If it’s a <emphasis>theme</emphasis> for a <emphasis>desktop environment</emphasis>, a <emphasis>window manager</emphasis> or a <emphasis>display manager</emphasis>:
688688- </term>
689689- <listitem>
690690- <para>
691691- <filename>data/themes</filename>
692692- </para>
693693- </listitem>
694694- </varlistentry>
695695- </variablelist>
696696- </listitem>
697697- </varlistentry>
698698- <varlistentry>
699699- <term>
700700- If it’s a <emphasis>game</emphasis>:
701701- </term>
702702- <listitem>
703703- <para>
704704- <filename>games</filename>
705705- </para>
706706- </listitem>
707707- </varlistentry>
708708- <varlistentry>
709709- <term>
710710- Else:
711711- </term>
712712- <listitem>
713713- <para>
714714- <filename>misc</filename>
715715- </para>
716716- </listitem>
717717- </varlistentry>
718718- </variablelist>
719719- </section>
720720-721721- <section xml:id="sec-versioning">
722722- <title>Versioning</title>
723723-724724- <para>
725725- 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.
726726- </para>
727727-728728- <para>
729729- If there is only one version of a package, its Nix expression should be named <filename>e2fsprogs/default.nix</filename>. If there are multiple versions, this should be reflected in the filename, e.g. <filename>e2fsprogs/1.41.8.nix</filename> and <filename>e2fsprogs/1.41.9.nix</filename>. 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 <filename>firefox/2.0.nix</filename> and <filename>firefox/3.5.nix</filename>, respectively (which, at a given point, might contain versions <literal>2.0.0.20</literal> and <literal>3.5.4</literal>). If a version requires many auxiliary files, you can use a subdirectory for each version, e.g. <filename>firefox/2.0/default.nix</filename> and <filename>firefox/3.5/default.nix</filename>.
730730- </para>
731731-732732- <para>
733733- All versions of a package <emphasis>must</emphasis> be included in <filename>all-packages.nix</filename> to make sure that they evaluate correctly.
734734- </para>
735735- </section>
736736- </section>
737737- <section xml:id="sec-sources">
738738- <title>Fetching Sources</title>
739739-740740- <para>
741741- 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 <literal>fetchurl</literal>. Note that you should also prefer protocols which have a corresponding proxy environment variable.
742742- </para>
743743-744744- <para>
745745- You can find many source fetch helpers in <literal>pkgs/build-support/fetch*</literal>.
746746- </para>
747747-748748- <para>
749749- In the file <literal>pkgs/top-level/all-packages.nix</literal> you can find fetch helpers, these have names on the form <literal>fetchFrom*</literal>. The intention of these are to provide snapshot fetches but using the same api as some of the version controlled fetchers from <literal>pkgs/build-support/</literal>. As an example going from bad to good:
750750- <itemizedlist>
751751- <listitem>
752752- <para>
753753- Bad: Uses <literal>git://</literal> which won't be proxied.
754754-<programlisting>
755755-src = fetchgit {
756756- url = "git://github.com/NixOS/nix.git";
757757- rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
758758- sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg";
759759-}
760760-</programlisting>
761761- </para>
762762- </listitem>
763763- <listitem>
764764- <para>
765765- Better: This is ok, but an archive fetch will still be faster.
766766-<programlisting>
767767-src = fetchgit {
768768- url = "https://github.com/NixOS/nix.git";
769769- rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
770770- sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg";
771771-}
772772-</programlisting>
773773- </para>
774774- </listitem>
775775- <listitem>
776776- <para>
777777- Best: Fetches a snapshot archive and you get the rev you want.
778778-<programlisting>
779779-src = fetchFromGitHub {
780780- owner = "NixOS";
781781- repo = "nix";
782782- rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
783783- sha256 = "1i2yxndxb6yc9l6c99pypbd92lfq5aac4klq7y2v93c9qvx2cgpc";
784784-}
785785-</programlisting>
786786- Find the value to put as <literal>sha256</literal> by running <literal>nix run -f '<nixpkgs>' nix-prefetch-github -c nix-prefetch-github --rev 1f795f9f44607cc5bec70d1300150bfefcef2aae NixOS nix</literal> or <literal>nix-prefetch-url --unpack https://github.com/NixOS/nix/archive/1f795f9f44607cc5bec70d1300150bfefcef2aae.tar.gz</literal>.
787787- </para>
788788- </listitem>
789789- </itemizedlist>
790790- </para>
791791- </section>
792792- <section xml:id="sec-source-hashes">
793793- <title>Obtaining source hash</title>
794794-795795- <para>
796796- Preferred source hash type is sha256. There are several ways to get it.
797797- </para>
798798-799799- <orderedlist>
800800- <listitem>
801801- <para>
802802- Prefetch URL (with <literal>nix-prefetch-<replaceable>XXX</replaceable> <replaceable>URL</replaceable></literal>, where <replaceable>XXX</replaceable> is one of <literal>url</literal>, <literal>git</literal>, <literal>hg</literal>, <literal>cvs</literal>, <literal>bzr</literal>, <literal>svn</literal>). Hash is printed to stdout.
803803- </para>
804804- </listitem>
805805- <listitem>
806806- <para>
807807- Prefetch by package source (with <literal>nix-prefetch-url '<nixpkgs>' -A <replaceable>PACKAGE</replaceable>.src</literal>, where <replaceable>PACKAGE</replaceable> is package attribute name). Hash is printed to stdout.
808808- </para>
809809- <para>
810810- 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 (<literal>.srcs</literal>, architecture-dependent sources, etc).
811811- </para>
812812- </listitem>
813813- <listitem>
814814- <para>
815815- Upstream provided hash: use it when upstream provides <literal>sha256</literal> or <literal>sha512</literal> (when upstream provides <literal>md5</literal>, don't use it, compute <literal>sha256</literal> instead).
816816- </para>
817817- <para>
818818- A little nuance is that <literal>nix-prefetch-*</literal> tools produce hash encoded with <literal>base32</literal>, but upstream usually provides hexadecimal (<literal>base16</literal>) encoding. Fetchers understand both formats. Nixpkgs does not standardize on any one format.
819819- </para>
820820- <para>
821821- You can convert between formats with nix-hash, for example:
822822-<screen>
823823-<prompt>$ </prompt>nix-hash --type sha256 --to-base32 <replaceable>HASH</replaceable>
824824-</screen>
825825- </para>
826826- </listitem>
827827- <listitem>
828828- <para>
829829- Extracting hash from local source tarball can be done with <literal>sha256sum</literal>. Use <literal>nix-prefetch-url file:///path/to/tarball </literal> if you want base32 hash.
830830- </para>
831831- </listitem>
832832- <listitem>
833833- <para>
834834- Fake hash: set fake hash in package expression, perform build and extract correct hash from error Nix prints.
835835- </para>
836836- <para>
837837- For package updates it is enough to change one symbol to make hash fake. For new packages, you can use <literal>lib.fakeSha256</literal>, <literal>lib.fakeSha512</literal> or any other fake hash.
838838- </para>
839839- <para>
840840- This is last resort method when reconstructing source URL is non-trivial and <literal>nix-prefetch-url -A</literal> isn't applicable (for example, <link xlink:href="https://github.com/NixOS/nixpkgs/blob/d2ab091dd308b99e4912b805a5eb088dd536adb9/pkgs/applications/video/kodi/default.nix#L73"> one of <literal>kodi</literal> dependencies</link>). 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.
841841- </para>
842842- <warning>
843843- <para>
844844- This method has security problems. Check below for details.
845845- </para>
846846- </warning>
847847- </listitem>
848848- </orderedlist>
849849-850850- <section xml:id="sec-source-hashes-security">
851851- <title>Obtaining hashes securely</title>
852852-853853- <para>
854854- 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:
855855- </para>
856856-857857- <itemizedlist>
858858- <listitem>
859859- <para>
860860- <literal>http://</literal> URLs are not secure to prefetch hash from;
861861- </para>
862862- </listitem>
863863- <listitem>
864864- <para>
865865- hashes from upstream (in method 3) should be obtained via secure protocol;
866866- </para>
867867- </listitem>
868868- <listitem>
869869- <para>
870870- <literal>https://</literal> URLs are secure in methods 1, 2, 3;
871871- </para>
872872- </listitem>
873873- <listitem>
874874- <para>
875875- <literal>https://</literal> 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 <literal>https://</literal> URL and prefetch it with method 1.
876876- </para>
877877- </listitem>
878878- </itemizedlist>
879879- </section>
880880- </section>
881881- <section xml:id="sec-patches">
882882- <title>Patches</title>
883883-884884- <para>
885885- Patches available online should be retrieved using <literal>fetchpatch</literal>.
886886- </para>
887887-888888- <para>
889889-<programlisting>
890890-patches = [
891891- (fetchpatch {
892892- name = "fix-check-for-using-shared-freetype-lib.patch";
893893- url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=8f5d285";
894894- sha256 = "1f0k043rng7f0rfl9hhb89qzvvksqmkrikmm38p61yfx51l325xr";
895895- })
896896-];
897897-</programlisting>
898898- </para>
899899-900900- <para>
901901- Otherwise, you can add a <literal>.patch</literal> file to the <literal>nixpkgs</literal> repository. In the interest of keeping our maintenance burden to a minimum, only patches that are unique to <literal>nixpkgs</literal> should be added in this way.
902902- </para>
903903-904904- <para>
905905-<programlisting>
906906-patches = [ ./0001-changes.patch ];
907907-</programlisting>
908908- </para>
909909-910910- <para>
911911- If you do need to do create this sort of patch file, one way to do so is with git:
912912- <orderedlist>
913913- <listitem>
914914- <para>
915915- Move to the root directory of the source code you're patching.
916916-<screen>
917917-<prompt>$ </prompt>cd the/program/source</screen>
918918- </para>
919919- </listitem>
920920- <listitem>
921921- <para>
922922- If a git repository is not already present, create one and stage all of the source files.
923923-<screen>
924924-<prompt>$ </prompt>git init
925925-<prompt>$ </prompt>git add .</screen>
926926- </para>
927927- </listitem>
928928- <listitem>
929929- <para>
930930- Edit some files to make whatever changes need to be included in the patch.
931931- </para>
932932- </listitem>
933933- <listitem>
934934- <para>
935935- Use git to create a diff, and pipe the output to a patch file:
936936-<screen>
937937-<prompt>$ </prompt>git diff > nixpkgs/pkgs/the/package/0001-changes.patch</screen>
938938- </para>
939939- </listitem>
940940- </orderedlist>
941941- </para>
942942- </section>
943943-</chapter>
···11+# Contributing to this documentation {#chap-contributing}
22+33+The DocBook sources of the Nixpkgs manual are in the [doc](https://github.com/NixOS/nixpkgs/tree/master/doc) subdirectory of the Nixpkgs repository.
44+55+You can quickly check your edits with `make`:
66+77+```ShellSession
88+$ cd /path/to/nixpkgs/doc
99+$ nix-shell
1010+[nix-shell]$ make $makeFlags
1111+```
1212+1313+If you experience problems, run `make debug` to help understand the docbook errors.
1414+1515+After making modifications to the manual, it's important to build it before committing. You can do that as follows:
1616+1717+```ShellSession
1818+$ cd /path/to/nixpkgs/doc
1919+$ nix-shell
2020+[nix-shell]$ make clean
2121+[nix-shell]$ nix-build .
2222+```
2323+2424+If the build succeeds, the manual will be in `./result/share/doc/nixpkgs/manual.html`.
···11-<chapter xmlns="http://docbook.org/ns/docbook"
22- xmlns:xlink="http://www.w3.org/1999/xlink"
33- xml:id="chap-contributing">
44- <title>Contributing to this documentation</title>
55- <para>
66- The DocBook sources of the Nixpkgs manual are in the <filename
77-xlink:href="https://github.com/NixOS/nixpkgs/tree/master/doc">doc</filename> subdirectory of the Nixpkgs repository.
88- </para>
99- <para>
1010- You can quickly check your edits with <command>make</command>:
1111- </para>
1212-<screen>
1313-<prompt>$ </prompt>cd /path/to/nixpkgs/doc
1414-<prompt>$ </prompt>nix-shell
1515-<prompt>[nix-shell]$ </prompt>make $makeFlags
1616-</screen>
1717- <para>
1818- If you experience problems, run <command>make debug</command> to help understand the docbook errors.
1919- </para>
2020- <para>
2121- After making modifications to the manual, it's important to build it before committing. You can do that as follows:
2222-<screen>
2323-<prompt>$ </prompt>cd /path/to/nixpkgs/doc
2424-<prompt>$ </prompt>nix-shell
2525-<prompt>[nix-shell]$ </prompt>make clean
2626-<prompt>[nix-shell]$ </prompt>nix-build .
2727-</screen>
2828- If the build succeeds, the manual will be in <filename>./result/share/doc/nixpkgs/manual.html</filename>.
2929- </para>
3030-</chapter>
+77
doc/contributing/quick-start.chapter.md
···11+# Quick Start to Adding a Package {#chap-quick-start}
22+33+To add a package to Nixpkgs:
44+55+1. Checkout the Nixpkgs source tree:
66+77+ ```ShellSession
88+ $ git clone https://github.com/NixOS/nixpkgs
99+ $ cd nixpkgs
1010+ ```
1111+1212+2. 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 <xref linkend="sec-organisation" /> for some hints on the tree organisation. Create a directory for your package, e.g.
1313+1414+ ```ShellSession
1515+ $ mkdir pkgs/development/libraries/libfoo
1616+ ```
1717+1818+3. 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`.
1919+2020+ ```ShellSession
2121+ $ emacs pkgs/development/libraries/libfoo/default.nix
2222+ $ git add pkgs/development/libraries/libfoo/default.nix
2323+ ```
2424+2525+ You can have a look at the existing Nix expressions under `pkgs/` to see how it’s done. Here are some good ones:
2626+2727+ - GNU Hello: [`pkgs/applications/misc/hello/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/hello/default.nix). Trivial package, which specifies some `meta` attributes which is good practice.
2828+2929+ - GNU cpio: [`pkgs/tools/archivers/cpio/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/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`.
3030+3131+ - GNU Multiple Precision arithmetic library (GMP): [`pkgs/development/libraries/gmp/5.1.x.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/gmp/5.1.x.nix). Also done by the generic builder, but has a dependency on `m4`.
3232+3333+ - Pan, a GTK-based newsreader: [`pkgs/applications/networking/newsreaders/pan/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix). Has an optional dependency on `gtkspell`, which is only built if `spellCheck` is `true`.
3434+3535+ - Apache HTTPD: [`pkgs/servers/http/apache-httpd/2.4.nix`](https://github.com/NixOS/nixpkgs/blob/master/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.
3636+3737+ - Thunderbird: [`pkgs/applications/networking/mailreaders/thunderbird/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/mailreaders/thunderbird/default.nix). Lots of dependencies.
3838+3939+ - JDiskReport, a Java utility: [`pkgs/tools/misc/jdiskreport/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/jdiskreport/default.nix). Nixpkgs doesn’t have a decent `stdenv` for Java yet so this is pretty ad-hoc.
4040+4141+ - XML::Simple, a Perl module: [`pkgs/top-level/perl-packages.nix`](https://github.com/NixOS/nixpkgs/blob/master/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.
4242+4343+ - Adobe Reader: [`pkgs/applications/misc/adobe-reader/default.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/default.nix). Shows how binary-only packages can be supported. In particular the [builder](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/builder.sh) uses `patchelf` to set the RUNPATH and ELF interpreter of the executables so that the right libraries are found at runtime.
4444+4545+ Some notes:
4646+4747+ - All [`meta`](#chap-meta) attributes are optional, but it’s still a good idea to provide at least the `description`, `homepage` and [`license`](#sec-meta-license).
4848+4949+ - 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.
5050+5151+ - A list of schemes for `mirror://` URLs can be found in [`pkgs/build-support/fetchurl/mirrors.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/fetchurl/mirrors.nix).
5252+5353+ 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](https://hydra.nixos.org/job/nix/trunk/tarball/latest/download-by-type/doc/manual/#chap-writing-nix-expressions).
5454+5555+4. Add a call to the function defined in the previous step to [`pkgs/top-level/all-packages.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix) with some descriptive name for the variable, e.g. `libfoo`.
5656+5757+ ```ShellSession
5858+ $ emacs pkgs/top-level/all-packages.nix
5959+ ```
6060+6161+ 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.
6262+6363+5. To test whether the package builds, run the following command from the root of the nixpkgs source tree:
6464+6565+ ```ShellSession
6666+ $ nix-build -A libfoo
6767+ ```
6868+6969+ where `libfoo` should be the variable name defined in the previous step. You may want to add the flag `-K` 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.
7070+7171+6. If you want to install the package into your profile (optional), do
7272+7373+ ```ShellSession
7474+ $ nix-env -f . -iA libfoo
7575+ ```
7676+7777+7. Optionally commit the new package and open a pull request [to nixpkgs](https://github.com/NixOS/nixpkgs/pulls), or use [the Patches category](https://discourse.nixos.org/t/about-the-patches-category/477) on Discourse for sending a patch without a GitHub account.
-152
doc/contributing/quick-start.xml
···11-<chapter xmlns="http://docbook.org/ns/docbook"
22- xmlns:xlink="http://www.w3.org/1999/xlink"
33- xml:id="chap-quick-start">
44- <title>Quick Start to Adding a Package</title>
55- <para>
66- To add a package to Nixpkgs:
77- <orderedlist>
88- <listitem>
99- <para>
1010- Checkout the Nixpkgs source tree:
1111-<screen>
1212-<prompt>$ </prompt>git clone https://github.com/NixOS/nixpkgs
1313-<prompt>$ </prompt>cd nixpkgs</screen>
1414- </para>
1515- </listitem>
1616- <listitem>
1717- <para>
1818- Find a good place in the Nixpkgs tree to add the Nix expression for your package. For instance, a library package typically goes into <filename>pkgs/development/libraries/<replaceable>pkgname</replaceable></filename>, while a web browser goes into <filename>pkgs/applications/networking/browsers/<replaceable>pkgname</replaceable></filename>. See <xref linkend="sec-organisation" /> for some hints on the tree organisation. Create a directory for your package, e.g.
1919-<screen>
2020-<prompt>$ </prompt>mkdir pkgs/development/libraries/libfoo</screen>
2121- </para>
2222- </listitem>
2323- <listitem>
2424- <para>
2525- 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 <emphasis>function</emphasis> 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 <filename>default.nix</filename>.
2626-<screen>
2727-<prompt>$ </prompt>emacs pkgs/development/libraries/libfoo/default.nix
2828-<prompt>$ </prompt>git add pkgs/development/libraries/libfoo/default.nix</screen>
2929- </para>
3030- <para>
3131- You can have a look at the existing Nix expressions under <filename>pkgs/</filename> to see how it’s done. Here are some good ones:
3232- <itemizedlist>
3333- <listitem>
3434- <para>
3535- GNU Hello: <link
3636- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/hello/default.nix"><filename>pkgs/applications/misc/hello/default.nix</filename></link>. Trivial package, which specifies some <varname>meta</varname> attributes which is good practice.
3737- </para>
3838- </listitem>
3939- <listitem>
4040- <para>
4141- GNU cpio: <link
4242- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/archivers/cpio/default.nix"><filename>pkgs/tools/archivers/cpio/default.nix</filename></link>. Also a simple package. The generic builder in <varname>stdenv</varname> does everything for you. It has no dependencies beyond <varname>stdenv</varname>.
4343- </para>
4444- </listitem>
4545- <listitem>
4646- <para>
4747- GNU Multiple Precision arithmetic library (GMP): <link
4848- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/gmp/5.1.x.nix"><filename>pkgs/development/libraries/gmp/5.1.x.nix</filename></link>. Also done by the generic builder, but has a dependency on <varname>m4</varname>.
4949- </para>
5050- </listitem>
5151- <listitem>
5252- <para>
5353- Pan, a GTK-based newsreader: <link
5454- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix"><filename>pkgs/applications/networking/newsreaders/pan/default.nix</filename></link>. Has an optional dependency on <varname>gtkspell</varname>, which is only built if <varname>spellCheck</varname> is <literal>true</literal>.
5555- </para>
5656- </listitem>
5757- <listitem>
5858- <para>
5959- Apache HTTPD: <link
6060- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/http/apache-httpd/2.4.nix"><filename>pkgs/servers/http/apache-httpd/2.4.nix</filename></link>. A bunch of optional features, variable substitutions in the configure flags, a post-install hook, and miscellaneous hackery.
6161- </para>
6262- </listitem>
6363- <listitem>
6464- <para>
6565- Thunderbird: <link
6666- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/mailreaders/thunderbird/default.nix"><filename>pkgs/applications/networking/mailreaders/thunderbird/default.nix</filename></link>. Lots of dependencies.
6767- </para>
6868- </listitem>
6969- <listitem>
7070- <para>
7171- JDiskReport, a Java utility: <link
7272- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/jdiskreport/default.nix"><filename>pkgs/tools/misc/jdiskreport/default.nix</filename></link>. Nixpkgs doesn’t have a decent <varname>stdenv</varname> for Java yet so this is pretty ad-hoc.
7373- </para>
7474- </listitem>
7575- <listitem>
7676- <para>
7777- XML::Simple, a Perl module: <link
7878- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/perl-packages.nix"><filename>pkgs/top-level/perl-packages.nix</filename></link> (search for the <varname>XMLSimple</varname> attribute). Most Perl modules are so simple to build that they are defined directly in <filename>perl-packages.nix</filename>; no need to make a separate file for them.
7979- </para>
8080- </listitem>
8181- <listitem>
8282- <para>
8383- Adobe Reader: <link
8484- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/default.nix"><filename>pkgs/applications/misc/adobe-reader/default.nix</filename></link>. Shows how binary-only packages can be supported. In particular the <link
8585- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/builder.sh">builder</link> uses <command>patchelf</command> to set the RUNPATH and ELF interpreter of the executables so that the right libraries are found at runtime.
8686- </para>
8787- </listitem>
8888- </itemizedlist>
8989- </para>
9090- <para>
9191- Some notes:
9292- <itemizedlist>
9393- <listitem>
9494- <para>
9595- All <varname linkend="chap-meta">meta</varname> attributes are optional, but it’s still a good idea to provide at least the <varname>description</varname>, <varname>homepage</varname> and <varname
9696- linkend="sec-meta-license">license</varname>.
9797- </para>
9898- </listitem>
9999- <listitem>
100100- <para>
101101- You can use <command>nix-prefetch-url</command> <replaceable>url</replaceable> to get the SHA-256 hash of source distributions. There are similar commands as <command>nix-prefetch-git</command> and <command>nix-prefetch-hg</command> available in <literal>nix-prefetch-scripts</literal> package.
102102- </para>
103103- </listitem>
104104- <listitem>
105105- <para>
106106- A list of schemes for <literal>mirror://</literal> URLs can be found in <link
107107- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/fetchurl/mirrors.nix"><filename>pkgs/build-support/fetchurl/mirrors.nix</filename></link>.
108108- </para>
109109- </listitem>
110110- </itemizedlist>
111111- </para>
112112- <para>
113113- The exact syntax and semantics of the Nix expression language, including the built-in function, are described in the Nix manual in the <link
114114- xlink:href="https://hydra.nixos.org/job/nix/trunk/tarball/latest/download-by-type/doc/manual/#chap-writing-nix-expressions">chapter on writing Nix expressions</link>.
115115- </para>
116116- </listitem>
117117- <listitem>
118118- <para>
119119- Add a call to the function defined in the previous step to <link
120120- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix"><filename>pkgs/top-level/all-packages.nix</filename></link> with some descriptive name for the variable, e.g. <varname>libfoo</varname>.
121121-<screen>
122122-<prompt>$ </prompt>emacs pkgs/top-level/all-packages.nix</screen>
123123- </para>
124124- <para>
125125- 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.
126126- </para>
127127- </listitem>
128128- <listitem>
129129- <para>
130130- To test whether the package builds, run the following command from the root of the nixpkgs source tree:
131131-<screen>
132132-<prompt>$ </prompt>nix-build -A libfoo</screen>
133133- where <varname>libfoo</varname> should be the variable name defined in the previous step. You may want to add the flag <option>-K</option> to keep the temporary build directory in case something fails. If the build succeeds, a symlink <filename>./result</filename> to the package in the Nix store is created.
134134- </para>
135135- </listitem>
136136- <listitem>
137137- <para>
138138- If you want to install the package into your profile (optional), do
139139-<screen>
140140-<prompt>$ </prompt>nix-env -f . -iA libfoo</screen>
141141- </para>
142142- </listitem>
143143- <listitem>
144144- <para>
145145- Optionally commit the new package and open a pull request <link
146146- xlink:href="https://github.com/NixOS/nixpkgs/pulls">to nixpkgs</link>, or use <link
147147- xlink:href="https://discourse.nixos.org/t/about-the-patches-category/477"> the Patches category</link> on Discourse for sending a patch without a GitHub account.
148148- </para>
149149- </listitem>
150150- </orderedlist>
151151- </para>
152152-</chapter>
···11+# Reviewing contributions {#chap-reviewing-contributions}
22+33+::: warning
44+The following section is a draft, and the policy for reviewing is still being discussed in issues such as [#11166](https://github.com/NixOS/nixpkgs/issues/11166) and [#20836](https://github.com/NixOS/nixpkgs/issues/20836).
55+:::
66+77+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.
88+99+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](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc) and the [least recently](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-asc) updated pull requests. We highly encourage looking at [this list of ready to merge, unreviewed pull requests](https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+review%3Anone+status%3Asuccess+-label%3A%222.status%3A+work-in-progress%22+no%3Aproject+no%3Aassignee+no%3Amilestone).
1010+1111+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.
1212+1313+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.
1414+1515+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.
1616+1717+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.
1818+1919+## Package updates {#reviewing-contributions-package-updates}
2020+2121+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.
2222+2323+It can happen that non-trivial updates include patches or more complex changes.
2424+2525+Reviewing process:
2626+2727+- Ensure that the package versioning fits the guidelines.
2828+- Ensure that the commit text fits the guidelines.
2929+- Ensure that the package maintainers are notified.
3030+ - [CODEOWNERS](https://help.github.com/articles/about-codeowners) will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers.
3131+- Ensure that the meta field information is correct.
3232+ - License can change with version updates, so it should be checked to match the upstream license.
3333+ - 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.
3434+- Ensure that the code contains no typos.
3535+- Building the package locally.
3636+ - 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.
3737+ - 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.
3838+ ```ShellSession
3939+ $ git fetch origin nixos-unstable
4040+ $ git fetch origin pull/PRNUMBER/head
4141+ $ git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD
4242+ ```
4343+ - The first command fetches the nixos-unstable branch.
4444+ - The second command fetches 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.
4545+ - The third command rebases the pull request changes to the nixos-unstable branch.
4646+ - The [nixpkgs-review](https://github.com/Mic92/nixpkgs-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.
4747+ ```ShellSession
4848+ $ nix-shell -p nixpkgs-review --run "nixpkgs-review pr PRNUMBER"
4949+ ```
5050+- Running every binary.
5151+5252+Sample template for a package update review is provided below.
5353+5454+```markdown
5555+##### Reviewed points
5656+5757+- [ ] package name fits guidelines
5858+- [ ] package version fits guidelines
5959+- [ ] package build on ARCHITECTURE
6060+- [ ] executables tested on ARCHITECTURE
6161+- [ ] all depending packages build
6262+6363+##### Possible improvements
6464+6565+##### Comments
6666+```
6767+6868+## New packages {#reviewing-contributions-new-packages}
6969+7070+New packages are a common type of pull requests. These pull requests consists in adding a new nix-expression for a package.
7171+7272+Review process:
7373+7474+- Ensure that the package versioning fits the guidelines.
7575+- Ensure that the commit name fits the guidelines.
7676+- Ensure that the meta fields contain correct information.
7777+ - License must match the upstream license.
7878+ - Platforms should be set (or the package will not get binary substitutes).
7979+ - Maintainers must be set. This can be the package submitter or a community member that accepts taking up maintainership of the package.
8080+- Report detected typos.
8181+- Ensure the package source:
8282+ - Uses mirror URLs when available.
8383+ - Uses the most appropriate functions (e.g. packages from GitHub should use `fetchFromGitHub`).
8484+- Building the package locally.
8585+- Running every binary.
8686+8787+Sample template for a new package review is provided below.
8888+8989+```markdown
9090+##### Reviewed points
9191+9292+- [ ] package path fits guidelines
9393+- [ ] package name fits guidelines
9494+- [ ] package version fits guidelines
9595+- [ ] package build on ARCHITECTURE
9696+- [ ] executables tested on ARCHITECTURE
9797+- [ ] `meta.description` is set and fits guidelines
9898+- [ ] `meta.license` fits upstream license
9999+- [ ] `meta.platforms` is set
100100+- [ ] `meta.maintainers` is set
101101+- [ ] build time only dependencies are declared in `nativeBuildInputs`
102102+- [ ] source is fetched using the appropriate function
103103+- [ ] phases are respected
104104+- [ ] patches that are remotely available are fetched with `fetchpatch`
105105+106106+##### Possible improvements
107107+108108+##### Comments
109109+```
110110+111111+## Module updates {#reviewing-contributions-module-updates}
112112+113113+Module updates are submissions changing modules in some ways. These often contains changes to the options or introduce new options.
114114+115115+Reviewing process:
116116+117117+- Ensure that the module maintainers are notified.
118118+ - [CODEOWNERS](https://help.github.com/articles/about-codeowners/) will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers.
119119+- Ensure that the module tests, if any, are succeeding.
120120+- Ensure that the introduced options are correct.
121121+ - Type should be appropriate (string related types differs in their merging capabilities, `optionSet` and `string` types are deprecated).
122122+ - Description, default and example should be provided.
123123+- Ensure that option changes are backward compatible.
124124+ - `mkRenamedOptionModule` and `mkAliasOptionModule` functions provide way to make option changes backward compatible.
125125+- Ensure that removed options are declared with `mkRemovedOptionModule`
126126+- Ensure that changes that are not backward compatible are mentioned in release notes.
127127+- Ensure that documentations affected by the change is updated.
128128+129129+Sample template for a module update review is provided below.
130130+131131+```markdown
132132+##### Reviewed points
133133+134134+- [ ] changes are backward compatible
135135+- [ ] removed options are declared with `mkRemovedOptionModule`
136136+- [ ] changes that are not backward compatible are documented in release notes
137137+- [ ] module tests succeed on ARCHITECTURE
138138+- [ ] options types are appropriate
139139+- [ ] options description is set
140140+- [ ] options example is provided
141141+- [ ] documentation affected by the changes is updated
142142+143143+##### Possible improvements
144144+145145+##### Comments
146146+```
147147+148148+## New modules {#reviewing-contributions-new-modules}
149149+150150+New modules submissions introduce a new module to NixOS.
151151+152152+Reviewing process:
153153+154154+- Ensure that the module tests, if any, are succeeding.
155155+- Ensure that the introduced options are correct.
156156+ - Type should be appropriate (string related types differs in their merging capabilities, `optionSet` and `string` types are deprecated).
157157+ - Description, default and example should be provided.
158158+- Ensure that module `meta` field is present
159159+ - Maintainers should be declared in `meta.maintainers`.
160160+ - Module documentation should be declared with `meta.doc`.
161161+- Ensure that the module respect other modules functionality.
162162+ - For example, enabling a module should not open firewall ports by default.
163163+164164+Sample template for a new module review is provided below.
165165+166166+```markdown
167167+##### Reviewed points
168168+169169+- [ ] module path fits the guidelines
170170+- [ ] module tests succeed on ARCHITECTURE
171171+- [ ] options have appropriate types
172172+- [ ] options have default
173173+- [ ] options have example
174174+- [ ] options have descriptions
175175+- [ ] No unneeded package is added to environment.systemPackages
176176+- [ ] meta.maintainers is set
177177+- [ ] module documentation is declared in meta.doc
178178+179179+##### Possible improvements
180180+181181+##### Comments
182182+```
183183+184184+## Other submissions {#reviewing-contributions-other-submissions}
185185+186186+Other type of submissions requires different reviewing steps.
187187+188188+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.
189189+190190+Container system, boot system and library changes are some examples of the pull requests fitting this category.
191191+192192+## Merging pull requests {#reviewing-contributions--merging-pull-requests}
193193+194194+It is possible for community members that have enough knowledge and experience on a special topic to contribute by merging pull requests.
195195+196196+<!--
197197+The following paragraphs about how to deal with unactive contributors is just a proposition and should be modified to what the community agrees to be the right policy.
198198+199199+Please note that contributors with commit rights unactive for more than three months will have their commit rights revoked.
200200+-->
201201+202202+Please see the discussion in [GitHub nixpkgs issue #50105](https://github.com/NixOS/nixpkgs/issues/50105) for information on how to proceed to be granted this level of access.
203203+204204+In a case a contributor definitively leaves the Nix community, they should create an issue or post on [Discourse](https://discourse.nixos.org) with references of packages and modules they maintain so the maintainership can be taken over by other contributors.
-488
doc/contributing/reviewing-contributions.xml
···11-<chapter xmlns="http://docbook.org/ns/docbook"
22- xmlns:xlink="http://www.w3.org/1999/xlink"
33- xmlns:xi="http://www.w3.org/2001/XInclude"
44- version="5.0"
55- xml:id="chap-reviewing-contributions">
66- <title>Reviewing contributions</title>
77- <warning>
88- <para>
99- The following section is a draft, and the policy for reviewing is still being discussed in issues such as <link
1010- xlink:href="https://github.com/NixOS/nixpkgs/issues/11166">#11166 </link> and <link
1111- xlink:href="https://github.com/NixOS/nixpkgs/issues/20836">#20836 </link>.
1212- </para>
1313- </warning>
1414- <para>
1515- 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.
1616- </para>
1717- <para>
1818- 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 <link
1919- xlink:href="https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc">most recently</link> and the <link
2020- xlink:href="https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-asc">least recently</link> updated pull requests. We highly encourage looking at <link xlink:href="https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+review%3Anone+status%3Asuccess+-label%3A%222.status%3A+work-in-progress%22+no%3Aproject+no%3Aassignee+no%3Amilestone"> this list of ready to merge, unreviewed pull requests</link>.
2121- </para>
2222- <para>
2323- 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.
2424- </para>
2525- <para>
2626- 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.
2727- </para>
2828- <para>
2929- 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.
3030- </para>
3131- <para>
3232- 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.
3333- </para>
3434- <section xml:id="reviewing-contributions-package-updates">
3535- <title>Package updates</title>
3636-3737- <para>
3838- 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.
3939- </para>
4040-4141- <para>
4242- It can happen that non-trivial updates include patches or more complex changes.
4343- </para>
4444-4545- <para>
4646- Reviewing process:
4747- </para>
4848-4949- <itemizedlist>
5050- <listitem>
5151- <para>
5252- Ensure that the package versioning fits the guidelines.
5353- </para>
5454- </listitem>
5555- <listitem>
5656- <para>
5757- Ensure that the commit text fits the guidelines.
5858- </para>
5959- </listitem>
6060- <listitem>
6161- <para>
6262- Ensure that the package maintainers are notified.
6363- </para>
6464- <itemizedlist>
6565- <listitem>
6666- <para>
6767- <link xlink:href="https://help.github.com/articles/about-codeowners/">CODEOWNERS</link> will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers.
6868- </para>
6969- </listitem>
7070- </itemizedlist>
7171- </listitem>
7272- <listitem>
7373- <para>
7474- Ensure that the meta field information is correct.
7575- </para>
7676- <itemizedlist>
7777- <listitem>
7878- <para>
7979- License can change with version updates, so it should be checked to match the upstream license.
8080- </para>
8181- </listitem>
8282- <listitem>
8383- <para>
8484- 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.
8585- </para>
8686- </listitem>
8787- </itemizedlist>
8888- </listitem>
8989- <listitem>
9090- <para>
9191- Ensure that the code contains no typos.
9292- </para>
9393- </listitem>
9494- <listitem>
9595- <para>
9696- Building the package locally.
9797- </para>
9898- <itemizedlist>
9999- <listitem>
100100- <para>
101101- 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.
102102- </para>
103103- <para>
104104- 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.
105105-<screen>
106106-<prompt>$ </prompt>git fetch origin nixos-unstable <co xml:id='reviewing-rebase-2' />
107107-<prompt>$ </prompt>git fetch origin pull/PRNUMBER/head <co xml:id='reviewing-rebase-3' />
108108-<prompt>$ </prompt>git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD <co
109109- xml:id='reviewing-rebase-4' />
110110-</screen>
111111- <calloutlist>
112112- <callout arearefs='reviewing-rebase-2'>
113113- <para>
114114- Fetching the nixos-unstable branch.
115115- </para>
116116- </callout>
117117- <callout arearefs='reviewing-rebase-3'>
118118- <para>
119119- Fetching the pull request changes, <varname>PRNUMBER</varname> is the number at the end of the pull request title and <varname>BASEBRANCH</varname> the base branch of the pull request.
120120- </para>
121121- </callout>
122122- <callout arearefs='reviewing-rebase-4'>
123123- <para>
124124- Rebasing the pull request changes to the nixos-unstable branch.
125125- </para>
126126- </callout>
127127- </calloutlist>
128128- </para>
129129- </listitem>
130130- <listitem>
131131- <para>
132132- The <link xlink:href="https://github.com/Mic92/nixpkgs-review">nixpkgs-review</link> tool can be used to review a pull request content in a single command. <varname>PRNUMBER</varname> should be replaced by the number at the end of the pull request title. You can also provide the full github pull request url.
133133- </para>
134134-<screen>
135135-<prompt>$ </prompt>nix-shell -p nixpkgs-review --run "nixpkgs-review pr PRNUMBER"
136136-</screen>
137137- </listitem>
138138- </itemizedlist>
139139- </listitem>
140140- <listitem>
141141- <para>
142142- Running every binary.
143143- </para>
144144- </listitem>
145145- </itemizedlist>
146146-147147- <example xml:id="reviewing-contributions-sample-package-update">
148148- <title>Sample template for a package update review</title>
149149-<screen>
150150-##### Reviewed points
151151-152152-- [ ] package name fits guidelines
153153-- [ ] package version fits guidelines
154154-- [ ] package build on ARCHITECTURE
155155-- [ ] executables tested on ARCHITECTURE
156156-- [ ] all depending packages build
157157-158158-##### Possible improvements
159159-160160-##### Comments
161161-162162-</screen>
163163- </example>
164164- </section>
165165- <section xml:id="reviewing-contributions-new-packages">
166166- <title>New packages</title>
167167-168168- <para>
169169- New packages are a common type of pull requests. These pull requests consists in adding a new nix-expression for a package.
170170- </para>
171171-172172- <para>
173173- Review process:
174174- </para>
175175-176176- <itemizedlist>
177177- <listitem>
178178- <para>
179179- Ensure that the package versioning fits the guidelines.
180180- </para>
181181- </listitem>
182182- <listitem>
183183- <para>
184184- Ensure that the commit name fits the guidelines.
185185- </para>
186186- </listitem>
187187- <listitem>
188188- <para>
189189- Ensure that the meta fields contain correct information.
190190- </para>
191191- <itemizedlist>
192192- <listitem>
193193- <para>
194194- License must match the upstream license.
195195- </para>
196196- </listitem>
197197- <listitem>
198198- <para>
199199- Platforms should be set (or the package will not get binary substitutes).
200200- </para>
201201- </listitem>
202202- <listitem>
203203- <para>
204204- Maintainers must be set. This can be the package submitter or a community member that accepts taking up maintainership of the package.
205205- </para>
206206- </listitem>
207207- </itemizedlist>
208208- </listitem>
209209- <listitem>
210210- <para>
211211- Report detected typos.
212212- </para>
213213- </listitem>
214214- <listitem>
215215- <para>
216216- Ensure the package source:
217217- </para>
218218- <itemizedlist>
219219- <listitem>
220220- <para>
221221- Uses mirror URLs when available.
222222- </para>
223223- </listitem>
224224- <listitem>
225225- <para>
226226- Uses the most appropriate functions (e.g. packages from GitHub should use <literal>fetchFromGitHub</literal>).
227227- </para>
228228- </listitem>
229229- </itemizedlist>
230230- </listitem>
231231- <listitem>
232232- <para>
233233- Building the package locally.
234234- </para>
235235- </listitem>
236236- <listitem>
237237- <para>
238238- Running every binary.
239239- </para>
240240- </listitem>
241241- </itemizedlist>
242242-243243- <example xml:id="reviewing-contributions-sample-new-package">
244244- <title>Sample template for a new package review</title>
245245-<screen>
246246-##### Reviewed points
247247-248248-- [ ] package path fits guidelines
249249-- [ ] package name fits guidelines
250250-- [ ] package version fits guidelines
251251-- [ ] package build on ARCHITECTURE
252252-- [ ] executables tested on ARCHITECTURE
253253-- [ ] `meta.description` is set and fits guidelines
254254-- [ ] `meta.license` fits upstream license
255255-- [ ] `meta.platforms` is set
256256-- [ ] `meta.maintainers` is set
257257-- [ ] build time only dependencies are declared in `nativeBuildInputs`
258258-- [ ] source is fetched using the appropriate function
259259-- [ ] phases are respected
260260-- [ ] patches that are remotely available are fetched with `fetchpatch`
261261-262262-##### Possible improvements
263263-264264-##### Comments
265265-266266-</screen>
267267- </example>
268268- </section>
269269- <section xml:id="reviewing-contributions-module-updates">
270270- <title>Module updates</title>
271271-272272- <para>
273273- Module updates are submissions changing modules in some ways. These often contains changes to the options or introduce new options.
274274- </para>
275275-276276- <para>
277277- Reviewing process
278278- </para>
279279-280280- <itemizedlist>
281281- <listitem>
282282- <para>
283283- Ensure that the module maintainers are notified.
284284- </para>
285285- <itemizedlist>
286286- <listitem>
287287- <para>
288288- <link xlink:href="https://help.github.com/articles/about-codeowners/">CODEOWNERS</link> will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers.
289289- </para>
290290- </listitem>
291291- </itemizedlist>
292292- </listitem>
293293- <listitem>
294294- <para>
295295- Ensure that the module tests, if any, are succeeding.
296296- </para>
297297- </listitem>
298298- <listitem>
299299- <para>
300300- Ensure that the introduced options are correct.
301301- </para>
302302- <itemizedlist>
303303- <listitem>
304304- <para>
305305- Type should be appropriate (string related types differs in their merging capabilities, <literal>optionSet</literal> and <literal>string</literal> types are deprecated).
306306- </para>
307307- </listitem>
308308- <listitem>
309309- <para>
310310- Description, default and example should be provided.
311311- </para>
312312- </listitem>
313313- </itemizedlist>
314314- </listitem>
315315- <listitem>
316316- <para>
317317- Ensure that option changes are backward compatible.
318318- </para>
319319- <itemizedlist>
320320- <listitem>
321321- <para>
322322- <literal>mkRenamedOptionModule</literal> and <literal>mkAliasOptionModule</literal> functions provide way to make option changes backward compatible.
323323- </para>
324324- </listitem>
325325- </itemizedlist>
326326- </listitem>
327327- <listitem>
328328- <para>
329329- Ensure that removed options are declared with <literal>mkRemovedOptionModule</literal>
330330- </para>
331331- </listitem>
332332- <listitem>
333333- <para>
334334- Ensure that changes that are not backward compatible are mentioned in release notes.
335335- </para>
336336- </listitem>
337337- <listitem>
338338- <para>
339339- Ensure that documentations affected by the change is updated.
340340- </para>
341341- </listitem>
342342- </itemizedlist>
343343-344344- <example xml:id="reviewing-contributions-sample-module-update">
345345- <title>Sample template for a module update review</title>
346346-<screen>
347347-##### Reviewed points
348348-349349-- [ ] changes are backward compatible
350350-- [ ] removed options are declared with `mkRemovedOptionModule`
351351-- [ ] changes that are not backward compatible are documented in release notes
352352-- [ ] module tests succeed on ARCHITECTURE
353353-- [ ] options types are appropriate
354354-- [ ] options description is set
355355-- [ ] options example is provided
356356-- [ ] documentation affected by the changes is updated
357357-358358-##### Possible improvements
359359-360360-##### Comments
361361-362362-</screen>
363363- </example>
364364- </section>
365365- <section xml:id="reviewing-contributions-new-modules">
366366- <title>New modules</title>
367367-368368- <para>
369369- New modules submissions introduce a new module to NixOS.
370370- </para>
371371-372372- <itemizedlist>
373373- <listitem>
374374- <para>
375375- Ensure that the module tests, if any, are succeeding.
376376- </para>
377377- </listitem>
378378- <listitem>
379379- <para>
380380- Ensure that the introduced options are correct.
381381- </para>
382382- <itemizedlist>
383383- <listitem>
384384- <para>
385385- Type should be appropriate (string related types differs in their merging capabilities, <literal>optionSet</literal> and <literal>string</literal> types are deprecated).
386386- </para>
387387- </listitem>
388388- <listitem>
389389- <para>
390390- Description, default and example should be provided.
391391- </para>
392392- </listitem>
393393- </itemizedlist>
394394- </listitem>
395395- <listitem>
396396- <para>
397397- Ensure that module <literal>meta</literal> field is present
398398- </para>
399399- <itemizedlist>
400400- <listitem>
401401- <para>
402402- Maintainers should be declared in <literal>meta.maintainers</literal>.
403403- </para>
404404- </listitem>
405405- <listitem>
406406- <para>
407407- Module documentation should be declared with <literal>meta.doc</literal>.
408408- </para>
409409- </listitem>
410410- </itemizedlist>
411411- </listitem>
412412- <listitem>
413413- <para>
414414- Ensure that the module respect other modules functionality.
415415- </para>
416416- <itemizedlist>
417417- <listitem>
418418- <para>
419419- For example, enabling a module should not open firewall ports by default.
420420- </para>
421421- </listitem>
422422- </itemizedlist>
423423- </listitem>
424424- </itemizedlist>
425425-426426- <example xml:id="reviewing-contributions-sample-new-module">
427427- <title>Sample template for a new module review</title>
428428-<screen>
429429-##### Reviewed points
430430-431431-- [ ] module path fits the guidelines
432432-- [ ] module tests succeed on ARCHITECTURE
433433-- [ ] options have appropriate types
434434-- [ ] options have default
435435-- [ ] options have example
436436-- [ ] options have descriptions
437437-- [ ] No unneeded package is added to environment.systemPackages
438438-- [ ] meta.maintainers is set
439439-- [ ] module documentation is declared in meta.doc
440440-441441-##### Possible improvements
442442-443443-##### Comments
444444-445445-</screen>
446446- </example>
447447- </section>
448448- <section xml:id="reviewing-contributions-other-submissions">
449449- <title>Other submissions</title>
450450-451451- <para>
452452- Other type of submissions requires different reviewing steps.
453453- </para>
454454-455455- <para>
456456- 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.
457457- </para>
458458-459459- <para>
460460- Container system, boot system and library changes are some examples of the pull requests fitting this category.
461461- </para>
462462- </section>
463463- <section xml:id="reviewing-contributions--merging-pull-requests">
464464- <title>Merging pull requests</title>
465465-466466- <para>
467467- It is possible for community members that have enough knowledge and experience on a special topic to contribute by merging pull requests.
468468- </para>
469469-470470-<!--
471471-The following paragraphs about how to deal with unactive contributors is just a
472472-proposition and should be modified to what the community agrees to be the right
473473-policy.
474474-475475-<para>Please note that contributors with commit rights unactive for more than
476476- three months will have their commit rights revoked.</para>
477477--->
478478-479479- <para>
480480- Please see the discussion in <link xlink:href="https://github.com/NixOS/nixpkgs/issues/50105">GitHub nixpkgs issue #50105</link> for information on how to proceed to be granted this level of access.
481481- </para>
482482-483483- <para>
484484- In a case a contributor definitively leaves the Nix community, they should create an issue or post on <link
485485- xlink:href="https://discourse.nixos.org">Discourse</link> with references of packages and modules they maintain so the maintainership can be taken over by other contributors.
486486- </para>
487487- </section>
488488-</chapter>
···188188 </varlistentry>
189189 <varlistentry>
190190 <term>
191191+ <methodname>get_screen_text_variants</methodname>
192192+ </term>
193193+ <listitem>
194194+ <para>
195195+ Return a list of different interpretations of what is currently visible
196196+ on the machine's screen using optical character recognition. The number
197197+ and order of the interpretations is not specified and is subject to
198198+ change, but if no exception is raised at least one will be returned.
199199+ </para>
200200+ <note>
201201+ <para>
202202+ This requires passing <option>enableOCR</option> to the test attribute
203203+ set.
204204+ </para>
205205+ </note>
206206+ </listitem>
207207+ </varlistentry>
208208+ <varlistentry>
209209+ <term>
191210 <methodname>get_screen_text</methodname>
192211 </term>
193212 <listitem>
···350369 <para>
351370 Wait until the supplied regular expressions matches the textual contents
352371 of the screen by using optical character recognition (see
353353- <methodname>get_screen_text</methodname>).
372372+ <methodname>get_screen_text</methodname> and
373373+ <methodname>get_screen_text_variants</methodname>).
354374 </para>
355375 <note>
356376 <para>
+48-31
nixos/lib/test-driver/test-driver.py
···11#! /somewhere/python3
22from contextlib import contextmanager, _GeneratorContextManager
33from queue import Queue, Empty
44-from typing import Tuple, Any, Callable, Dict, Iterator, Optional, List
44+from typing import Tuple, Any, Callable, Dict, Iterator, Optional, List, Iterable
55from xml.sax.saxutils import XMLGenerator
66import queue
77import io
···203203 self.log("({:.2f} seconds)".format(toc - tic))
204204205205 self.xml.endElement("nest")
206206+207207+208208+def _perform_ocr_on_screenshot(
209209+ screenshot_path: str, model_ids: Iterable[int]
210210+) -> List[str]:
211211+ if shutil.which("tesseract") is None:
212212+ raise Exception("OCR requested but enableOCR is false")
213213+214214+ magick_args = (
215215+ "-filter Catrom -density 72 -resample 300 "
216216+ + "-contrast -normalize -despeckle -type grayscale "
217217+ + "-sharpen 1 -posterize 3 -negate -gamma 100 "
218218+ + "-blur 1x65535"
219219+ )
220220+221221+ tess_args = f"-c debug_file=/dev/null --psm 11"
222222+223223+ cmd = f"convert {magick_args} {screenshot_path} tiff:{screenshot_path}.tiff"
224224+ ret = subprocess.run(cmd, shell=True, capture_output=True)
225225+ if ret.returncode != 0:
226226+ raise Exception(f"TIFF conversion failed with exit code {ret.returncode}")
227227+228228+ model_results = []
229229+ for model_id in model_ids:
230230+ cmd = f"tesseract {screenshot_path}.tiff - {tess_args} --oem {model_id}"
231231+ ret = subprocess.run(cmd, shell=True, capture_output=True)
232232+ if ret.returncode != 0:
233233+ raise Exception(f"OCR failed with exit code {ret.returncode}")
234234+ model_results.append(ret.stdout.decode("utf-8"))
235235+236236+ return model_results
206237207238208239class Machine:
···637668 """Debugging: Dump the contents of the TTY<n>"""
638669 self.execute("fold -w 80 /dev/vcs{} | systemd-cat".format(tty))
639670640640- def get_screen_text(self) -> str:
641641- if shutil.which("tesseract") is None:
642642- raise Exception("get_screen_text used but enableOCR is false")
671671+ def _get_screen_text_variants(self, model_ids: Iterable[int]) -> List[str]:
672672+ with tempfile.TemporaryDirectory() as tmpdir:
673673+ screenshot_path = os.path.join(tmpdir, "ppm")
674674+ self.send_monitor_command(f"screendump {screenshot_path}")
675675+ return _perform_ocr_on_screenshot(screenshot_path, model_ids)
643676644644- magick_args = (
645645- "-filter Catrom -density 72 -resample 300 "
646646- + "-contrast -normalize -despeckle -type grayscale "
647647- + "-sharpen 1 -posterize 3 -negate -gamma 100 "
648648- + "-blur 1x65535"
649649- )
650650-651651- tess_args = "-c debug_file=/dev/null --psm 11 --oem 2"
652652-653653- with self.nested("performing optical character recognition"):
654654- with tempfile.NamedTemporaryFile() as tmpin:
655655- self.send_monitor_command("screendump {}".format(tmpin.name))
656656-657657- cmd = "convert {} {} tiff:- | tesseract - - {}".format(
658658- magick_args, tmpin.name, tess_args
659659- )
660660- ret = subprocess.run(cmd, shell=True, capture_output=True)
661661- if ret.returncode != 0:
662662- raise Exception(
663663- "OCR failed with exit code {}".format(ret.returncode)
664664- )
677677+ def get_screen_text_variants(self) -> List[str]:
678678+ return self._get_screen_text_variants([0, 1, 2])
665679666666- return ret.stdout.decode("utf-8")
680680+ def get_screen_text(self) -> str:
681681+ return self._get_screen_text_variants([2])[0]
667682668683 def wait_for_text(self, regex: str) -> None:
669684 def screen_matches(last: bool) -> bool:
670670- text = self.get_screen_text()
671671- matches = re.search(regex, text) is not None
685685+ variants = self.get_screen_text_variants()
686686+ for text in variants:
687687+ if re.search(regex, text) is not None:
688688+ return True
672689673673- if last and not matches:
674674- self.log("Last OCR attempt failed. Text was: {}".format(text))
690690+ if last:
691691+ self.log("Last OCR attempt failed. Text was: {}".format(variants))
675692676676- return matches
693693+ return False
677694678695 with self.nested("waiting for {} to appear on screen".format(regex)):
679696 retry(screen_matches)
···1010 extensions = { enabled, all }:
1111 (with all;
1212 enabled
1313- ++ optional (!cfg.disableImagemagick) imagick
1313+ ++ optional cfg.enableImagemagick imagick
1414 # Optionally enabled depending on caching settings
1515 ++ optional cfg.caching.apcu apcu
1616 ++ optional cfg.caching.redis redis
···62626363 Further details about this can be found in the `Nextcloud`-section of the NixOS-manual
6464 (which can be openend e.g. by running `nixos-help`).
6565+ '')
6666+ (mkRemovedOptionModule [ "services" "nextcloud" "disableImagemagick" ] ''
6767+ Use services.nextcloud.nginx.enableImagemagick instead.
6568 '')
6669 ];
6770···303306 };
304307 };
305308306306- disableImagemagick = mkOption {
307307- type = types.bool;
308308- default = false;
309309- description = ''
310310- Whether to not load the ImageMagick module into PHP.
309309+ enableImagemagick = mkEnableOption ''
310310+ Whether to load the ImageMagick module into PHP.
311311 This is used by the theming app and for generating previews of certain images (e.g. SVG and HEIF).
312312 You may want to disable it for increased security. In that case, previews will still be available
313313 for some images (e.g. JPEG and PNG).
314314 See https://github.com/nextcloud/server/issues/13099
315315- '';
315315+ '' // {
316316+ default = true;
316317 };
317318318319 caching = {
···661661 # fine with newer versions.
662662 spagoWithOverrides = doJailbreak super.spago;
663663664664- # This defines the version of the purescript-docs-search release we are using.
665665- # This is defined in the src/Spago/Prelude.hs file in the spago source.
666666- docsSearchVersion = "v0.0.10";
664664+ docsSearchApp_0_0_10 = pkgs.fetchurl {
665665+ url = "https://github.com/purescript/purescript-docs-search/releases/download/v0.0.10/docs-search-app.js";
666666+ sha256 = "0m5ah29x290r0zk19hx2wix2djy7bs4plh9kvjz6bs9r45x25pa5";
667667+ };
667668668668- docsSearchAppJsFile = pkgs.fetchurl {
669669- url = "https://github.com/spacchetti/purescript-docs-search/releases/download/${docsSearchVersion}/docs-search-app.js";
670670- sha256 = "0m5ah29x290r0zk19hx2wix2djy7bs4plh9kvjz6bs9r45x25pa5";
669669+ docsSearchApp_0_0_11 = pkgs.fetchurl {
670670+ url = "https://github.com/purescript/purescript-docs-search/releases/download/v0.0.11/docs-search-app.js";
671671+ sha256 = "17qngsdxfg96cka1cgrl3zdrpal8ll6vyhhnazqm4hwj16ywjm02";
671672 };
672673673673- purescriptDocsSearchFile = pkgs.fetchurl {
674674- url = "https://github.com/spacchetti/purescript-docs-search/releases/download/${docsSearchVersion}/purescript-docs-search";
674674+ purescriptDocsSearch_0_0_10 = pkgs.fetchurl {
675675+ url = "https://github.com/purescript/purescript-docs-search/releases/download/v0.0.10/purescript-docs-search";
675676 sha256 = "0wc1zyhli4m2yykc6i0crm048gyizxh7b81n8xc4yb7ibjqwhyj3";
676677 };
677678679679+ purescriptDocsSearch_0_0_11 = pkgs.fetchurl {
680680+ url = "https://github.com/purescript/purescript-docs-search/releases/download/v0.0.11/purescript-docs-search";
681681+ sha256 = "1hjdprm990vyxz86fgq14ajn0lkams7i00h8k2i2g1a0hjdwppq6";
682682+ };
683683+678684 spagoFixHpack = overrideCabal spagoWithOverrides (drv: {
679685 postUnpack = (drv.postUnpack or "") + ''
680686 # The source for spago is pulled directly from GitHub. It uses a
···695701 # However, they are not actually available in the spago source, so they
696702 # need to fetched with nix and put in the correct place.
697703 # https://github.com/spacchetti/spago/issues/510
698698- cp ${docsSearchAppJsFile} "$sourceRoot/templates/docs-search-app.js"
699699- cp ${purescriptDocsSearchFile} "$sourceRoot/templates/purescript-docs-search"
704704+ cp ${docsSearchApp_0_0_10} "$sourceRoot/templates/docs-search-app-0.0.10.js"
705705+ cp ${docsSearchApp_0_0_11} "$sourceRoot/templates/docs-search-app-0.0.11.js"
706706+ cp ${purescriptDocsSearch_0_0_10} "$sourceRoot/templates/purescript-docs-search-0.0.10"
707707+ cp ${purescriptDocsSearch_0_0_11} "$sourceRoot/templates/purescript-docs-search-0.0.11"
700708701709 # For some weird reason, on Darwin, the open(2) call to embed these files
702710 # requires write permissions. The easiest resolution is just to permit that
703711 # (doesn't cause any harm on other systems).
704704- chmod u+w "$sourceRoot/templates/docs-search-app.js" "$sourceRoot/templates/purescript-docs-search"
712712+ chmod u+w \
713713+ "$sourceRoot/templates/docs-search-app-0.0.10.js" \
714714+ "$sourceRoot/templates/purescript-docs-search-0.0.10" \
715715+ "$sourceRoot/templates/docs-search-app-0.0.11.js" \
716716+ "$sourceRoot/templates/purescript-docs-search-0.0.11"
705717 '';
706718 });
707719
···210210 kernelCompatible = kernel.kernelAtLeast "3.10" && kernel.kernelOlder "5.12";
211211212212 # this package should point to a version / git revision compatible with the latest kernel release
213213- version = "2.1.0-rc3";
213213+ version = "2.1.0-rc4";
214214215215- sha256 = "sha256-ARRUuyu07dWwEuXerTz9KBmclhlmsnnGucfBxxn0Zsw=";
215215+ sha256 = "sha256-eakOEA7LCJOYDsZH24Y5JbEd2wh1KfCN+qX3QxQZ4e8=";
216216217217 isUnstable = true;
218218 };
···10101111buildGoModule rec {
1212 pname = "bettercap";
1313- version = "2.30.2";
1313+ version = "2.31.0";
14141515 src = fetchFromGitHub {
1616 owner = pname;
1717 repo = pname;
1818 rev = "v${version}";
1919- sha256 = "sha256-5CAWMW0u/8BUn/8JJBApyHGH+/Tz8hzAmSChoT2gFr8=";
1919+ sha256 = "sha256-PmS4ox1ZaHrBGJAdNByott61rEvfmR1ZJ12ut0MGtrc=";
2020 };
21212222- vendorSha256 = "sha256-fApxHxdzEEc+M+U5f0271VgrkXTGkUD75BpDXpVYd5k=";
2222+ vendorSha256 = "sha256-3j64Z4BQhAbUtoHJ6IT1SCsKxSeYZRxSO3K2Nx9Vv4w=";
23232424 doCheck = false;
2525···3030 meta = with lib; {
3131 description = "A man in the middle tool";
3232 longDescription = ''
3333- BetterCAP is a powerful, flexible and portable tool created to perform various types of MITM attacks against a network, manipulate HTTP, HTTPS and TCP traffic in realtime, sniff for credentials and much more.
3333+ BetterCAP is a powerful, flexible and portable tool created to perform various
3434+ types of MITM attacks against a network, manipulate HTTP, HTTPS and TCP traffic
3535+ in realtime, sniff for credentials and much more.
3436 '';
3537 homepage = "https://www.bettercap.org/";
3636- license = with licenses; gpl3;
3838+ license = with licenses; [ gpl3Only ];
3739 maintainers = with maintainers; [ y0no ];
3840 };
3941}