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 [](#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- Unnecessary string conversions should be avoided. Do
173
174 ```nix
175 rev = version;
176 ```
177
178 instead of
179
180 ```nix
181 rev = "${version}";
182 ```
183
184- Building lists conditionally _should_ be done with `lib.optional(s)` instead of using `if cond then [ ... ] else null` or `if cond then [ ... ] else [ ]`.
185
186 ```nix
187 buildInputs = lib.optional stdenv.isDarwin iconv;
188 ```
189
190 instead of
191
192 ```nix
193 buildInputs = if stdenv.isDarwin then [ iconv ] else null;
194 ```
195
196 As an exception, an explicit conditional expression with null can be used when fixing a important bug without triggering a mass rebuild.
197 If this is done a follow up pull request _should_ be created to change the code to `lib.optional(s)`.
198
199- Arguments should be listed in the order they are used, with the exception of `lib`, which always goes first.
200
201## Package naming {#sec-package-naming}
202
203The 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.
204
205In Nixpkgs, there are generally three different names associated with a package:
206
207- The `pname` attribute of the derivation. This is what most users see, in particular when using `nix-env`.
208
209- 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`.
210
211- The filename for (the directory containing) the Nix expression.
212
213Most of the time, these are the same. For instance, the package `e2fsprogs` has a `pname` attribute `"e2fsprogs"`, is bound to the variable name `e2fsprogs` in `all-packages.nix`, and the Nix expression is in `pkgs/os-specific/linux/e2fsprogs/default.nix`.
214
215There are a few naming guidelines:
216
217- The `pname` attribute _should_ be identical to the upstream package name.
218
219- The `pname` and the `version` attribute _must not_ contain uppercase letters — e.g., `"mplayer" instead of `"MPlayer"`.
220
221- The `version` attribute _must_ start with a digit e.g`"0.3.1rc2".
222
223- If a package is not a release but a commit from a repository, then the `version` attribute _must_ be the date of that (fetched) commit. The date _must_ be in `"unstable-YYYY-MM-DD"` format.
224
225- Dashes in the package `pname` _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.
226
227- 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 [](#sec-versioning)
228
229## File naming and organisation {#sec-organisation}
230
231Names 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`.
232
233### Hierarchy {#sec-hierarchy}
234
235Each 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`.
236
237When in doubt, consider refactoring the `pkgs/` tree, e.g. creating new categories or splitting up an existing category.
238
239**If it’s used to support _software development_:**
240
241- **If it’s a _library_ used by other packages:**
242
243 - `development/libraries` (e.g. `libxml2`)
244
245- **If it’s a _compiler_:**
246
247 - `development/compilers` (e.g. `gcc`)
248
249- **If it’s an _interpreter_:**
250
251 - `development/interpreters` (e.g. `guile`)
252
253- **If it’s a (set of) development _tool(s)_:**
254
255 - **If it’s a _parser generator_ (including lexers):**
256
257 - `development/tools/parsing` (e.g. `bison`, `flex`)
258
259 - **If it’s a _build manager_:**
260
261 - `development/tools/build-managers` (e.g. `gnumake`)
262
263 - **If it’s a _language server_:**
264
265 - `development/tools/language-servers` (e.g. `ccls` or `rnix-lsp`)
266
267 - **Else:**
268
269 - `development/tools/misc` (e.g. `binutils`)
270
271- **Else:**
272
273 - `development/misc`
274
275**If it’s a (set of) _tool(s)_:**
276
277(A tool is a relatively small program, especially one intended to be used non-interactively.)
278
279- **If it’s for _networking_:**
280
281 - `tools/networking` (e.g. `wget`)
282
283- **If it’s for _text processing_:**
284
285 - `tools/text` (e.g. `diffutils`)
286
287- **If it’s a _system utility_, i.e., something related or essential to the operation of a system:**
288
289 - `tools/system` (e.g. `cron`)
290
291- **If it’s an _archiver_ (which may include a compression function):**
292
293 - `tools/archivers` (e.g. `zip`, `tar`)
294
295- **If it’s a _compression_ program:**
296
297 - `tools/compression` (e.g. `gzip`, `bzip2`)
298
299- **If it’s a _security_-related program:**
300
301 - `tools/security` (e.g. `nmap`, `gnupg`)
302
303- **Else:**
304
305 - `tools/misc`
306
307**If it’s a _shell_:**
308
309- `shells` (e.g. `bash`)
310
311**If it’s a _server_:**
312
313- **If it’s a web server:**
314
315 - `servers/http` (e.g. `apache-httpd`)
316
317- **If it’s an implementation of the X Windowing System:**
318
319 - `servers/x11` (e.g. `xorg` — this includes the client libraries and programs)
320
321- **Else:**
322
323 - `servers/misc`
324
325**If it’s a _desktop environment_:**
326
327- `desktops` (e.g. `kde`, `gnome`, `enlightenment`)
328
329**If it’s a _window manager_:**
330
331- `applications/window-managers` (e.g. `awesome`, `stumpwm`)
332
333**If it’s an _application_:**
334
335A (typically large) program with a distinct user interface, primarily used interactively.
336
337- **If it’s a _version management system_:**
338
339 - `applications/version-management` (e.g. `subversion`)
340
341- **If it’s a _terminal emulator_:**
342
343 - `applications/terminal-emulators` (e.g. `alacritty` or `rxvt` or `termite`)
344
345- **If it’s a _file manager_:**
346
347 - `applications/file-managers` (e.g. `mc` or `ranger` or `pcmanfm`)
348
349- **If it’s for _video playback / editing_:**
350
351 - `applications/video` (e.g. `vlc`)
352
353- **If it’s for _graphics viewing / editing_:**
354
355 - `applications/graphics` (e.g. `gimp`)
356
357- **If it’s for _networking_:**
358
359 - **If it’s a _mailreader_:**
360
361 - `applications/networking/mailreaders` (e.g. `thunderbird`)
362
363 - **If it’s a _newsreader_:**
364
365 - `applications/networking/newsreaders` (e.g. `pan`)
366
367 - **If it’s a _web browser_:**
368
369 - `applications/networking/browsers` (e.g. `firefox`)
370
371 - **Else:**
372
373 - `applications/networking/misc`
374
375- **Else:**
376
377 - `applications/misc`
378
379**If it’s _data_ (i.e., does not have a straight-forward executable semantics):**
380
381- **If it’s a _font_:**
382
383 - `data/fonts`
384
385- **If it’s an _icon theme_:**
386
387 - `data/icons`
388
389- **If it’s related to _SGML/XML processing_:**
390
391 - **If it’s an _XML DTD_:**
392
393 - `data/sgml+xml/schemas/xml-dtd` (e.g. `docbook`)
394
395 - **If it’s an _XSLT stylesheet_:**
396
397 (Okay, these are executable...)
398
399 - `data/sgml+xml/stylesheets/xslt` (e.g. `docbook-xsl`)
400
401- **If it’s a _theme_ for a _desktop environment_, a _window manager_ or a _display manager_:**
402
403 - `data/themes`
404
405**If it’s a _game_:**
406
407- `games`
408
409**Else:**
410
411- `misc`
412
413### Versioning {#sec-versioning}
414
415Because 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.
416
417If 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`.
418
419All versions of a package _must_ be included in `all-packages.nix` to make sure that they evaluate correctly.
420
421## Fetching Sources {#sec-sources}
422
423There 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.
424
425You can find many source fetch helpers in `pkgs/build-support/fetch*`.
426
427In 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:
428
429- Bad: Uses `git://` which won't be proxied.
430
431 ```nix
432 src = fetchgit {
433 url = "git@github.com:NixOS/nix.git"
434 url = "git://github.com/NixOS/nix.git";
435 rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
436 hash = "sha256-7D4m+saJjbSFP5hOwpQq2FGR2rr+psQMTcyb1ZvtXsQ=";
437 }
438 ```
439
440- Better: This is ok, but an archive fetch will still be faster.
441
442 ```nix
443 src = fetchgit {
444 url = "https://github.com/NixOS/nix.git";
445 rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
446 hash = "sha256-7D4m+saJjbSFP5hOwpQq2FGR2rr+psQMTcyb1ZvtXsQ=";
447 }
448 ```
449
450- Best: Fetches a snapshot archive and you get the rev you want.
451
452 ```nix
453 src = fetchFromGitHub {
454 owner = "NixOS";
455 repo = "nix";
456 rev = "1f795f9f44607cc5bec70d1300150bfefcef2aae";
457 hash = "ha256-7D4m+saJjbSFP5hOwpQq2FGR2rr+psQMTcyb1ZvtXsQ=";
458 }
459 ```
460
461When fetching from GitHub, commits must always be referenced by their full commit hash. This is because GitHub shares commit hashes among all forks and returns `404 Not Found` when a short commit hash is ambiguous. It already happens for some short, 6-character commit hashes in `nixpkgs`.
462It is a practical vector for a denial-of-service attack by pushing large amounts of auto generated commits into forks and was already [demonstrated against GitHub Actions Beta](https://blog.teddykatz.com/2019/11/12/github-actions-dos.html).
463
464Find the value to put as `hash` by running `nix-shell -p nix-prefetch-github --run "nix-prefetch-github --rev 1f795f9f44607cc5bec70d1300150bfefcef2aae NixOS nix"`.
465
466## Obtaining source hash {#sec-source-hashes}
467
468Preferred source hash type is sha256. There are several ways to get it.
469
4701. Prefetch URL (with `nix-prefetch-XXX URL`, where `XXX` is one of `url`, `git`, `hg`, `cvs`, `bzr`, `svn`). Hash is printed to stdout.
471
4722. Prefetch by package source (with `nix-prefetch-url '<nixpkgs>' -A PACKAGE.src`, where `PACKAGE` is package attribute name). Hash is printed to stdout.
473
474 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).
475
4763. Upstream provided hash: use it when upstream provides `sha256` or `sha512` (when upstream provides `md5`, don't use it, compute `sha256` instead).
477
478 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.
479
480 You can convert between formats with nix-hash, for example:
481
482 ```ShellSession
483 $ nix-hash --type sha256 --to-base32 HASH
484 ```
485
4864. Extracting hash from local source tarball can be done with `sha256sum`. Use `nix-prefetch-url file:///path/to/tarball` if you want base32 hash.
487
4885. Fake hash: set the hash to one of
489
490 - `""`
491 - `lib.fakeHash`
492 - `lib.fakeSha256`
493 - `lib.fakeSha512`
494
495 in the package expression, attempt build and extract correct hash from error messages.
496
497 ::: {.warning}
498 You must use one of these four fake hashes and not some arbitrarily-chosen hash.
499
500 See [](#sec-source-hashes-security).
501 :::
502
503 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.
504
505
506### Obtaining hashes securely {#sec-source-hashes-security}
507
508Let'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:
509
510- `http://` URLs are not secure to prefetch hash from;
511
512- hashes from upstream (in method 3) should be obtained via secure protocol;
513
514- `https://` URLs are secure in methods 1, 2, 3;
515
516- `https://` URLs are secure in method 5 *only if* you use one of the listed fake hashes. If you use any other hash, `fetchurl` will pass `--insecure` to `curl` and may then degrade to HTTP in case of TLS certificate expiration.
517
518## Patches {#sec-patches}
519
520Patches available online should be retrieved using `fetchpatch`.
521
522```nix
523patches = [
524 (fetchpatch {
525 name = "fix-check-for-using-shared-freetype-lib.patch";
526 url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=8f5d285";
527 hash = "sha256-uRcxaCjd+WAuGrXOmGfFeu79cUILwkRdBu48mwcBE7g=";
528 })
529];
530```
531
532Otherwise, 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.
533
534If a patch is available online but does not cleanly apply, it can be modified in some fixed ways by using additional optional arguments for `fetchpatch`. Check [](#fetchpatch) for details.
535
536```nix
537patches = [ ./0001-changes.patch ];
538```
539
540If you do need to do create this sort of patch file, one way to do so is with git:
541
5421. Move to the root directory of the source code you're patching.
543
544 ```ShellSession
545 $ cd the/program/source
546 ```
547
5482. If a git repository is not already present, create one and stage all of the source files.
549
550 ```ShellSession
551 $ git init
552 $ git add .
553 ```
554
5553. Edit some files to make whatever changes need to be included in the patch.
556
5574. Use git to create a diff, and pipe the output to a patch file:
558
559 ```ShellSession
560 $ git diff -a > nixpkgs/pkgs/the/package/0001-changes.patch
561 ```
562
563## Package tests {#sec-package-tests}
564
565Tests are important to ensure quality and make reviews and automatic updates easy.
566
567The following types of tests exists:
568
569* [NixOS **module tests**](https://nixos.org/manual/nixos/stable/#sec-nixos-tests), which spawn one or more NixOS VMs. They exercise both NixOS modules and the packaged programs used within them. For example, a NixOS module test can start a web server VM running the `nginx` module, and a client VM running `curl` or a graphical `firefox`, and test that they can talk to each other and display the correct content.
570* Nix **package tests** are a lightweight alternative to NixOS module tests. They should be used to create simple integration tests for packages, but cannot test NixOS services, and some programs with graphical user interfaces may also be difficult to test with them.
571* The **`checkPhase` of a package**, which should execute the unit tests that are included in the source code of a package.
572
573Here in the nixpkgs manual we describe mostly _package tests_; for _module tests_ head over to the corresponding [section in the NixOS manual](https://nixos.org/manual/nixos/stable/#sec-nixos-tests).
574
575### Writing inline package tests {#ssec-inline-package-tests-writing}
576
577For very simple tests, they can be written inline:
578
579```nix
580{ …, yq-go }:
581
582buildGoModule rec {
583 …
584
585 passthru.tests = {
586 simple = runCommand "${pname}-test" {} ''
587 echo "test: 1" | ${yq-go}/bin/yq eval -j > $out
588 [ "$(cat $out | tr -d $'\n ')" = '{"test":1}' ]
589 '';
590 };
591}
592```
593
594### Writing larger package tests {#ssec-package-tests-writing}
595
596This is an example using the `phoronix-test-suite` package with the current best practices.
597
598Add the tests in `passthru.tests` to the package definition like this:
599
600```nix
601{ stdenv, lib, fetchurl, callPackage }:
602
603stdenv.mkDerivation {
604 …
605
606 passthru.tests = {
607 simple-execution = callPackage ./tests.nix { };
608 };
609
610 meta = { … };
611}
612```
613
614Create `tests.nix` in the package directory:
615
616```nix
617{ runCommand, phoronix-test-suite }:
618
619let
620 inherit (phoronix-test-suite) pname version;
621in
622
623runCommand "${pname}-tests" { meta.timeout = 60; }
624 ''
625 # automatic initial setup to prevent interactive questions
626 ${phoronix-test-suite}/bin/phoronix-test-suite enterprise-setup >/dev/null
627 # get version of installed program and compare with package version
628 if [[ `${phoronix-test-suite}/bin/phoronix-test-suite version` != *"${version}"* ]]; then
629 echo "Error: program version does not match package version"
630 exit 1
631 fi
632 # run dummy command
633 ${phoronix-test-suite}/bin/phoronix-test-suite dummy_module.dummy-command >/dev/null
634 # needed for Nix to register the command as successful
635 touch $out
636 ''
637```
638
639### Running package tests {#ssec-package-tests-running}
640
641You can run these tests with:
642
643```ShellSession
644$ cd path/to/nixpkgs
645$ nix-build -A phoronix-test-suite.tests
646```
647
648### Examples of package tests {#ssec-package-tests-examples}
649
650Here are examples of package tests:
651
652- [Jasmin compile test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/jasmin/test-assemble-hello-world/default.nix)
653- [Lobster compile test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/lobster/test-can-run-hello-world.nix)
654- [Spacy annotation test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/spacy/annotation-test/default.nix)
655- [Libtorch test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/science/math/libtorch/test/default.nix)
656- [Multiple tests for nanopb](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/nanopb/default.nix)
657
658### Linking NixOS module tests to a package {#ssec-nixos-tests-linking}
659
660Like [package tests](#ssec-package-tests-writing) as shown above, [NixOS module tests](https://nixos.org/manual/nixos/stable/#sec-nixos-tests) can also be linked to a package, so that the tests can be easily run when changing the related package.
661
662For example, assuming we're packaging `nginx`, we can link its module test via `passthru.tests`:
663
664```nix
665{ stdenv, lib, nixosTests }:
666
667stdenv.mkDerivation {
668 ...
669
670 passthru.tests = {
671 nginx = nixosTests.nginx;
672 };
673
674 ...
675}
676```
677
678### Import From Derivation {#ssec-import-from-derivation}
679
680Import From Derivation (IFD) is disallowed in Nixpkgs for performance reasons:
681[Hydra] evaluates the entire package set, and sequential builds during evaluation would increase evaluation times to become impractical.
682
683[Hydra]: https://github.com/NixOS/hydra
684
685Import From Derivation can be worked around in some cases by committing generated intermediate files to version control and reading those instead.
686
687<!-- TODO: remove the following and link to Nix manual once https://github.com/NixOS/nix/pull/7332 is merged -->
688
689See also [NixOS Wiki: Import From Derivation].
690
691[NixOS Wiki: Import From Derivation]: https://nixos.wiki/wiki/Import_From_Derivation