···1+# Coding conventions {#chap-conventions}
2+3+## Syntax {#sec-syntax}
4+5+- Use 2 spaces of indentation per indentation level in Nix expressions, 4 spaces in shell scripts.
6+7+- 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.
8+9+- 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"/>.
10+11+- Function calls with attribute set arguments are written as
12+13+ ```nix
14+ foo {
15+ arg = ...;
16+ }
17+ ```
18+19+ not
20+21+ ```nix
22+ foo
23+ {
24+ arg = ...;
25+ }
26+ ```
27+28+ Also fine is
29+30+ ```nix
31+ foo { arg = ...; }
32+ ```
33+34+ if it's a short call.
35+36+- In attribute sets or lists that span multiple lines, the attribute names or list elements should be aligned:
37+38+ ```nix
39+ # A long list.
40+ list = [
41+ elem1
42+ elem2
43+ elem3
44+ ];
45+46+ # A long attribute set.
47+ attrs = {
48+ attr1 = short_expr;
49+ attr2 =
50+ if true then big_expr else big_expr;
51+ };
52+53+ # Combined
54+ listOfAttrs = [
55+ {
56+ attr1 = 3;
57+ attr2 = "fff";
58+ }
59+ {
60+ attr1 = 5;
61+ attr2 = "ggg";
62+ }
63+ ];
64+ ```
65+66+- Short lists or attribute sets can be written on one line:
67+68+ ```nix
69+ # A short list.
70+ list = [ elem1 elem2 elem3 ];
71+72+ # A short set.
73+ attrs = { x = 1280; y = 1024; };
74+ ```
75+76+- Breaking in the middle of a function argument can give hard-to-read code, like
77+78+ ```nix
79+ someFunction { x = 1280;
80+ y = 1024; } otherArg
81+ yetAnotherArg
82+ ```
83+84+ (especially if the argument is very large, spanning multiple lines).
85+86+ Better:
87+88+ ```nix
89+ someFunction
90+ { x = 1280; y = 1024; }
91+ otherArg
92+ yetAnotherArg
93+ ```
94+95+ or
96+97+ ```nix
98+ let res = { x = 1280; y = 1024; };
99+ in someFunction res otherArg yetAnotherArg
100+ ```
101+102+- The bodies of functions, asserts, and withs are not indented to prevent a lot of superfluous indentation levels, i.e.
103+104+ ```nix
105+ { arg1, arg2 }:
106+ assert system == "i686-linux";
107+ stdenv.mkDerivation { ...
108+ ```
109+110+ not
111+112+ ```nix
113+ { arg1, arg2 }:
114+ assert system == "i686-linux";
115+ stdenv.mkDerivation { ...
116+ ```
117+118+- Function formal arguments are written as:
119+120+ ```nix
121+ { arg1, arg2, arg3 }:
122+ ```
123+124+ but if they don't fit on one line they're written as:
125+126+ ```nix
127+ { arg1, arg2, arg3
128+ , arg4, ...
129+ , # Some comment...
130+ argN
131+ }:
132+ ```
133+134+- Functions should list their expected arguments as precisely as possible. That is, write
135+136+ ```nix
137+ { stdenv, fetchurl, perl }: ...
138+ ```
139+140+ instead of
141+142+ ```nix
143+ args: with args; ...
144+ ```
145+146+ or
147+148+ ```nix
149+ { stdenv, fetchurl, perl, ... }: ...
150+ ```
151+152+ 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:
153+154+ ```nix
155+ { stdenv, doCoverageAnalysis ? false, ... } @ args:
156+157+ stdenv.mkDerivation (args // {
158+ ... if doCoverageAnalysis then "bla" else "" ...
159+ })
160+ ```
161+162+ instead of
163+164+ ```nix
165+ args:
166+167+ args.stdenv.mkDerivation (args // {
168+ ... if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else "" ...
169+ })
170+ ```
171+172+- Arguments should be listed in the order they are used, with the exception of `lib`, which always goes first.
173+174+- 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.
175+176+## Package naming {#sec-package-naming}
177+178+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.
179+180+In Nixpkgs, there are generally three different names associated with a package:
181+182+- The `name` attribute of the derivation (excluding the version part). This is what most users see, in particular when using `nix-env`.
183+184+- 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`.
185+186+- The filename for (the directory containing) the Nix expression.
187+188+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`.
189+190+There are a few naming guidelines:
191+192+- The `name` attribute _should_ be identical to the upstream package name.
193+194+- The `name` attribute _must not_ contain uppercase letters — e.g., `"mplayer-1.0rc2"` instead of `"MPlayer-1.0rc2"`.
195+196+- The version part of the `name` attribute _must_ start with a digit (following a dash) — e.g., `"hello-0.3.1rc2"`.
197+198+- 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"`.
199+200+- 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.
201+202+- 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" />
203+204+## File naming and organisation {#sec-organisation}
205+206+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`.
207+208+### Hierarchy {#sec-hierarchy}
209+210+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`.
211+212+When in doubt, consider refactoring the `pkgs/` tree, e.g. creating new categories or splitting up an existing category.
213+214+**If it’s used to support _software development_:**
215+216+- **If it’s a _library_ used by other packages:**
217+218+ - `development/libraries` (e.g. `libxml2`)
219+220+- **If it’s a _compiler_:**
221+222+ - `development/compilers` (e.g. `gcc`)
223+224+- **If it’s an _interpreter_:**
225+226+ - `development/interpreters` (e.g. `guile`)
227+228+- **If it’s a (set of) development _tool(s)_:**
229+230+ - **If it’s a _parser generator_ (including lexers):**
231+232+ - `development/tools/parsing` (e.g. `bison`, `flex`)
233+234+ - **If it’s a _build manager_:**
235+236+ - `development/tools/build-managers` (e.g. `gnumake`)
237+238+ - **Else:**
239+240+ - `development/tools/misc` (e.g. `binutils`)
241+242+- **Else:**
243+244+ - `development/misc`
245+246+**If it’s a (set of) _tool(s)_:**
247+248+(A tool is a relatively small program, especially one intended to be used non-interactively.)
249+250+- **If it’s for _networking_:**
251+252+ - `tools/networking` (e.g. `wget`)
253+254+- **If it’s for _text processing_:**
255+256+ - `tools/text` (e.g. `diffutils`)
257+258+- **If it’s a _system utility_, i.e., something related or essential to the operation of a system:**
259+260+ - `tools/system` (e.g. `cron`)
261+262+- **If it’s an _archiver_ (which may include a compression function):**
263+264+ - `tools/archivers` (e.g. `zip`, `tar`)
265+266+- **If it’s a _compression_ program:**
267+268+ - `tools/compression` (e.g. `gzip`, `bzip2`)
269+270+- **If it’s a _security_-related program:**
271+272+ - `tools/security` (e.g. `nmap`, `gnupg`)
273+274+- **Else:**
275+276+ - `tools/misc`
277+278+**If it’s a _shell_:**
279+280+- `shells` (e.g. `bash`)
281+282+**If it’s a _server_:**
283+284+- **If it’s a web server:**
285+286+ - `servers/http` (e.g. `apache-httpd`)
287+288+- **If it’s an implementation of the X Windowing System:**
289+290+ - `servers/x11` (e.g. `xorg` — this includes the client libraries and programs)
291+292+- **Else:**
293+294+ - `servers/misc`
295+296+**If it’s a _desktop environment_:**
297+298+- `desktops` (e.g. `kde`, `gnome`, `enlightenment`)
299+300+**If it’s a _window manager_:**
301+302+- `applications/window-managers` (e.g. `awesome`, `stumpwm`)
303+304+**If it’s an _application_:**
305+306+A (typically large) program with a distinct user interface, primarily used interactively.
307+308+- **If it’s a _version management system_:**
309+310+ - `applications/version-management` (e.g. `subversion`)
311+312+- **If it’s a _terminal emulator_:**
313+314+ - `applications/terminal-emulators` (e.g. `alacritty` or `rxvt` or `termite`)
315+316+- **If it’s for _video playback / editing_:**
317+318+ - `applications/video` (e.g. `vlc`)
319+320+- **If it’s for _graphics viewing / editing_:**
321+322+ - `applications/graphics` (e.g. `gimp`)
323+324+- **If it’s for _networking_:**
325+326+ - **If it’s a _mailreader_:**
327+328+ - `applications/networking/mailreaders` (e.g. `thunderbird`)
329+330+ - **If it’s a _newsreader_:**
331+332+ - `applications/networking/newsreaders` (e.g. `pan`)
333+334+ - **If it’s a _web browser_:**
335+336+ - `applications/networking/browsers` (e.g. `firefox`)
337+338+ - **Else:**
339+340+ - `applications/networking/misc`
341+342+- **Else:**
343+344+ - `applications/misc`
345+346+**If it’s _data_ (i.e., does not have a straight-forward executable semantics):**
347+348+- **If it’s a _font_:**
349+350+ - `data/fonts`
351+352+- **If it’s an _icon theme_:**
353+354+ - `data/icons`
355+356+- **If it’s related to _SGML/XML processing_:**
357+358+ - **If it’s an _XML DTD_:**
359+360+ - `data/sgml+xml/schemas/xml-dtd` (e.g. `docbook`)
361+362+ - **If it’s an _XSLT stylesheet_:**
363+364+ (Okay, these are executable...)
365+366+ - `data/sgml+xml/stylesheets/xslt` (e.g. `docbook-xsl`)
367+368+- **If it’s a _theme_ for a _desktop environment_, a _window manager_ or a _display manager_:**
369+370+ - `data/themes`
371+372+**If it’s a _game_:**
373+374+- `games`
375+376+**Else:**
377+378+- `misc`
379+380+### Versioning {#sec-versioning}
381+382+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.
383+384+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`.
385+386+All versions of a package _must_ be included in `all-packages.nix` to make sure that they evaluate correctly.
387+388+## Fetching Sources {#sec-sources}
389+390+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.
391+392+You can find many source fetch helpers in `pkgs/build-support/fetch*`.
393+394+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:
395+396+- Bad: Uses `git://` which won't be proxied.
397+398+ ```nix
399+ src = fetchgit {
400+ url = "git://github.com/NixOS/nix.git";
401+ rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
402+ sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg";
403+ }
404+ ```
405+406+- Better: This is ok, but an archive fetch will still be faster.
407+408+ ```nix
409+ src = fetchgit {
410+ url = "https://github.com/NixOS/nix.git";
411+ rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
412+ sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg";
413+ }
414+ ```
415+416+- Best: Fetches a snapshot archive and you get the rev you want.
417+418+ ```nix
419+ src = fetchFromGitHub {
420+ owner = "NixOS";
421+ repo = "nix";
422+ rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
423+ sha256 = "1i2yxndxb6yc9l6c99pypbd92lfq5aac4klq7y2v93c9qvx2cgpc";
424+ }
425+ ```
426+427+ 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`.
428+429+## Obtaining source hash {#sec-source-hashes}
430+431+Preferred source hash type is sha256. There are several ways to get it.
432+433+1. Prefetch URL (with `nix-prefetch-XXX URL`, where `XXX` is one of `url`, `git`, `hg`, `cvs`, `bzr`, `svn`). Hash is printed to stdout.
434+435+2. Prefetch by package source (with `nix-prefetch-url '<nixpkgs>' -A PACKAGE.src`, where `PACKAGE` is package attribute name). Hash is printed to stdout.
436+437+ 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).
438+439+3. Upstream provided hash: use it when upstream provides `sha256` or `sha512` (when upstream provides `md5`, don't use it, compute `sha256` instead).
440+441+ 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.
442+443+ You can convert between formats with nix-hash, for example:
444+445+ ```ShellSession
446+ $ nix-hash --type sha256 --to-base32 HASH
447+ ```
448+449+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.
450+451+5. Fake hash: set fake hash in package expression, perform build and extract correct hash from error Nix prints.
452+453+ 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.
454+455+ 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.
456+457+::: warning
458+This method has security problems. Check below for details.
459+:::
460+461+### Obtaining hashes securely {#sec-source-hashes-security}
462+463+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:
464+465+- `http://` URLs are not secure to prefetch hash from;
466+467+- hashes from upstream (in method 3) should be obtained via secure protocol;
468+469+- `https://` URLs are secure in methods 1, 2, 3;
470+471+- `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.
472+473+## Patches {#sec-patches}
474+475+Patches available online should be retrieved using `fetchpatch`.
476+477+```nix
478+patches = [
479+ (fetchpatch {
480+ name = "fix-check-for-using-shared-freetype-lib.patch";
481+ url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=8f5d285";
482+ sha256 = "1f0k043rng7f0rfl9hhb89qzvvksqmkrikmm38p61yfx51l325xr";
483+ })
484+];
485+```
486+487+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.
488+489+```nix
490+patches = [ ./0001-changes.patch ];
491+```
492+493+If you do need to do create this sort of patch file, one way to do so is with git:
494+495+1. Move to the root directory of the source code you're patching.
496+497+ ```ShellSession
498+ $ cd the/program/source
499+ ```
500+501+2. If a git repository is not already present, create one and stage all of the source files.
502+503+ ```ShellSession
504+ $ git init
505+ $ git add .
506+ ```
507+508+3. Edit some files to make whatever changes need to be included in the patch.
509+510+4. Use git to create a diff, and pipe the output to a patch file:
511+512+ ```ShellSession
513+ $ git diff > nixpkgs/pkgs/the/package/0001-changes.patch
514+ ```
-943
doc/contributing/coding-conventions.xml
···1-<chapter xmlns="http://docbook.org/ns/docbook"
2- xmlns:xlink="http://www.w3.org/1999/xlink"
3- xml:id="chap-conventions">
4- <title>Coding conventions</title>
5- <section xml:id="sec-syntax">
6- <title>Syntax</title>
7-8- <itemizedlist>
9- <listitem>
10- <para>
11- Use 2 spaces of indentation per indentation level in Nix expressions, 4 spaces in shell scripts.
12- </para>
13- </listitem>
14- <listitem>
15- <para>
16- 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.
17- </para>
18- </listitem>
19- <listitem>
20- <para>
21- 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"/>.
22- </para>
23- </listitem>
24- <listitem>
25- <para>
26- Function calls with attribute set arguments are written as
27-<programlisting>
28-foo {
29- arg = ...;
30-}
31-</programlisting>
32- not
33-<programlisting>
34-foo
35-{
36- arg = ...;
37-}
38-</programlisting>
39- Also fine is
40-<programlisting>
41-foo { arg = ...; }
42-</programlisting>
43- if it's a short call.
44- </para>
45- </listitem>
46- <listitem>
47- <para>
48- In attribute sets or lists that span multiple lines, the attribute names or list elements should be aligned:
49-<programlisting>
50-# A long list.
51-list = [
52- elem1
53- elem2
54- elem3
55-];
56-57-# A long attribute set.
58-attrs = {
59- attr1 = short_expr;
60- attr2 =
61- if true then big_expr else big_expr;
62-};
63-64-# Combined
65-listOfAttrs = [
66- {
67- attr1 = 3;
68- attr2 = "fff";
69- }
70- {
71- attr1 = 5;
72- attr2 = "ggg";
73- }
74-];
75-</programlisting>
76- </para>
77- </listitem>
78- <listitem>
79- <para>
80- Short lists or attribute sets can be written on one line:
81-<programlisting>
82-# A short list.
83-list = [ elem1 elem2 elem3 ];
84-85-# A short set.
86-attrs = { x = 1280; y = 1024; };
87-</programlisting>
88- </para>
89- </listitem>
90- <listitem>
91- <para>
92- Breaking in the middle of a function argument can give hard-to-read code, like
93-<programlisting>
94-someFunction { x = 1280;
95- y = 1024; } otherArg
96- yetAnotherArg
97-</programlisting>
98- (especially if the argument is very large, spanning multiple lines).
99- </para>
100- <para>
101- Better:
102-<programlisting>
103-someFunction
104- { x = 1280; y = 1024; }
105- otherArg
106- yetAnotherArg
107-</programlisting>
108- or
109-<programlisting>
110-let res = { x = 1280; y = 1024; };
111-in someFunction res otherArg yetAnotherArg
112-</programlisting>
113- </para>
114- </listitem>
115- <listitem>
116- <para>
117- The bodies of functions, asserts, and withs are not indented to prevent a lot of superfluous indentation levels, i.e.
118-<programlisting>
119-{ arg1, arg2 }:
120-assert system == "i686-linux";
121-stdenv.mkDerivation { ...
122-</programlisting>
123- not
124-<programlisting>
125-{ arg1, arg2 }:
126- assert system == "i686-linux";
127- stdenv.mkDerivation { ...
128-</programlisting>
129- </para>
130- </listitem>
131- <listitem>
132- <para>
133- Function formal arguments are written as:
134-<programlisting>
135-{ arg1, arg2, arg3 }:
136-</programlisting>
137- but if they don't fit on one line they're written as:
138-<programlisting>
139-{ arg1, arg2, arg3
140-, arg4, ...
141-, # Some comment...
142- argN
143-}:
144-</programlisting>
145- </para>
146- </listitem>
147- <listitem>
148- <para>
149- Functions should list their expected arguments as precisely as possible. That is, write
150-<programlisting>
151-{ stdenv, fetchurl, perl }: <replaceable>...</replaceable>
152-</programlisting>
153- instead of
154-<programlisting>
155-args: with args; <replaceable>...</replaceable>
156-</programlisting>
157- or
158-<programlisting>
159-{ stdenv, fetchurl, perl, ... }: <replaceable>...</replaceable>
160-</programlisting>
161- </para>
162- <para>
163- 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:
164-<programlisting>
165-{ stdenv, doCoverageAnalysis ? false, ... } @ args:
166-167-stdenv.mkDerivation (args // {
168- <replaceable>...</replaceable> if doCoverageAnalysis then "bla" else "" <replaceable>...</replaceable>
169-})
170-</programlisting>
171- instead of
172-<programlisting>
173-args:
174-175-args.stdenv.mkDerivation (args // {
176- <replaceable>...</replaceable> if args ? doCoverageAnalysis && args.doCoverageAnalysis then "bla" else "" <replaceable>...</replaceable>
177-})
178-</programlisting>
179- </para>
180- </listitem>
181- <listitem>
182- <para>
183- Arguments should be listed in the order they are used, with the exception of <varname>lib</varname>, which always goes first.
184- </para>
185- </listitem>
186- <listitem>
187- <para>
188- 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.
189- </para>
190- </listitem>
191- </itemizedlist>
192- </section>
193- <section xml:id="sec-package-naming">
194- <title>Package naming</title>
195-196- <para>
197- 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.
198- </para>
199-200- <para>
201- In Nixpkgs, there are generally three different names associated with a package:
202- <itemizedlist>
203- <listitem>
204- <para>
205- 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>.
206- </para>
207- </listitem>
208- <listitem>
209- <para>
210- 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>.
211- </para>
212- </listitem>
213- <listitem>
214- <para>
215- The filename for (the directory containing) the Nix expression.
216- </para>
217- </listitem>
218- </itemizedlist>
219- 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>.
220- </para>
221-222- <para>
223- There are a few naming guidelines:
224- <itemizedlist>
225- <listitem>
226- <para>
227- The <literal>name</literal> attribute <emphasis>should</emphasis> be identical to the upstream package name.
228- </para>
229- </listitem>
230- <listitem>
231- <para>
232- 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>.
233- </para>
234- </listitem>
235- <listitem>
236- <para>
237- 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>.
238- </para>
239- </listitem>
240- <listitem>
241- <para>
242- 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>.
243- </para>
244- </listitem>
245- <listitem>
246- <para>
247- 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.
248- </para>
249- </listitem>
250- <listitem>
251- <para>
252- 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" />
253- </para>
254- </listitem>
255- </itemizedlist>
256- </para>
257- </section>
258- <section xml:id="sec-organisation">
259- <title>File naming and organisation</title>
260-261- <para>
262- 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>.
263- </para>
264-265- <section xml:id="sec-hierarchy">
266- <title>Hierarchy</title>
267-268- <para>
269- 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>.
270- </para>
271-272- <para>
273- When in doubt, consider refactoring the <filename>pkgs/</filename> tree, e.g. creating new categories or splitting up an existing category.
274- </para>
275-276- <variablelist>
277- <varlistentry>
278- <term>
279- If it’s used to support <emphasis>software development</emphasis>:
280- </term>
281- <listitem>
282- <variablelist>
283- <varlistentry>
284- <term>
285- If it’s a <emphasis>library</emphasis> used by other packages:
286- </term>
287- <listitem>
288- <para>
289- <filename>development/libraries</filename> (e.g. <filename>libxml2</filename>)
290- </para>
291- </listitem>
292- </varlistentry>
293- <varlistentry>
294- <term>
295- If it’s a <emphasis>compiler</emphasis>:
296- </term>
297- <listitem>
298- <para>
299- <filename>development/compilers</filename> (e.g. <filename>gcc</filename>)
300- </para>
301- </listitem>
302- </varlistentry>
303- <varlistentry>
304- <term>
305- If it’s an <emphasis>interpreter</emphasis>:
306- </term>
307- <listitem>
308- <para>
309- <filename>development/interpreters</filename> (e.g. <filename>guile</filename>)
310- </para>
311- </listitem>
312- </varlistentry>
313- <varlistentry>
314- <term>
315- If it’s a (set of) development <emphasis>tool(s)</emphasis>:
316- </term>
317- <listitem>
318- <variablelist>
319- <varlistentry>
320- <term>
321- If it’s a <emphasis>parser generator</emphasis> (including lexers):
322- </term>
323- <listitem>
324- <para>
325- <filename>development/tools/parsing</filename> (e.g. <filename>bison</filename>, <filename>flex</filename>)
326- </para>
327- </listitem>
328- </varlistentry>
329- <varlistentry>
330- <term>
331- If it’s a <emphasis>build manager</emphasis>:
332- </term>
333- <listitem>
334- <para>
335- <filename>development/tools/build-managers</filename> (e.g. <filename>gnumake</filename>)
336- </para>
337- </listitem>
338- </varlistentry>
339- <varlistentry>
340- <term>
341- Else:
342- </term>
343- <listitem>
344- <para>
345- <filename>development/tools/misc</filename> (e.g. <filename>binutils</filename>)
346- </para>
347- </listitem>
348- </varlistentry>
349- </variablelist>
350- </listitem>
351- </varlistentry>
352- <varlistentry>
353- <term>
354- Else:
355- </term>
356- <listitem>
357- <para>
358- <filename>development/misc</filename>
359- </para>
360- </listitem>
361- </varlistentry>
362- </variablelist>
363- </listitem>
364- </varlistentry>
365- <varlistentry>
366- <term>
367- If it’s a (set of) <emphasis>tool(s)</emphasis>:
368- </term>
369- <listitem>
370- <para>
371- (A tool is a relatively small program, especially one intended to be used non-interactively.)
372- </para>
373- <variablelist>
374- <varlistentry>
375- <term>
376- If it’s for <emphasis>networking</emphasis>:
377- </term>
378- <listitem>
379- <para>
380- <filename>tools/networking</filename> (e.g. <filename>wget</filename>)
381- </para>
382- </listitem>
383- </varlistentry>
384- <varlistentry>
385- <term>
386- If it’s for <emphasis>text processing</emphasis>:
387- </term>
388- <listitem>
389- <para>
390- <filename>tools/text</filename> (e.g. <filename>diffutils</filename>)
391- </para>
392- </listitem>
393- </varlistentry>
394- <varlistentry>
395- <term>
396- If it’s a <emphasis>system utility</emphasis>, i.e., something related or essential to the operation of a system:
397- </term>
398- <listitem>
399- <para>
400- <filename>tools/system</filename> (e.g. <filename>cron</filename>)
401- </para>
402- </listitem>
403- </varlistentry>
404- <varlistentry>
405- <term>
406- If it’s an <emphasis>archiver</emphasis> (which may include a compression function):
407- </term>
408- <listitem>
409- <para>
410- <filename>tools/archivers</filename> (e.g. <filename>zip</filename>, <filename>tar</filename>)
411- </para>
412- </listitem>
413- </varlistentry>
414- <varlistentry>
415- <term>
416- If it’s a <emphasis>compression</emphasis> program:
417- </term>
418- <listitem>
419- <para>
420- <filename>tools/compression</filename> (e.g. <filename>gzip</filename>, <filename>bzip2</filename>)
421- </para>
422- </listitem>
423- </varlistentry>
424- <varlistentry>
425- <term>
426- If it’s a <emphasis>security</emphasis>-related program:
427- </term>
428- <listitem>
429- <para>
430- <filename>tools/security</filename> (e.g. <filename>nmap</filename>, <filename>gnupg</filename>)
431- </para>
432- </listitem>
433- </varlistentry>
434- <varlistentry>
435- <term>
436- Else:
437- </term>
438- <listitem>
439- <para>
440- <filename>tools/misc</filename>
441- </para>
442- </listitem>
443- </varlistentry>
444- </variablelist>
445- </listitem>
446- </varlistentry>
447- <varlistentry>
448- <term>
449- If it’s a <emphasis>shell</emphasis>:
450- </term>
451- <listitem>
452- <para>
453- <filename>shells</filename> (e.g. <filename>bash</filename>)
454- </para>
455- </listitem>
456- </varlistentry>
457- <varlistentry>
458- <term>
459- If it’s a <emphasis>server</emphasis>:
460- </term>
461- <listitem>
462- <variablelist>
463- <varlistentry>
464- <term>
465- If it’s a web server:
466- </term>
467- <listitem>
468- <para>
469- <filename>servers/http</filename> (e.g. <filename>apache-httpd</filename>)
470- </para>
471- </listitem>
472- </varlistentry>
473- <varlistentry>
474- <term>
475- If it’s an implementation of the X Windowing System:
476- </term>
477- <listitem>
478- <para>
479- <filename>servers/x11</filename> (e.g. <filename>xorg</filename> — this includes the client libraries and programs)
480- </para>
481- </listitem>
482- </varlistentry>
483- <varlistentry>
484- <term>
485- Else:
486- </term>
487- <listitem>
488- <para>
489- <filename>servers/misc</filename>
490- </para>
491- </listitem>
492- </varlistentry>
493- </variablelist>
494- </listitem>
495- </varlistentry>
496- <varlistentry>
497- <term>
498- If it’s a <emphasis>desktop environment</emphasis>:
499- </term>
500- <listitem>
501- <para>
502- <filename>desktops</filename> (e.g. <filename>kde</filename>, <filename>gnome</filename>, <filename>enlightenment</filename>)
503- </para>
504- </listitem>
505- </varlistentry>
506- <varlistentry>
507- <term>
508- If it’s a <emphasis>window manager</emphasis>:
509- </term>
510- <listitem>
511- <para>
512- <filename>applications/window-managers</filename> (e.g. <filename>awesome</filename>, <filename>stumpwm</filename>)
513- </para>
514- </listitem>
515- </varlistentry>
516- <varlistentry>
517- <term>
518- If it’s an <emphasis>application</emphasis>:
519- </term>
520- <listitem>
521- <para>
522- A (typically large) program with a distinct user interface, primarily used interactively.
523- </para>
524- <variablelist>
525- <varlistentry>
526- <term>
527- If it’s a <emphasis>version management system</emphasis>:
528- </term>
529- <listitem>
530- <para>
531- <filename>applications/version-management</filename> (e.g. <filename>subversion</filename>)
532- </para>
533- </listitem>
534- </varlistentry>
535- <varlistentry>
536- <term>
537- If it’s a <emphasis>terminal emulator</emphasis>:
538- </term>
539- <listitem>
540- <para>
541- <filename>applications/terminal-emulators</filename> (e.g. <filename>alacritty</filename> or <filename>rxvt</filename> or <filename>termite</filename>)
542- </para>
543- </listitem>
544- </varlistentry>
545- <varlistentry>
546- <term>
547- If it’s for <emphasis>video playback / editing</emphasis>:
548- </term>
549- <listitem>
550- <para>
551- <filename>applications/video</filename> (e.g. <filename>vlc</filename>)
552- </para>
553- </listitem>
554- </varlistentry>
555- <varlistentry>
556- <term>
557- If it’s for <emphasis>graphics viewing / editing</emphasis>:
558- </term>
559- <listitem>
560- <para>
561- <filename>applications/graphics</filename> (e.g. <filename>gimp</filename>)
562- </para>
563- </listitem>
564- </varlistentry>
565- <varlistentry>
566- <term>
567- If it’s for <emphasis>networking</emphasis>:
568- </term>
569- <listitem>
570- <variablelist>
571- <varlistentry>
572- <term>
573- If it’s a <emphasis>mailreader</emphasis>:
574- </term>
575- <listitem>
576- <para>
577- <filename>applications/networking/mailreaders</filename> (e.g. <filename>thunderbird</filename>)
578- </para>
579- </listitem>
580- </varlistentry>
581- <varlistentry>
582- <term>
583- If it’s a <emphasis>newsreader</emphasis>:
584- </term>
585- <listitem>
586- <para>
587- <filename>applications/networking/newsreaders</filename> (e.g. <filename>pan</filename>)
588- </para>
589- </listitem>
590- </varlistentry>
591- <varlistentry>
592- <term>
593- If it’s a <emphasis>web browser</emphasis>:
594- </term>
595- <listitem>
596- <para>
597- <filename>applications/networking/browsers</filename> (e.g. <filename>firefox</filename>)
598- </para>
599- </listitem>
600- </varlistentry>
601- <varlistentry>
602- <term>
603- Else:
604- </term>
605- <listitem>
606- <para>
607- <filename>applications/networking/misc</filename>
608- </para>
609- </listitem>
610- </varlistentry>
611- </variablelist>
612- </listitem>
613- </varlistentry>
614- <varlistentry>
615- <term>
616- Else:
617- </term>
618- <listitem>
619- <para>
620- <filename>applications/misc</filename>
621- </para>
622- </listitem>
623- </varlistentry>
624- </variablelist>
625- </listitem>
626- </varlistentry>
627- <varlistentry>
628- <term>
629- If it’s <emphasis>data</emphasis> (i.e., does not have a straight-forward executable semantics):
630- </term>
631- <listitem>
632- <variablelist>
633- <varlistentry>
634- <term>
635- If it’s a <emphasis>font</emphasis>:
636- </term>
637- <listitem>
638- <para>
639- <filename>data/fonts</filename>
640- </para>
641- </listitem>
642- </varlistentry>
643- <varlistentry>
644- <term>
645- If it’s an <emphasis>icon theme</emphasis>:
646- </term>
647- <listitem>
648- <para>
649- <filename>data/icons</filename>
650- </para>
651- </listitem>
652- </varlistentry>
653- <varlistentry>
654- <term>
655- If it’s related to <emphasis>SGML/XML processing</emphasis>:
656- </term>
657- <listitem>
658- <variablelist>
659- <varlistentry>
660- <term>
661- If it’s an <emphasis>XML DTD</emphasis>:
662- </term>
663- <listitem>
664- <para>
665- <filename>data/sgml+xml/schemas/xml-dtd</filename> (e.g. <filename>docbook</filename>)
666- </para>
667- </listitem>
668- </varlistentry>
669- <varlistentry>
670- <term>
671- If it’s an <emphasis>XSLT stylesheet</emphasis>:
672- </term>
673- <listitem>
674- <para>
675- (Okay, these are executable...)
676- </para>
677- <para>
678- <filename>data/sgml+xml/stylesheets/xslt</filename> (e.g. <filename>docbook-xsl</filename>)
679- </para>
680- </listitem>
681- </varlistentry>
682- </variablelist>
683- </listitem>
684- </varlistentry>
685- <varlistentry>
686- <term>
687- If it’s a <emphasis>theme</emphasis> for a <emphasis>desktop environment</emphasis>, a <emphasis>window manager</emphasis> or a <emphasis>display manager</emphasis>:
688- </term>
689- <listitem>
690- <para>
691- <filename>data/themes</filename>
692- </para>
693- </listitem>
694- </varlistentry>
695- </variablelist>
696- </listitem>
697- </varlistentry>
698- <varlistentry>
699- <term>
700- If it’s a <emphasis>game</emphasis>:
701- </term>
702- <listitem>
703- <para>
704- <filename>games</filename>
705- </para>
706- </listitem>
707- </varlistentry>
708- <varlistentry>
709- <term>
710- Else:
711- </term>
712- <listitem>
713- <para>
714- <filename>misc</filename>
715- </para>
716- </listitem>
717- </varlistentry>
718- </variablelist>
719- </section>
720-721- <section xml:id="sec-versioning">
722- <title>Versioning</title>
723-724- <para>
725- 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.
726- </para>
727-728- <para>
729- 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>.
730- </para>
731-732- <para>
733- All versions of a package <emphasis>must</emphasis> be included in <filename>all-packages.nix</filename> to make sure that they evaluate correctly.
734- </para>
735- </section>
736- </section>
737- <section xml:id="sec-sources">
738- <title>Fetching Sources</title>
739-740- <para>
741- 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.
742- </para>
743-744- <para>
745- You can find many source fetch helpers in <literal>pkgs/build-support/fetch*</literal>.
746- </para>
747-748- <para>
749- 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:
750- <itemizedlist>
751- <listitem>
752- <para>
753- Bad: Uses <literal>git://</literal> which won't be proxied.
754-<programlisting>
755-src = fetchgit {
756- url = "git://github.com/NixOS/nix.git";
757- rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
758- sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg";
759-}
760-</programlisting>
761- </para>
762- </listitem>
763- <listitem>
764- <para>
765- Better: This is ok, but an archive fetch will still be faster.
766-<programlisting>
767-src = fetchgit {
768- url = "https://github.com/NixOS/nix.git";
769- rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
770- sha256 = "1cw5fszffl5pkpa6s6wjnkiv6lm5k618s32sp60kvmvpy7a2v9kg";
771-}
772-</programlisting>
773- </para>
774- </listitem>
775- <listitem>
776- <para>
777- Best: Fetches a snapshot archive and you get the rev you want.
778-<programlisting>
779-src = fetchFromGitHub {
780- owner = "NixOS";
781- repo = "nix";
782- rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
783- sha256 = "1i2yxndxb6yc9l6c99pypbd92lfq5aac4klq7y2v93c9qvx2cgpc";
784-}
785-</programlisting>
786- 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>.
787- </para>
788- </listitem>
789- </itemizedlist>
790- </para>
791- </section>
792- <section xml:id="sec-source-hashes">
793- <title>Obtaining source hash</title>
794-795- <para>
796- Preferred source hash type is sha256. There are several ways to get it.
797- </para>
798-799- <orderedlist>
800- <listitem>
801- <para>
802- 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.
803- </para>
804- </listitem>
805- <listitem>
806- <para>
807- 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.
808- </para>
809- <para>
810- 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).
811- </para>
812- </listitem>
813- <listitem>
814- <para>
815- 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).
816- </para>
817- <para>
818- 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.
819- </para>
820- <para>
821- You can convert between formats with nix-hash, for example:
822-<screen>
823-<prompt>$ </prompt>nix-hash --type sha256 --to-base32 <replaceable>HASH</replaceable>
824-</screen>
825- </para>
826- </listitem>
827- <listitem>
828- <para>
829- 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.
830- </para>
831- </listitem>
832- <listitem>
833- <para>
834- Fake hash: set fake hash in package expression, perform build and extract correct hash from error Nix prints.
835- </para>
836- <para>
837- 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.
838- </para>
839- <para>
840- 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.
841- </para>
842- <warning>
843- <para>
844- This method has security problems. Check below for details.
845- </para>
846- </warning>
847- </listitem>
848- </orderedlist>
849-850- <section xml:id="sec-source-hashes-security">
851- <title>Obtaining hashes securely</title>
852-853- <para>
854- 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:
855- </para>
856-857- <itemizedlist>
858- <listitem>
859- <para>
860- <literal>http://</literal> URLs are not secure to prefetch hash from;
861- </para>
862- </listitem>
863- <listitem>
864- <para>
865- hashes from upstream (in method 3) should be obtained via secure protocol;
866- </para>
867- </listitem>
868- <listitem>
869- <para>
870- <literal>https://</literal> URLs are secure in methods 1, 2, 3;
871- </para>
872- </listitem>
873- <listitem>
874- <para>
875- <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.
876- </para>
877- </listitem>
878- </itemizedlist>
879- </section>
880- </section>
881- <section xml:id="sec-patches">
882- <title>Patches</title>
883-884- <para>
885- Patches available online should be retrieved using <literal>fetchpatch</literal>.
886- </para>
887-888- <para>
889-<programlisting>
890-patches = [
891- (fetchpatch {
892- name = "fix-check-for-using-shared-freetype-lib.patch";
893- url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=8f5d285";
894- sha256 = "1f0k043rng7f0rfl9hhb89qzvvksqmkrikmm38p61yfx51l325xr";
895- })
896-];
897-</programlisting>
898- </para>
899-900- <para>
901- 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.
902- </para>
903-904- <para>
905-<programlisting>
906-patches = [ ./0001-changes.patch ];
907-</programlisting>
908- </para>
909-910- <para>
911- If you do need to do create this sort of patch file, one way to do so is with git:
912- <orderedlist>
913- <listitem>
914- <para>
915- Move to the root directory of the source code you're patching.
916-<screen>
917-<prompt>$ </prompt>cd the/program/source</screen>
918- </para>
919- </listitem>
920- <listitem>
921- <para>
922- If a git repository is not already present, create one and stage all of the source files.
923-<screen>
924-<prompt>$ </prompt>git init
925-<prompt>$ </prompt>git add .</screen>
926- </para>
927- </listitem>
928- <listitem>
929- <para>
930- Edit some files to make whatever changes need to be included in the patch.
931- </para>
932- </listitem>
933- <listitem>
934- <para>
935- Use git to create a diff, and pipe the output to a patch file:
936-<screen>
937-<prompt>$ </prompt>git diff > nixpkgs/pkgs/the/package/0001-changes.patch</screen>
938- </para>
939- </listitem>
940- </orderedlist>
941- </para>
942- </section>
943-</chapter>
···1+# Contributing to this documentation {#chap-contributing}
2+3+The DocBook sources of the Nixpkgs manual are in the [doc](https://github.com/NixOS/nixpkgs/tree/master/doc) subdirectory of the Nixpkgs repository.
4+5+You can quickly check your edits with `make`:
6+7+```ShellSession
8+$ cd /path/to/nixpkgs/doc
9+$ nix-shell
10+[nix-shell]$ make $makeFlags
11+```
12+13+If you experience problems, run `make debug` to help understand the docbook errors.
14+15+After making modifications to the manual, it's important to build it before committing. You can do that as follows:
16+17+```ShellSession
18+$ cd /path/to/nixpkgs/doc
19+$ nix-shell
20+[nix-shell]$ make clean
21+[nix-shell]$ nix-build .
22+```
23+24+If the build succeeds, the manual will be in `./result/share/doc/nixpkgs/manual.html`.
···1-<chapter xmlns="http://docbook.org/ns/docbook"
2- xmlns:xlink="http://www.w3.org/1999/xlink"
3- xml:id="chap-contributing">
4- <title>Contributing to this documentation</title>
5- <para>
6- The DocBook sources of the Nixpkgs manual are in the <filename
7-xlink:href="https://github.com/NixOS/nixpkgs/tree/master/doc">doc</filename> subdirectory of the Nixpkgs repository.
8- </para>
9- <para>
10- You can quickly check your edits with <command>make</command>:
11- </para>
12-<screen>
13-<prompt>$ </prompt>cd /path/to/nixpkgs/doc
14-<prompt>$ </prompt>nix-shell
15-<prompt>[nix-shell]$ </prompt>make $makeFlags
16-</screen>
17- <para>
18- If you experience problems, run <command>make debug</command> to help understand the docbook errors.
19- </para>
20- <para>
21- After making modifications to the manual, it's important to build it before committing. You can do that as follows:
22-<screen>
23-<prompt>$ </prompt>cd /path/to/nixpkgs/doc
24-<prompt>$ </prompt>nix-shell
25-<prompt>[nix-shell]$ </prompt>make clean
26-<prompt>[nix-shell]$ </prompt>nix-build .
27-</screen>
28- If the build succeeds, the manual will be in <filename>./result/share/doc/nixpkgs/manual.html</filename>.
29- </para>
30-</chapter>
···1+# Quick Start to Adding a Package {#chap-quick-start}
2+3+To add a package to Nixpkgs:
4+5+1. Checkout the Nixpkgs source tree:
6+7+ ```ShellSession
8+ $ git clone https://github.com/NixOS/nixpkgs
9+ $ cd nixpkgs
10+ ```
11+12+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.
13+14+ ```ShellSession
15+ $ mkdir pkgs/development/libraries/libfoo
16+ ```
17+18+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`.
19+20+ ```ShellSession
21+ $ emacs pkgs/development/libraries/libfoo/default.nix
22+ $ git add pkgs/development/libraries/libfoo/default.nix
23+ ```
24+25+ You can have a look at the existing Nix expressions under `pkgs/` to see how it’s done. Here are some good ones:
26+27+ - 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.
28+29+ - 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`.
30+31+ - 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`.
32+33+ - 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`.
34+35+ - 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.
36+37+ - 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.
38+39+ - 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.
40+41+ - 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.
42+43+ - 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.
44+45+ Some notes:
46+47+ - 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).
48+49+ - 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.
50+51+ - 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).
52+53+ 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).
54+55+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`.
56+57+ ```ShellSession
58+ $ emacs pkgs/top-level/all-packages.nix
59+ ```
60+61+ 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.
62+63+5. To test whether the package builds, run the following command from the root of the nixpkgs source tree:
64+65+ ```ShellSession
66+ $ nix-build -A libfoo
67+ ```
68+69+ 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.
70+71+6. If you want to install the package into your profile (optional), do
72+73+ ```ShellSession
74+ $ nix-env -f . -iA libfoo
75+ ```
76+77+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
···1-<chapter xmlns="http://docbook.org/ns/docbook"
2- xmlns:xlink="http://www.w3.org/1999/xlink"
3- xml:id="chap-quick-start">
4- <title>Quick Start to Adding a Package</title>
5- <para>
6- To add a package to Nixpkgs:
7- <orderedlist>
8- <listitem>
9- <para>
10- Checkout the Nixpkgs source tree:
11-<screen>
12-<prompt>$ </prompt>git clone https://github.com/NixOS/nixpkgs
13-<prompt>$ </prompt>cd nixpkgs</screen>
14- </para>
15- </listitem>
16- <listitem>
17- <para>
18- 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.
19-<screen>
20-<prompt>$ </prompt>mkdir pkgs/development/libraries/libfoo</screen>
21- </para>
22- </listitem>
23- <listitem>
24- <para>
25- 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>.
26-<screen>
27-<prompt>$ </prompt>emacs pkgs/development/libraries/libfoo/default.nix
28-<prompt>$ </prompt>git add pkgs/development/libraries/libfoo/default.nix</screen>
29- </para>
30- <para>
31- 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:
32- <itemizedlist>
33- <listitem>
34- <para>
35- GNU Hello: <link
36- 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.
37- </para>
38- </listitem>
39- <listitem>
40- <para>
41- GNU cpio: <link
42- 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>.
43- </para>
44- </listitem>
45- <listitem>
46- <para>
47- GNU Multiple Precision arithmetic library (GMP): <link
48- 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>.
49- </para>
50- </listitem>
51- <listitem>
52- <para>
53- Pan, a GTK-based newsreader: <link
54- 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>.
55- </para>
56- </listitem>
57- <listitem>
58- <para>
59- Apache HTTPD: <link
60- 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.
61- </para>
62- </listitem>
63- <listitem>
64- <para>
65- Thunderbird: <link
66- 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.
67- </para>
68- </listitem>
69- <listitem>
70- <para>
71- JDiskReport, a Java utility: <link
72- 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.
73- </para>
74- </listitem>
75- <listitem>
76- <para>
77- XML::Simple, a Perl module: <link
78- 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.
79- </para>
80- </listitem>
81- <listitem>
82- <para>
83- Adobe Reader: <link
84- 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
85- 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.
86- </para>
87- </listitem>
88- </itemizedlist>
89- </para>
90- <para>
91- Some notes:
92- <itemizedlist>
93- <listitem>
94- <para>
95- 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
96- linkend="sec-meta-license">license</varname>.
97- </para>
98- </listitem>
99- <listitem>
100- <para>
101- 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.
102- </para>
103- </listitem>
104- <listitem>
105- <para>
106- A list of schemes for <literal>mirror://</literal> URLs can be found in <link
107- xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/fetchurl/mirrors.nix"><filename>pkgs/build-support/fetchurl/mirrors.nix</filename></link>.
108- </para>
109- </listitem>
110- </itemizedlist>
111- </para>
112- <para>
113- The exact syntax and semantics of the Nix expression language, including the built-in function, are described in the Nix manual in the <link
114- 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>.
115- </para>
116- </listitem>
117- <listitem>
118- <para>
119- Add a call to the function defined in the previous step to <link
120- 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>.
121-<screen>
122-<prompt>$ </prompt>emacs pkgs/top-level/all-packages.nix</screen>
123- </para>
124- <para>
125- 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.
126- </para>
127- </listitem>
128- <listitem>
129- <para>
130- To test whether the package builds, run the following command from the root of the nixpkgs source tree:
131-<screen>
132-<prompt>$ </prompt>nix-build -A libfoo</screen>
133- 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.
134- </para>
135- </listitem>
136- <listitem>
137- <para>
138- If you want to install the package into your profile (optional), do
139-<screen>
140-<prompt>$ </prompt>nix-env -f . -iA libfoo</screen>
141- </para>
142- </listitem>
143- <listitem>
144- <para>
145- Optionally commit the new package and open a pull request <link
146- xlink:href="https://github.com/NixOS/nixpkgs/pulls">to nixpkgs</link>, or use <link
147- 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.
148- </para>
149- </listitem>
150- </orderedlist>
151- </para>
152-</chapter>
···1+# Reviewing contributions {#chap-reviewing-contributions}
2+3+::: warning
4+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).
5+:::
6+7+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.
8+9+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).
10+11+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.
12+13+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.
14+15+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.
16+17+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.
18+19+## Package updates {#reviewing-contributions-package-updates}
20+21+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.
22+23+It can happen that non-trivial updates include patches or more complex changes.
24+25+Reviewing process:
26+27+- Ensure that the package versioning fits the guidelines.
28+- Ensure that the commit text fits the guidelines.
29+- Ensure that the package maintainers are notified.
30+ - [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.
31+- Ensure that the meta field information is correct.
32+ - License can change with version updates, so it should be checked to match the upstream license.
33+ - 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.
34+- Ensure that the code contains no typos.
35+- Building the package locally.
36+ - 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.
37+ - 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.
38+ ```ShellSession
39+ $ git fetch origin nixos-unstable
40+ $ git fetch origin pull/PRNUMBER/head
41+ $ git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD
42+ ```
43+ - The first command fetches the nixos-unstable branch.
44+ - 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.
45+ - The third command rebases the pull request changes to the nixos-unstable branch.
46+ - 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.
47+ ```ShellSession
48+ $ nix-shell -p nixpkgs-review --run "nixpkgs-review pr PRNUMBER"
49+ ```
50+- Running every binary.
51+52+Sample template for a package update review is provided below.
53+54+```markdown
55+##### Reviewed points
56+57+- [ ] package name fits guidelines
58+- [ ] package version fits guidelines
59+- [ ] package build on ARCHITECTURE
60+- [ ] executables tested on ARCHITECTURE
61+- [ ] all depending packages build
62+63+##### Possible improvements
64+65+##### Comments
66+```
67+68+## New packages {#reviewing-contributions-new-packages}
69+70+New packages are a common type of pull requests. These pull requests consists in adding a new nix-expression for a package.
71+72+Review process:
73+74+- Ensure that the package versioning fits the guidelines.
75+- Ensure that the commit name fits the guidelines.
76+- Ensure that the meta fields contain correct information.
77+ - License must match the upstream license.
78+ - Platforms should be set (or the package will not get binary substitutes).
79+ - Maintainers must be set. This can be the package submitter or a community member that accepts taking up maintainership of the package.
80+- Report detected typos.
81+- Ensure the package source:
82+ - Uses mirror URLs when available.
83+ - Uses the most appropriate functions (e.g. packages from GitHub should use `fetchFromGitHub`).
84+- Building the package locally.
85+- Running every binary.
86+87+Sample template for a new package review is provided below.
88+89+```markdown
90+##### Reviewed points
91+92+- [ ] package path fits guidelines
93+- [ ] package name fits guidelines
94+- [ ] package version fits guidelines
95+- [ ] package build on ARCHITECTURE
96+- [ ] executables tested on ARCHITECTURE
97+- [ ] `meta.description` is set and fits guidelines
98+- [ ] `meta.license` fits upstream license
99+- [ ] `meta.platforms` is set
100+- [ ] `meta.maintainers` is set
101+- [ ] build time only dependencies are declared in `nativeBuildInputs`
102+- [ ] source is fetched using the appropriate function
103+- [ ] phases are respected
104+- [ ] patches that are remotely available are fetched with `fetchpatch`
105+106+##### Possible improvements
107+108+##### Comments
109+```
110+111+## Module updates {#reviewing-contributions-module-updates}
112+113+Module updates are submissions changing modules in some ways. These often contains changes to the options or introduce new options.
114+115+Reviewing process:
116+117+- Ensure that the module maintainers are notified.
118+ - [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.
119+- Ensure that the module tests, if any, are succeeding.
120+- Ensure that the introduced options are correct.
121+ - Type should be appropriate (string related types differs in their merging capabilities, `optionSet` and `string` types are deprecated).
122+ - Description, default and example should be provided.
123+- Ensure that option changes are backward compatible.
124+ - `mkRenamedOptionModule` and `mkAliasOptionModule` functions provide way to make option changes backward compatible.
125+- Ensure that removed options are declared with `mkRemovedOptionModule`
126+- Ensure that changes that are not backward compatible are mentioned in release notes.
127+- Ensure that documentations affected by the change is updated.
128+129+Sample template for a module update review is provided below.
130+131+```markdown
132+##### Reviewed points
133+134+- [ ] changes are backward compatible
135+- [ ] removed options are declared with `mkRemovedOptionModule`
136+- [ ] changes that are not backward compatible are documented in release notes
137+- [ ] module tests succeed on ARCHITECTURE
138+- [ ] options types are appropriate
139+- [ ] options description is set
140+- [ ] options example is provided
141+- [ ] documentation affected by the changes is updated
142+143+##### Possible improvements
144+145+##### Comments
146+```
147+148+## New modules {#reviewing-contributions-new-modules}
149+150+New modules submissions introduce a new module to NixOS.
151+152+Reviewing process:
153+154+- Ensure that the module tests, if any, are succeeding.
155+- Ensure that the introduced options are correct.
156+ - Type should be appropriate (string related types differs in their merging capabilities, `optionSet` and `string` types are deprecated).
157+ - Description, default and example should be provided.
158+- Ensure that module `meta` field is present
159+ - Maintainers should be declared in `meta.maintainers`.
160+ - Module documentation should be declared with `meta.doc`.
161+- Ensure that the module respect other modules functionality.
162+ - For example, enabling a module should not open firewall ports by default.
163+164+Sample template for a new module review is provided below.
165+166+```markdown
167+##### Reviewed points
168+169+- [ ] module path fits the guidelines
170+- [ ] module tests succeed on ARCHITECTURE
171+- [ ] options have appropriate types
172+- [ ] options have default
173+- [ ] options have example
174+- [ ] options have descriptions
175+- [ ] No unneeded package is added to environment.systemPackages
176+- [ ] meta.maintainers is set
177+- [ ] module documentation is declared in meta.doc
178+179+##### Possible improvements
180+181+##### Comments
182+```
183+184+## Other submissions {#reviewing-contributions-other-submissions}
185+186+Other type of submissions requires different reviewing steps.
187+188+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.
189+190+Container system, boot system and library changes are some examples of the pull requests fitting this category.
191+192+## Merging pull requests {#reviewing-contributions--merging-pull-requests}
193+194+It is possible for community members that have enough knowledge and experience on a special topic to contribute by merging pull requests.
195+196+<!--
197+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.
198+199+Please note that contributors with commit rights unactive for more than three months will have their commit rights revoked.
200+-->
201+202+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.
203+204+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
···1-<chapter xmlns="http://docbook.org/ns/docbook"
2- xmlns:xlink="http://www.w3.org/1999/xlink"
3- xmlns:xi="http://www.w3.org/2001/XInclude"
4- version="5.0"
5- xml:id="chap-reviewing-contributions">
6- <title>Reviewing contributions</title>
7- <warning>
8- <para>
9- The following section is a draft, and the policy for reviewing is still being discussed in issues such as <link
10- xlink:href="https://github.com/NixOS/nixpkgs/issues/11166">#11166 </link> and <link
11- xlink:href="https://github.com/NixOS/nixpkgs/issues/20836">#20836 </link>.
12- </para>
13- </warning>
14- <para>
15- 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.
16- </para>
17- <para>
18- 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
19- xlink:href="https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc">most recently</link> and the <link
20- 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>.
21- </para>
22- <para>
23- 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.
24- </para>
25- <para>
26- 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.
27- </para>
28- <para>
29- 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.
30- </para>
31- <para>
32- 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.
33- </para>
34- <section xml:id="reviewing-contributions-package-updates">
35- <title>Package updates</title>
36-37- <para>
38- 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.
39- </para>
40-41- <para>
42- It can happen that non-trivial updates include patches or more complex changes.
43- </para>
44-45- <para>
46- Reviewing process:
47- </para>
48-49- <itemizedlist>
50- <listitem>
51- <para>
52- Ensure that the package versioning fits the guidelines.
53- </para>
54- </listitem>
55- <listitem>
56- <para>
57- Ensure that the commit text fits the guidelines.
58- </para>
59- </listitem>
60- <listitem>
61- <para>
62- Ensure that the package maintainers are notified.
63- </para>
64- <itemizedlist>
65- <listitem>
66- <para>
67- <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.
68- </para>
69- </listitem>
70- </itemizedlist>
71- </listitem>
72- <listitem>
73- <para>
74- Ensure that the meta field information is correct.
75- </para>
76- <itemizedlist>
77- <listitem>
78- <para>
79- License can change with version updates, so it should be checked to match the upstream license.
80- </para>
81- </listitem>
82- <listitem>
83- <para>
84- 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.
85- </para>
86- </listitem>
87- </itemizedlist>
88- </listitem>
89- <listitem>
90- <para>
91- Ensure that the code contains no typos.
92- </para>
93- </listitem>
94- <listitem>
95- <para>
96- Building the package locally.
97- </para>
98- <itemizedlist>
99- <listitem>
100- <para>
101- 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.
102- </para>
103- <para>
104- 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.
105-<screen>
106-<prompt>$ </prompt>git fetch origin nixos-unstable <co xml:id='reviewing-rebase-2' />
107-<prompt>$ </prompt>git fetch origin pull/PRNUMBER/head <co xml:id='reviewing-rebase-3' />
108-<prompt>$ </prompt>git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD <co
109- xml:id='reviewing-rebase-4' />
110-</screen>
111- <calloutlist>
112- <callout arearefs='reviewing-rebase-2'>
113- <para>
114- Fetching the nixos-unstable branch.
115- </para>
116- </callout>
117- <callout arearefs='reviewing-rebase-3'>
118- <para>
119- 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.
120- </para>
121- </callout>
122- <callout arearefs='reviewing-rebase-4'>
123- <para>
124- Rebasing the pull request changes to the nixos-unstable branch.
125- </para>
126- </callout>
127- </calloutlist>
128- </para>
129- </listitem>
130- <listitem>
131- <para>
132- 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.
133- </para>
134-<screen>
135-<prompt>$ </prompt>nix-shell -p nixpkgs-review --run "nixpkgs-review pr PRNUMBER"
136-</screen>
137- </listitem>
138- </itemizedlist>
139- </listitem>
140- <listitem>
141- <para>
142- Running every binary.
143- </para>
144- </listitem>
145- </itemizedlist>
146-147- <example xml:id="reviewing-contributions-sample-package-update">
148- <title>Sample template for a package update review</title>
149-<screen>
150-##### Reviewed points
151-152-- [ ] package name fits guidelines
153-- [ ] package version fits guidelines
154-- [ ] package build on ARCHITECTURE
155-- [ ] executables tested on ARCHITECTURE
156-- [ ] all depending packages build
157-158-##### Possible improvements
159-160-##### Comments
161-162-</screen>
163- </example>
164- </section>
165- <section xml:id="reviewing-contributions-new-packages">
166- <title>New packages</title>
167-168- <para>
169- New packages are a common type of pull requests. These pull requests consists in adding a new nix-expression for a package.
170- </para>
171-172- <para>
173- Review process:
174- </para>
175-176- <itemizedlist>
177- <listitem>
178- <para>
179- Ensure that the package versioning fits the guidelines.
180- </para>
181- </listitem>
182- <listitem>
183- <para>
184- Ensure that the commit name fits the guidelines.
185- </para>
186- </listitem>
187- <listitem>
188- <para>
189- Ensure that the meta fields contain correct information.
190- </para>
191- <itemizedlist>
192- <listitem>
193- <para>
194- License must match the upstream license.
195- </para>
196- </listitem>
197- <listitem>
198- <para>
199- Platforms should be set (or the package will not get binary substitutes).
200- </para>
201- </listitem>
202- <listitem>
203- <para>
204- Maintainers must be set. This can be the package submitter or a community member that accepts taking up maintainership of the package.
205- </para>
206- </listitem>
207- </itemizedlist>
208- </listitem>
209- <listitem>
210- <para>
211- Report detected typos.
212- </para>
213- </listitem>
214- <listitem>
215- <para>
216- Ensure the package source:
217- </para>
218- <itemizedlist>
219- <listitem>
220- <para>
221- Uses mirror URLs when available.
222- </para>
223- </listitem>
224- <listitem>
225- <para>
226- Uses the most appropriate functions (e.g. packages from GitHub should use <literal>fetchFromGitHub</literal>).
227- </para>
228- </listitem>
229- </itemizedlist>
230- </listitem>
231- <listitem>
232- <para>
233- Building the package locally.
234- </para>
235- </listitem>
236- <listitem>
237- <para>
238- Running every binary.
239- </para>
240- </listitem>
241- </itemizedlist>
242-243- <example xml:id="reviewing-contributions-sample-new-package">
244- <title>Sample template for a new package review</title>
245-<screen>
246-##### Reviewed points
247-248-- [ ] package path fits guidelines
249-- [ ] package name fits guidelines
250-- [ ] package version fits guidelines
251-- [ ] package build on ARCHITECTURE
252-- [ ] executables tested on ARCHITECTURE
253-- [ ] `meta.description` is set and fits guidelines
254-- [ ] `meta.license` fits upstream license
255-- [ ] `meta.platforms` is set
256-- [ ] `meta.maintainers` is set
257-- [ ] build time only dependencies are declared in `nativeBuildInputs`
258-- [ ] source is fetched using the appropriate function
259-- [ ] phases are respected
260-- [ ] patches that are remotely available are fetched with `fetchpatch`
261-262-##### Possible improvements
263-264-##### Comments
265-266-</screen>
267- </example>
268- </section>
269- <section xml:id="reviewing-contributions-module-updates">
270- <title>Module updates</title>
271-272- <para>
273- Module updates are submissions changing modules in some ways. These often contains changes to the options or introduce new options.
274- </para>
275-276- <para>
277- Reviewing process
278- </para>
279-280- <itemizedlist>
281- <listitem>
282- <para>
283- Ensure that the module maintainers are notified.
284- </para>
285- <itemizedlist>
286- <listitem>
287- <para>
288- <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.
289- </para>
290- </listitem>
291- </itemizedlist>
292- </listitem>
293- <listitem>
294- <para>
295- Ensure that the module tests, if any, are succeeding.
296- </para>
297- </listitem>
298- <listitem>
299- <para>
300- Ensure that the introduced options are correct.
301- </para>
302- <itemizedlist>
303- <listitem>
304- <para>
305- Type should be appropriate (string related types differs in their merging capabilities, <literal>optionSet</literal> and <literal>string</literal> types are deprecated).
306- </para>
307- </listitem>
308- <listitem>
309- <para>
310- Description, default and example should be provided.
311- </para>
312- </listitem>
313- </itemizedlist>
314- </listitem>
315- <listitem>
316- <para>
317- Ensure that option changes are backward compatible.
318- </para>
319- <itemizedlist>
320- <listitem>
321- <para>
322- <literal>mkRenamedOptionModule</literal> and <literal>mkAliasOptionModule</literal> functions provide way to make option changes backward compatible.
323- </para>
324- </listitem>
325- </itemizedlist>
326- </listitem>
327- <listitem>
328- <para>
329- Ensure that removed options are declared with <literal>mkRemovedOptionModule</literal>
330- </para>
331- </listitem>
332- <listitem>
333- <para>
334- Ensure that changes that are not backward compatible are mentioned in release notes.
335- </para>
336- </listitem>
337- <listitem>
338- <para>
339- Ensure that documentations affected by the change is updated.
340- </para>
341- </listitem>
342- </itemizedlist>
343-344- <example xml:id="reviewing-contributions-sample-module-update">
345- <title>Sample template for a module update review</title>
346-<screen>
347-##### Reviewed points
348-349-- [ ] changes are backward compatible
350-- [ ] removed options are declared with `mkRemovedOptionModule`
351-- [ ] changes that are not backward compatible are documented in release notes
352-- [ ] module tests succeed on ARCHITECTURE
353-- [ ] options types are appropriate
354-- [ ] options description is set
355-- [ ] options example is provided
356-- [ ] documentation affected by the changes is updated
357-358-##### Possible improvements
359-360-##### Comments
361-362-</screen>
363- </example>
364- </section>
365- <section xml:id="reviewing-contributions-new-modules">
366- <title>New modules</title>
367-368- <para>
369- New modules submissions introduce a new module to NixOS.
370- </para>
371-372- <itemizedlist>
373- <listitem>
374- <para>
375- Ensure that the module tests, if any, are succeeding.
376- </para>
377- </listitem>
378- <listitem>
379- <para>
380- Ensure that the introduced options are correct.
381- </para>
382- <itemizedlist>
383- <listitem>
384- <para>
385- Type should be appropriate (string related types differs in their merging capabilities, <literal>optionSet</literal> and <literal>string</literal> types are deprecated).
386- </para>
387- </listitem>
388- <listitem>
389- <para>
390- Description, default and example should be provided.
391- </para>
392- </listitem>
393- </itemizedlist>
394- </listitem>
395- <listitem>
396- <para>
397- Ensure that module <literal>meta</literal> field is present
398- </para>
399- <itemizedlist>
400- <listitem>
401- <para>
402- Maintainers should be declared in <literal>meta.maintainers</literal>.
403- </para>
404- </listitem>
405- <listitem>
406- <para>
407- Module documentation should be declared with <literal>meta.doc</literal>.
408- </para>
409- </listitem>
410- </itemizedlist>
411- </listitem>
412- <listitem>
413- <para>
414- Ensure that the module respect other modules functionality.
415- </para>
416- <itemizedlist>
417- <listitem>
418- <para>
419- For example, enabling a module should not open firewall ports by default.
420- </para>
421- </listitem>
422- </itemizedlist>
423- </listitem>
424- </itemizedlist>
425-426- <example xml:id="reviewing-contributions-sample-new-module">
427- <title>Sample template for a new module review</title>
428-<screen>
429-##### Reviewed points
430-431-- [ ] module path fits the guidelines
432-- [ ] module tests succeed on ARCHITECTURE
433-- [ ] options have appropriate types
434-- [ ] options have default
435-- [ ] options have example
436-- [ ] options have descriptions
437-- [ ] No unneeded package is added to environment.systemPackages
438-- [ ] meta.maintainers is set
439-- [ ] module documentation is declared in meta.doc
440-441-##### Possible improvements
442-443-##### Comments
444-445-</screen>
446- </example>
447- </section>
448- <section xml:id="reviewing-contributions-other-submissions">
449- <title>Other submissions</title>
450-451- <para>
452- Other type of submissions requires different reviewing steps.
453- </para>
454-455- <para>
456- 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.
457- </para>
458-459- <para>
460- Container system, boot system and library changes are some examples of the pull requests fitting this category.
461- </para>
462- </section>
463- <section xml:id="reviewing-contributions--merging-pull-requests">
464- <title>Merging pull requests</title>
465-466- <para>
467- It is possible for community members that have enough knowledge and experience on a special topic to contribute by merging pull requests.
468- </para>
469-470-<!--
471-The following paragraphs about how to deal with unactive contributors is just a
472-proposition and should be modified to what the community agrees to be the right
473-policy.
474-475-<para>Please note that contributors with commit rights unactive for more than
476- three months will have their commit rights revoked.</para>
477--->
478-479- <para>
480- 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.
481- </para>
482-483- <para>
484- In a case a contributor definitively leaves the Nix community, they should create an issue or post on <link
485- 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.
486- </para>
487- </section>
488-</chapter>
···188 </varlistentry>
189 <varlistentry>
190 <term>
0000000000000000000191 <methodname>get_screen_text</methodname>
192 </term>
193 <listitem>
···350 <para>
351 Wait until the supplied regular expressions matches the textual contents
352 of the screen by using optical character recognition (see
353- <methodname>get_screen_text</methodname>).
0354 </para>
355 <note>
356 <para>
···188 </varlistentry>
189 <varlistentry>
190 <term>
191+ <methodname>get_screen_text_variants</methodname>
192+ </term>
193+ <listitem>
194+ <para>
195+ Return a list of different interpretations of what is currently visible
196+ on the machine's screen using optical character recognition. The number
197+ and order of the interpretations is not specified and is subject to
198+ change, but if no exception is raised at least one will be returned.
199+ </para>
200+ <note>
201+ <para>
202+ This requires passing <option>enableOCR</option> to the test attribute
203+ set.
204+ </para>
205+ </note>
206+ </listitem>
207+ </varlistentry>
208+ <varlistentry>
209+ <term>
210 <methodname>get_screen_text</methodname>
211 </term>
212 <listitem>
···369 <para>
370 Wait until the supplied regular expressions matches the textual contents
371 of the screen by using optical character recognition (see
372+ <methodname>get_screen_text</methodname> and
373+ <methodname>get_screen_text_variants</methodname>).
374 </para>
375 <note>
376 <para>
+48-31
nixos/lib/test-driver/test-driver.py
···1#! /somewhere/python3
2from contextlib import contextmanager, _GeneratorContextManager
3from queue import Queue, Empty
4-from typing import Tuple, Any, Callable, Dict, Iterator, Optional, List
5from xml.sax.saxutils import XMLGenerator
6import queue
7import io
···203 self.log("({:.2f} seconds)".format(toc - tic))
204205 self.xml.endElement("nest")
0000000000000000000000000000000206207208class Machine:
···637 """Debugging: Dump the contents of the TTY<n>"""
638 self.execute("fold -w 80 /dev/vcs{} | systemd-cat".format(tty))
639640- def get_screen_text(self) -> str:
641- if shutil.which("tesseract") is None:
642- raise Exception("get_screen_text used but enableOCR is false")
00643644- magick_args = (
645- "-filter Catrom -density 72 -resample 300 "
646- + "-contrast -normalize -despeckle -type grayscale "
647- + "-sharpen 1 -posterize 3 -negate -gamma 100 "
648- + "-blur 1x65535"
649- )
650-651- tess_args = "-c debug_file=/dev/null --psm 11 --oem 2"
652-653- with self.nested("performing optical character recognition"):
654- with tempfile.NamedTemporaryFile() as tmpin:
655- self.send_monitor_command("screendump {}".format(tmpin.name))
656-657- cmd = "convert {} {} tiff:- | tesseract - - {}".format(
658- magick_args, tmpin.name, tess_args
659- )
660- ret = subprocess.run(cmd, shell=True, capture_output=True)
661- if ret.returncode != 0:
662- raise Exception(
663- "OCR failed with exit code {}".format(ret.returncode)
664- )
665666- return ret.stdout.decode("utf-8")
0667668 def wait_for_text(self, regex: str) -> None:
669 def screen_matches(last: bool) -> bool:
670- text = self.get_screen_text()
671- matches = re.search(regex, text) is not None
00672673- if last and not matches:
674- self.log("Last OCR attempt failed. Text was: {}".format(text))
675676- return matches
677678 with self.nested("waiting for {} to appear on screen".format(regex)):
679 retry(screen_matches)
···1#! /somewhere/python3
2from contextlib import contextmanager, _GeneratorContextManager
3from queue import Queue, Empty
4+from typing import Tuple, Any, Callable, Dict, Iterator, Optional, List, Iterable
5from xml.sax.saxutils import XMLGenerator
6import queue
7import io
···203 self.log("({:.2f} seconds)".format(toc - tic))
204205 self.xml.endElement("nest")
206+207+208+def _perform_ocr_on_screenshot(
209+ screenshot_path: str, model_ids: Iterable[int]
210+) -> List[str]:
211+ if shutil.which("tesseract") is None:
212+ raise Exception("OCR requested but enableOCR is false")
213+214+ magick_args = (
215+ "-filter Catrom -density 72 -resample 300 "
216+ + "-contrast -normalize -despeckle -type grayscale "
217+ + "-sharpen 1 -posterize 3 -negate -gamma 100 "
218+ + "-blur 1x65535"
219+ )
220+221+ tess_args = f"-c debug_file=/dev/null --psm 11"
222+223+ cmd = f"convert {magick_args} {screenshot_path} tiff:{screenshot_path}.tiff"
224+ ret = subprocess.run(cmd, shell=True, capture_output=True)
225+ if ret.returncode != 0:
226+ raise Exception(f"TIFF conversion failed with exit code {ret.returncode}")
227+228+ model_results = []
229+ for model_id in model_ids:
230+ cmd = f"tesseract {screenshot_path}.tiff - {tess_args} --oem {model_id}"
231+ ret = subprocess.run(cmd, shell=True, capture_output=True)
232+ if ret.returncode != 0:
233+ raise Exception(f"OCR failed with exit code {ret.returncode}")
234+ model_results.append(ret.stdout.decode("utf-8"))
235+236+ return model_results
237238239class Machine:
···668 """Debugging: Dump the contents of the TTY<n>"""
669 self.execute("fold -w 80 /dev/vcs{} | systemd-cat".format(tty))
670671+ def _get_screen_text_variants(self, model_ids: Iterable[int]) -> List[str]:
672+ with tempfile.TemporaryDirectory() as tmpdir:
673+ screenshot_path = os.path.join(tmpdir, "ppm")
674+ self.send_monitor_command(f"screendump {screenshot_path}")
675+ return _perform_ocr_on_screenshot(screenshot_path, model_ids)
676677+ def get_screen_text_variants(self) -> List[str]:
678+ return self._get_screen_text_variants([0, 1, 2])
0000000000000000000679680+ def get_screen_text(self) -> str:
681+ return self._get_screen_text_variants([2])[0]
682683 def wait_for_text(self, regex: str) -> None:
684 def screen_matches(last: bool) -> bool:
685+ variants = self.get_screen_text_variants()
686+ for text in variants:
687+ if re.search(regex, text) is not None:
688+ return True
689690+ if last:
691+ self.log("Last OCR attempt failed. Text was: {}".format(variants))
692693+ return False
694695 with self.nested("waiting for {} to appear on screen".format(regex)):
696 retry(screen_matches)
···10 extensions = { enabled, all }:
11 (with all;
12 enabled
13- ++ optional (!cfg.disableImagemagick) imagick
14 # Optionally enabled depending on caching settings
15 ++ optional cfg.caching.apcu apcu
16 ++ optional cfg.caching.redis redis
···6263 Further details about this can be found in the `Nextcloud`-section of the NixOS-manual
64 (which can be openend e.g. by running `nixos-help`).
00065 '')
66 ];
67···303 };
304 };
305306- disableImagemagick = mkOption {
307- type = types.bool;
308- default = false;
309- description = ''
310- Whether to not load the ImageMagick module into PHP.
311 This is used by the theming app and for generating previews of certain images (e.g. SVG and HEIF).
312 You may want to disable it for increased security. In that case, previews will still be available
313 for some images (e.g. JPEG and PNG).
314 See https://github.com/nextcloud/server/issues/13099
315- '';
0316 };
317318 caching = {
···10 extensions = { enabled, all }:
11 (with all;
12 enabled
13+ ++ optional cfg.enableImagemagick imagick
14 # Optionally enabled depending on caching settings
15 ++ optional cfg.caching.apcu apcu
16 ++ optional cfg.caching.redis redis
···6263 Further details about this can be found in the `Nextcloud`-section of the NixOS-manual
64 (which can be openend e.g. by running `nixos-help`).
65+ '')
66+ (mkRemovedOptionModule [ "services" "nextcloud" "disableImagemagick" ] ''
67+ Use services.nextcloud.nginx.enableImagemagick instead.
68 '')
69 ];
70···306 };
307 };
308309+ enableImagemagick = mkEnableOption ''
310+ Whether to load the ImageMagick module into PHP.
000311 This is used by the theming app and for generating previews of certain images (e.g. SVG and HEIF).
312 You may want to disable it for increased security. In that case, previews will still be available
313 for some images (e.g. JPEG and PNG).
314 See https://github.com/nextcloud/server/issues/13099
315+ '' // {
316+ default = true;
317 };
318319 caching = {
···661 # fine with newer versions.
662 spagoWithOverrides = doJailbreak super.spago;
663664- # This defines the version of the purescript-docs-search release we are using.
665- # This is defined in the src/Spago/Prelude.hs file in the spago source.
666- docsSearchVersion = "v0.0.10";
0667668- docsSearchAppJsFile = pkgs.fetchurl {
669- url = "https://github.com/spacchetti/purescript-docs-search/releases/download/${docsSearchVersion}/docs-search-app.js";
670- sha256 = "0m5ah29x290r0zk19hx2wix2djy7bs4plh9kvjz6bs9r45x25pa5";
671 };
672673- purescriptDocsSearchFile = pkgs.fetchurl {
674- url = "https://github.com/spacchetti/purescript-docs-search/releases/download/${docsSearchVersion}/purescript-docs-search";
675 sha256 = "0wc1zyhli4m2yykc6i0crm048gyizxh7b81n8xc4yb7ibjqwhyj3";
676 };
67700000678 spagoFixHpack = overrideCabal spagoWithOverrides (drv: {
679 postUnpack = (drv.postUnpack or "") + ''
680 # The source for spago is pulled directly from GitHub. It uses a
···695 # However, they are not actually available in the spago source, so they
696 # need to fetched with nix and put in the correct place.
697 # https://github.com/spacchetti/spago/issues/510
698- cp ${docsSearchAppJsFile} "$sourceRoot/templates/docs-search-app.js"
699- cp ${purescriptDocsSearchFile} "$sourceRoot/templates/purescript-docs-search"
00700701 # For some weird reason, on Darwin, the open(2) call to embed these files
702 # requires write permissions. The easiest resolution is just to permit that
703 # (doesn't cause any harm on other systems).
704- chmod u+w "$sourceRoot/templates/docs-search-app.js" "$sourceRoot/templates/purescript-docs-search"
0000705 '';
706 });
707
···661 # fine with newer versions.
662 spagoWithOverrides = doJailbreak super.spago;
663664+ docsSearchApp_0_0_10 = pkgs.fetchurl {
665+ url = "https://github.com/purescript/purescript-docs-search/releases/download/v0.0.10/docs-search-app.js";
666+ sha256 = "0m5ah29x290r0zk19hx2wix2djy7bs4plh9kvjz6bs9r45x25pa5";
667+ };
668669+ docsSearchApp_0_0_11 = pkgs.fetchurl {
670+ url = "https://github.com/purescript/purescript-docs-search/releases/download/v0.0.11/docs-search-app.js";
671+ sha256 = "17qngsdxfg96cka1cgrl3zdrpal8ll6vyhhnazqm4hwj16ywjm02";
672 };
673674+ purescriptDocsSearch_0_0_10 = pkgs.fetchurl {
675+ url = "https://github.com/purescript/purescript-docs-search/releases/download/v0.0.10/purescript-docs-search";
676 sha256 = "0wc1zyhli4m2yykc6i0crm048gyizxh7b81n8xc4yb7ibjqwhyj3";
677 };
678679+ purescriptDocsSearch_0_0_11 = pkgs.fetchurl {
680+ url = "https://github.com/purescript/purescript-docs-search/releases/download/v0.0.11/purescript-docs-search";
681+ sha256 = "1hjdprm990vyxz86fgq14ajn0lkams7i00h8k2i2g1a0hjdwppq6";
682+ };
683+684 spagoFixHpack = overrideCabal spagoWithOverrides (drv: {
685 postUnpack = (drv.postUnpack or "") + ''
686 # The source for spago is pulled directly from GitHub. It uses a
···701 # However, they are not actually available in the spago source, so they
702 # need to fetched with nix and put in the correct place.
703 # https://github.com/spacchetti/spago/issues/510
704+ cp ${docsSearchApp_0_0_10} "$sourceRoot/templates/docs-search-app-0.0.10.js"
705+ cp ${docsSearchApp_0_0_11} "$sourceRoot/templates/docs-search-app-0.0.11.js"
706+ cp ${purescriptDocsSearch_0_0_10} "$sourceRoot/templates/purescript-docs-search-0.0.10"
707+ cp ${purescriptDocsSearch_0_0_11} "$sourceRoot/templates/purescript-docs-search-0.0.11"
708709 # For some weird reason, on Darwin, the open(2) call to embed these files
710 # requires write permissions. The easiest resolution is just to permit that
711 # (doesn't cause any harm on other systems).
712+ chmod u+w \
713+ "$sourceRoot/templates/docs-search-app-0.0.10.js" \
714+ "$sourceRoot/templates/purescript-docs-search-0.0.10" \
715+ "$sourceRoot/templates/docs-search-app-0.0.11.js" \
716+ "$sourceRoot/templates/purescript-docs-search-0.0.11"
717 '';
718 });
719
···210 kernelCompatible = kernel.kernelAtLeast "3.10" && kernel.kernelOlder "5.12";
211212 # this package should point to a version / git revision compatible with the latest kernel release
213- version = "2.1.0-rc3";
214215- sha256 = "sha256-ARRUuyu07dWwEuXerTz9KBmclhlmsnnGucfBxxn0Zsw=";
216217 isUnstable = true;
218 };
···210 kernelCompatible = kernel.kernelAtLeast "3.10" && kernel.kernelOlder "5.12";
211212 # this package should point to a version / git revision compatible with the latest kernel release
213+ version = "2.1.0-rc4";
214215+ sha256 = "sha256-eakOEA7LCJOYDsZH24Y5JbEd2wh1KfCN+qX3QxQZ4e8=";
216217 isUnstable = true;
218 };
···1011buildGoModule rec {
12 pname = "bettercap";
13- version = "2.30.2";
1415 src = fetchFromGitHub {
16 owner = pname;
17 repo = pname;
18 rev = "v${version}";
19- sha256 = "sha256-5CAWMW0u/8BUn/8JJBApyHGH+/Tz8hzAmSChoT2gFr8=";
20 };
2122- vendorSha256 = "sha256-fApxHxdzEEc+M+U5f0271VgrkXTGkUD75BpDXpVYd5k=";
2324 doCheck = false;
25···30 meta = with lib; {
31 description = "A man in the middle tool";
32 longDescription = ''
33- 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.
0034 '';
35 homepage = "https://www.bettercap.org/";
36- license = with licenses; gpl3;
37 maintainers = with maintainers; [ y0no ];
38 };
39}
···1011buildGoModule rec {
12 pname = "bettercap";
13+ version = "2.31.0";
1415 src = fetchFromGitHub {
16 owner = pname;
17 repo = pname;
18 rev = "v${version}";
19+ sha256 = "sha256-PmS4ox1ZaHrBGJAdNByott61rEvfmR1ZJ12ut0MGtrc=";
20 };
2122+ vendorSha256 = "sha256-3j64Z4BQhAbUtoHJ6IT1SCsKxSeYZRxSO3K2Nx9Vv4w=";
2324 doCheck = false;
25···30 meta = with lib; {
31 description = "A man in the middle tool";
32 longDescription = ''
33+ BetterCAP is a powerful, flexible and portable tool created to perform various
34+ types of MITM attacks against a network, manipulate HTTP, HTTPS and TCP traffic
35+ in realtime, sniff for credentials and much more.
36 '';
37 homepage = "https://www.bettercap.org/";
38+ license = with licenses; [ gpl3Only ];
39 maintainers = with maintainers; [ y0no ];
40 };
41}