···
1
-
<chapter xmlns="http://docbook.org/ns/docbook"
2
-
xmlns:xlink="http://www.w3.org/1999/xlink"
3
-
xml:id="chap-language-support">
5
-
<title>Support for specific programming languages</title>
7
-
<para>The <link linkend="chap-stdenv">standard build
8
-
environment</link> makes it easy to build typical Autotools-based
9
-
packages with very little code. Any other kind of package can be
10
-
accomodated by overriding the appropriate phases of
11
-
<literal>stdenv</literal>. However, there are specialised functions
12
-
in Nixpkgs to easily build packages for other programming languages,
13
-
such as Perl or Haskell. These are described in this chapter.</para>
16
-
<section xml:id="sec-language-perl"><title>Perl</title>
18
-
<para>Nixpkgs provides a function <varname>buildPerlPackage</varname>,
19
-
a generic package builder function for any Perl package that has a
20
-
standard <varname>Makefile.PL</varname>. It’s implemented in <link
21
-
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/perl-modules/generic"><filename>pkgs/development/perl-modules/generic</filename></link>.</para>
23
-
<para>Perl packages from CPAN are defined in <link
24
-
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/perl-packages.nix"><filename>pkgs/top-level/perl-packages.nix</filename></link>,
25
-
rather than <filename>pkgs/all-packages.nix</filename>. Most Perl
26
-
packages are so straight-forward to build that they are defined here
27
-
directly, rather than having a separate function for each package
28
-
called from <filename>perl-packages.nix</filename>. However, more
29
-
complicated packages should be put in a separate file, typically in
30
-
<filename>pkgs/development/perl-modules</filename>. Here is an
31
-
example of the former:
34
-
ClassC3 = buildPerlPackage rec {
35
-
name = "Class-C3-0.21";
37
-
url = "mirror://cpan/authors/id/F/FL/FLORA/${name}.tar.gz";
38
-
sha256 = "1bl8z095y4js66pwxnm7s853pi9czala4sqc743fdlnk27kq94gz";
43
-
Note the use of <literal>mirror://cpan/</literal>, and the
44
-
<literal>${name}</literal> in the URL definition to ensure that the
45
-
name attribute is consistent with the source that we’re actually
46
-
downloading. Perl packages are made available in
47
-
<filename>all-packages.nix</filename> through the variable
48
-
<varname>perlPackages</varname>. For instance, if you have a package
49
-
that needs <varname>ClassC3</varname>, you would typically write
52
-
foo = import ../path/to/foo.nix {
53
-
inherit stdenv fetchurl ...;
54
-
inherit (perlPackages) ClassC3;
58
-
in <filename>all-packages.nix</filename>. You can test building a
59
-
Perl package as follows:
62
-
$ nix-build -A perlPackages.ClassC3
65
-
<varname>buildPerlPackage</varname> adds <literal>perl-</literal> to
66
-
the start of the name attribute, so the package above is actually
67
-
called <literal>perl-Class-C3-0.21</literal>. So to install it, you
71
-
$ nix-env -i perl-Class-C3
74
-
(Of course you can also install using the attribute name:
75
-
<literal>nix-env -i -A perlPackages.ClassC3</literal>.)</para>
77
-
<para>So what does <varname>buildPerlPackage</varname> do? It does
82
-
<listitem><para>In the configure phase, it calls <literal>perl
83
-
Makefile.PL</literal> to generate a Makefile. You can set the
84
-
variable <varname>makeMakerFlags</varname> to pass flags to
85
-
<filename>Makefile.PL</filename></para></listitem>
87
-
<listitem><para>It adds the contents of the <envar>PERL5LIB</envar>
88
-
environment variable to <literal>#! .../bin/perl</literal> line of
89
-
Perl scripts as <literal>-I<replaceable>dir</replaceable></literal>
90
-
flags. This ensures that a script can find its
91
-
dependencies.</para></listitem>
93
-
<listitem><para>In the fixup phase, it writes the propagated build
94
-
inputs (<varname>propagatedBuildInputs</varname>) to the file
95
-
<filename>$out/nix-support/propagated-user-env-packages</filename>.
96
-
<command>nix-env</command> recursively installs all packages listed
97
-
in this file when you install a package that has it. This ensures
98
-
that a Perl package can find its dependencies.</para></listitem>
104
-
<para><varname>buildPerlPackage</varname> is built on top of
105
-
<varname>stdenv</varname>, so everything can be customised in the
106
-
usual way. For instance, the <literal>BerkeleyDB</literal> module has
107
-
a <varname>preConfigure</varname> hook to generate a configuration
108
-
file used by <filename>Makefile.PL</filename>:
111
-
{ buildPerlPackage, fetchurl, db }:
113
-
buildPerlPackage rec {
114
-
name = "BerkeleyDB-0.36";
117
-
url = "mirror://cpan/authors/id/P/PM/PMQS/${name}.tar.gz";
118
-
sha256 = "07xf50riarb60l1h6m2dqmql8q5dij619712fsgw7ach04d8g3z1";
122
-
echo "LIB = ${db}/lib" > config.in
123
-
echo "INCLUDE = ${db}/include" >> config.in
130
-
<para>Dependencies on other Perl packages can be specified in the
131
-
<varname>buildInputs</varname> and
132
-
<varname>propagatedBuildInputs</varname> attributes. If something is
133
-
exclusively a build-time dependency, use
134
-
<varname>buildInputs</varname>; if it’s (also) a runtime dependency,
135
-
use <varname>propagatedBuildInputs</varname>. For instance, this
136
-
builds a Perl module that has runtime dependencies on a bunch of other
140
-
ClassC3Componentised = buildPerlPackage rec {
141
-
name = "Class-C3-Componentised-1.0004";
143
-
url = "mirror://cpan/authors/id/A/AS/ASH/${name}.tar.gz";
144
-
sha256 = "0xql73jkcdbq4q9m0b0rnca6nrlvf5hyzy8is0crdk65bynvs8q1";
146
-
propagatedBuildInputs = [
147
-
ClassC3 ClassInspector TestException MROCompat
154
-
<section xml:id="ssec-generation-from-CPAN"><title>Generation from CPAN</title>
156
-
<para>Nix expressions for Perl packages can be generated (almost)
157
-
automatically from CPAN. This is done by the program
158
-
<command>nix-generate-from-cpan</command>, which can be installed
162
-
$ nix-env -i nix-generate-from-cpan
165
-
<para>This program takes a Perl module name, looks it up on CPAN,
166
-
fetches and unpacks the corresponding package, and prints a Nix
167
-
expression on standard output. For example:
170
-
$ nix-generate-from-cpan XML::Simple
171
-
XMLSimple = buildPerlPackage {
172
-
name = "XML-Simple-2.20";
174
-
url = mirror://cpan/authors/id/G/GR/GRANTM/XML-Simple-2.20.tar.gz;
175
-
sha256 = "5cff13d0802792da1eb45895ce1be461903d98ec97c9c953bc8406af7294434a";
177
-
propagatedBuildInputs = [ XMLNamespaceSupport XMLSAX XMLSAXExpat ];
179
-
description = "Easily read/write XML (esp config files)";
185
-
The output can be pasted into
186
-
<filename>pkgs/top-level/perl-packages.nix</filename> or wherever else
187
-
you need it.</para>
194
-
<section xml:id="sec-python"><title>Python</title>
197
-
Currently supported interpreters are <varname>python26</varname>, <varname>python27</varname>,
198
-
<varname>python33</varname>, <varname>python34</varname>, <varname>python35</varname>
199
-
and <varname>pypy</varname>.
203
-
<varname>python</varname> is an alias to <varname>python27</varname> and <varname>python3</varname> is an alias to <varname>python34</varname>.
207
-
<varname>python26</varname> and <varname>python27</varname> do not include modules that require
208
-
external dependencies (to reduce dependency bloat). Following modules need to be added as
209
-
<varname>buildInput</varname> explicitly:
213
-
<listitem><para><varname>python.modules.bsddb</varname></para></listitem>
214
-
<listitem><para><varname>python.modules.curses</varname></para></listitem>
215
-
<listitem><para><varname>python.modules.curses_panel</varname></para></listitem>
216
-
<listitem><para><varname>python.modules.crypt</varname></para></listitem>
217
-
<listitem><para><varname>python.modules.gdbm</varname></para></listitem>
218
-
<listitem><para><varname>python.modules.sqlite3</varname></para></listitem>
219
-
<listitem><para><varname>python.modules.tkinter</varname></para></listitem>
220
-
<listitem><para><varname>python.modules.readline</varname></para></listitem>
223
-
<para>For convenience <varname>python27Full</varname> and <varname>python26Full</varname>
224
-
are provided with all modules included.</para>
227
-
Python packages that
228
-
use <link xlink:href="http://pypi.python.org/pypi/setuptools/"><literal>setuptools</literal></link> or <literal>distutils</literal>,
229
-
can be built using the <varname>buildPythonPackage</varname> function as documented below.
233
-
All packages depending on any Python interpreter get appended <varname>$out/${python.sitePackages}</varname>
234
-
to <literal>$PYTHONPATH</literal> if such directory exists.
239
-
Useful attributes on interpreters packages:
243
-
<term><varname>libPrefix</varname></term>
245
-
Name of the folder in <literal>${python}/lib/</literal> for corresponding interpreter.
250
-
<term><varname>interpreter</varname></term>
252
-
Alias for <literal>${python}/bin/${executable}.</literal>
257
-
<term><varname>buildEnv</varname></term>
259
-
Function to build python interpreter environments with extra packages bundled together.
260
-
See <xref linkend="ssec-python-build-env" /> for usage and documentation.
265
-
<term><varname>sitePackages</varname></term>
267
-
Alias for <literal>lib/${libPrefix}/site-packages</literal>.
272
-
<term><varname>executable</varname></term>
274
-
Name of the interpreter executable, ie <literal>python3.4</literal>.
279
-
<section xml:id="ssec-build-python-package"><title><varname>buildPythonPackage</varname> function</title>
282
-
The function is implemented in <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/generic/default.nix">
283
-
<filename>pkgs/development/python-modules/generic/default.nix</filename></link>.
286
-
<programlisting language="nix">
287
-
twisted = buildPythonPackage {
288
-
name = "twisted-8.1.0";
290
-
src = pkgs.fetchurl {
291
-
url = http://tmrc.mit.edu/mirror/twisted/Twisted/8.1/Twisted-8.1.0.tar.bz2;
292
-
sha256 = "0q25zbr4xzknaghha72mq57kh53qw1bf8csgp63pm9sfi72qhirl";
295
-
propagatedBuildInputs = [ self.ZopeInterface ];
298
-
homepage = http://twistedmatrix.com/;
299
-
description = "Twisted, an event-driven networking engine written in Python";
300
-
license = stdenv.lib.licenses.mit;
305
-
Most of Python packages that use <varname>buildPythonPackage</varname> are defined
306
-
in <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/python-packages.nix"><filename>pkgs/top-level/python-packages.nix</filename></link>
307
-
and generated for each python interpreter separately into attribute sets <varname>python26Packages</varname>,
308
-
<varname>python27Packages</varname>, <varname>python35Packages</varname>, <varname>python33Packages</varname>,
309
-
<varname>python34Packages</varname> and <varname>pypyPackages</varname>.
313
-
<function>buildPythonPackage</function> mainly does four things:
317
-
In the <varname>buildPhase</varname>, it calls
318
-
<literal>${python.interpreter} setup.py bdist_wheel</literal> to build a wheel binary zipfile.
322
-
In the <varname>installPhase</varname>, it installs the wheel file using
323
-
<literal>pip install *.whl</literal>.
327
-
In the <varname>postFixup</varname> phase, <literal>wrapPythonPrograms</literal>
328
-
bash function is called to wrap all programs in <filename>$out/bin/*</filename>
329
-
directory to include <literal>$PYTHONPATH</literal> and <literal>$PATH</literal>
330
-
environment variables.
334
-
In the <varname>installCheck</varname> phase, <literal>${python.interpreter} setup.py test</literal>
340
-
<para>By default <varname>doCheck = true</varname> is set</para>
343
-
As in Perl, dependencies on other Python packages can be specified in the
344
-
<varname>buildInputs</varname> and
345
-
<varname>propagatedBuildInputs</varname> attributes. If something is
346
-
exclusively a build-time dependency, use
347
-
<varname>buildInputs</varname>; if it’s (also) a runtime dependency,
348
-
use <varname>propagatedBuildInputs</varname>.
352
-
By default <varname>meta.platforms</varname> is set to the same value
353
-
as the interpreter unless overriden otherwise.
358
-
<varname>buildPythonPackage</varname> parameters
359
-
(all parameters from <varname>mkDerivation</varname> function are still supported)
363
-
<term><varname>namePrefix</varname></term>
365
-
Prepended text to <varname>${name}</varname> parameter.
366
-
Defaults to <literal>"python3.3-"</literal> for Python 3.3, etc. Set it to
367
-
<literal>""</literal>
368
-
if you're packaging an application or a command line tool.
373
-
<term><varname>disabled</varname></term>
375
-
If <varname>true</varname>, package is not build for
376
-
particular python interpreter version. Grep around
377
-
<filename>pkgs/top-level/python-packages.nix</filename>
383
-
<term><varname>setupPyBuildFlags</varname></term>
385
-
List of flags passed to <command>setup.py build_ext</command> command.
390
-
<term><varname>pythonPath</varname></term>
392
-
List of packages to be added into <literal>$PYTHONPATH</literal>.
393
-
Packages in <varname>pythonPath</varname> are not propagated
394
-
(contrary to <varname>propagatedBuildInputs</varname>).
399
-
<term><varname>preShellHook</varname></term>
401
-
Hook to execute commands before <varname>shellHook</varname>.
406
-
<term><varname>postShellHook</varname></term>
408
-
Hook to execute commands after <varname>shellHook</varname>.
413
-
<term><varname>makeWrapperArgs</varname></term>
415
-
A list of strings. Arguments to be passed to
416
-
<varname>makeWrapper</varname>, which wraps generated binaries. By
417
-
default, the arguments to <varname>makeWrapper</varname> set
418
-
<varname>PATH</varname> and <varname>PYTHONPATH</varname> environment
419
-
variables before calling the binary. Additional arguments here can
420
-
allow a developer to set environment variables which will be
421
-
available when the binary is run. For example,
422
-
<varname>makeWrapperArgs = ["--set FOO BAR" "--set BAZ QUX"]</varname>.
430
-
<section xml:id="ssec-python-build-env"><title><function>python.buildEnv</function> function</title>
432
-
Create Python environments using low-level <function>pkgs.buildEnv</function> function. Example <filename>default.nix</filename>:
434
-
<programlisting language="nix">
435
-
<![CDATA[with import <nixpkgs> {};
437
-
python.buildEnv.override {
438
-
extraLibs = [ pkgs.pythonPackages.pyramid ];
439
-
ignoreCollisions = true;
443
-
Running <command>nix-build</command> will create
444
-
<filename>/nix/store/cf1xhjwzmdki7fasgr4kz6di72ykicl5-python-2.7.8-env</filename>
445
-
with wrapped binaries in <filename>bin/</filename>.
449
-
You can also use <varname>env</varname> attribute to create local
450
-
environments with needed packages installed (somewhat comparable to
451
-
<literal>virtualenv</literal>). For example, with the following
452
-
<filename>shell.nix</filename>:
454
-
<programlisting language="nix">
455
-
<![CDATA[with import <nixpkgs> {};
457
-
(python3.buildEnv.override {
458
-
extraLibs = with python3Packages;
465
-
Running <command>nix-shell</command> will drop you into a shell where
466
-
<command>python</command> will have specified packages in its path.
471
-
<function>python.buildEnv</function> arguments
475
-
<term><varname>extraLibs</varname></term>
477
-
List of packages installed inside the environment.
482
-
<term><varname>postBuild</varname></term>
484
-
Shell command executed after the build of environment.
489
-
<term><varname>ignoreCollisions</varname></term>
491
-
Ignore file collisions inside the environment (default is <varname>false</varname>).
497
-
<section xml:id="ssec-python-tools"><title>Tools</title>
499
-
<para>Packages inside nixpkgs are written by hand. However many tools
500
-
exist in community to help save time. No tool is preferred at the moment.
506
-
<link xlink:href="https://github.com/proger/python2nix">python2nix</link>
507
-
by Vladimir Kirillov
511
-
<link xlink:href="https://github.com/garbas/pypi2nix">pypi2nix</link>
516
-
<link xlink:href="https://github.com/offlinehacker/pypi2nix">pypi2nix</link>
524
-
<section xml:id="ssec-python-development"><title>Development</title>
527
-
To develop Python packages <function>buildPythonPackage</function> has
528
-
additional logic inside <varname>shellPhase</varname> to run
529
-
<command>pip install -e . --prefix $TMPDIR/</command> for the package.
532
-
<warning><para><varname>shellPhase</varname> is executed only if <filename>setup.py</filename>
533
-
exists.</para></warning>
536
-
Given a <filename>default.nix</filename>:
538
-
<programlisting language="nix">
539
-
<![CDATA[with import <nixpkgs> {};
541
-
buildPythonPackage {
542
-
name = "myproject";
544
-
buildInputs = with pkgs.pythonPackages; [ pyramid ];
550
-
Running <command>nix-shell</command> with no arguments should give you
551
-
the environment in which the package would be build with
552
-
<command>nix-build</command>.
556
-
Shortcut to setup environments with C headers/libraries and python packages:
558
-
<programlisting language="bash">$ nix-shell -p pythonPackages.pyramid zlib libjpeg git</programlisting>
562
-
There is a boolean value <varname>lib.inNixShell</varname> set to
563
-
<varname>true</varname> if nix-shell is invoked.
568
-
<section xml:id="ssec-python-faq"><title>FAQ</title>
573
-
<term>How to solve circular dependencies?</term>
575
-
If you have packages <varname>A</varname> and <varname>B</varname> that
576
-
depend on each other, when packaging <varname>B</varname> override package
577
-
<varname>A</varname> not to depend on <varname>B</varname> as input
578
-
(and also the other way around).
583
-
<term><varname>install_data / data_files</varname> problems resulting into <literal>error: could not create '/nix/store/6l1bvljpy8gazlsw2aw9skwwp4pmvyxw-python-2.7.8/etc': Permission denied</literal></term>
585
-
<link xlink:href="https://bitbucket.org/pypa/setuptools/issue/130/install_data-doesnt-respect-prefix">
586
-
Known bug in setuptools <varname>install_data</varname> does not respect --prefix</link>. Example of
587
-
such package using the feature is <filename>pkgs/tools/X11/xpra/default.nix</filename>. As workaround
588
-
install it as an extra <varname>preInstall</varname> step:
590
-
<programlisting>${python.interpreter} setup.py install_data --install-dir=$out --root=$out
591
-
sed -i '/ = data_files/d' setup.py</programlisting>
596
-
<term>Rationale of non-existent global site-packages</term>
598
-
There is no need to have global site-packages in Nix. Each package has isolated
599
-
dependency tree and installing any python package will only populate <varname>$PATH</varname>
600
-
inside user environment. See <xref linkend="ssec-python-build-env" /> to create self-contained
601
-
interpreter with a set of packages.
610
-
<section xml:id="ssec-python-contrib"><title>Contributing guidelines</title>
612
-
Following rules are desired to be respected:
618
-
Make sure package builds for all python interpreters. Use <varname>disabled</varname> argument to
619
-
<function>buildPythonPackage</function> to set unsupported interpreters.
623
-
If tests need to be disabled for a package, make sure you leave a comment about reasoning.
627
-
Packages in <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/python-packages.nix"><filename>pkgs/top-level/python-packages.nix</filename></link>
628
-
are sorted quasi-alphabetically to avoid merge conflicts.
638
-
<section xml:id="sec-language-ruby"><title>Ruby</title>
639
-
<para>There currently is support to bundle applications that are packaged as Ruby gems. The utility "bundix" allows you to write a <filename>Gemfile</filename>, let bundler create a <filename>Gemfile.lock</filename>, and then convert
640
-
this into a nix expression that contains all Gem dependencies automatically.</para>
642
-
<para>For example, to package sensu, we did:</para>
645
-
<![CDATA[$ cd pkgs/servers/monitoring
648
-
source 'https://rubygems.org'
650
-
$ bundler package --path /tmp/vendor/bundle
651
-
$ $(nix-build '<nixpkgs>' -A bundix)/bin/bundix
652
-
$ cat > default.nix
653
-
{ lib, bundlerEnv, ruby }:
656
-
name = "sensu-0.17.1";
659
-
gemfile = ./Gemfile;
660
-
lockfile = ./Gemfile.lock;
661
-
gemset = ./gemset.nix;
664
-
description = "A monitoring framework that aims to be simple, malleable,
666
-
homepage = http://sensuapp.org/;
667
-
license = with licenses; mit;
668
-
maintainers = with maintainers; [ theuni ];
669
-
platforms = platforms.unix;
674
-
<para>Please check in the <filename>Gemfile</filename>, <filename>Gemfile.lock</filename> and the <filename>gemset.nix</filename> so future updates can be run easily.
679
-
<section xml:id="sec-language-go"><title>Go</title>
681
-
<para>The function <varname>buildGoPackage</varname> builds
682
-
standard Go packages.
685
-
<example xml:id='ex-buildGoPackage'><title>buildGoPackage</title>
687
-
net = buildGoPackage rec {
688
-
name = "go.net-${rev}";
689
-
goPackagePath = "golang.org/x/net"; <co xml:id='ex-buildGoPackage-1' />
690
-
subPackages = [ "ipv4" "ipv6" ]; <co xml:id='ex-buildGoPackage-2' />
691
-
rev = "e0403b4e005";
692
-
src = fetchFromGitHub {
696
-
sha256 = "1g7cjzw4g4301a3yqpbk8n1d4s97sfby2aysl275x04g0zh8jxqp";
698
-
goPackageAliases = [ "code.google.com/p/go.net" ]; <co xml:id='ex-buildGoPackage-3' />
699
-
propagatedBuildInputs = [ goPackages.text ]; <co xml:id='ex-buildGoPackage-4' />
700
-
buildFlags = "--tags release"; <co xml:id='ex-buildGoPackage-5' />
701
-
disabled = isGo13;<co xml:id='ex-buildGoPackage-6' />
706
-
<para><xref linkend='ex-buildGoPackage'/> is an example expression using buildGoPackage,
707
-
the following arguments are of special significance to the function:
711
-
<callout arearefs='ex-buildGoPackage-1'>
713
-
<varname>goPackagePath</varname> specifies the package's canonical Go import path.
717
-
<callout arearefs='ex-buildGoPackage-2'>
719
-
<varname>subPackages</varname> limits the builder from building child packages that
720
-
have not been listed. If <varname>subPackages</varname> is not specified, all child
721
-
packages will be built.
724
-
In this example only <literal>code.google.com/p/go.net/ipv4</literal> and
725
-
<literal>code.google.com/p/go.net/ipv6</literal> will be built.
729
-
<callout arearefs='ex-buildGoPackage-3'>
731
-
<varname>goPackageAliases</varname> is a list of alternative import paths
732
-
that are valid for this library.
733
-
Packages that depend on this library will automatically rename
734
-
import paths that match any of the aliases to <literal>goPackagePath</literal>.
737
-
In this example imports will be renamed from
738
-
<literal>code.google.com/p/go.net</literal> to
739
-
<literal>golang.org/x/net</literal> in every package that depend on the
740
-
<literal>go.net</literal> library.
744
-
<callout arearefs='ex-buildGoPackage-4'>
746
-
<varname>propagatedBuildInputs</varname> is where the dependencies of a Go library are
747
-
listed. Only libraries should list <varname>propagatedBuildInputs</varname>. If a standalone
748
-
program is being built instead, use <varname>buildInputs</varname>. If a library's tests require
749
-
additional dependencies that are not propagated, they should be listed in <varname>buildInputs</varname>.
753
-
<callout arearefs='ex-buildGoPackage-5'>
755
-
<varname>buildFlags</varname> is a list of flags passed to the go build command.
759
-
<callout arearefs='ex-buildGoPackage-6'>
761
-
If <varname>disabled</varname> is <literal>true</literal>,
762
-
nix will refuse to build this package.
765
-
In this example the package will not be built for go 1.3. The <literal>isGo13</literal>
766
-
is an utility function that returns <literal>true</literal> if go used to build the
767
-
package has version 1.3.x.
776
-
Reusable Go libraries may be found in the <varname>goPackages</varname> set. You can test
777
-
build a Go package as follows:
780
-
$ nix-build -A goPackages.net
786
-
You may use Go packages installed into the active Nix profiles by adding
787
-
the following to your ~/.bashrc:
790
-
for p in $NIX_PROFILES; do
791
-
GOPATH="$p/share/go:$GOPATH"
796
-
<para>To extract dependency information from a Go package in automated way use <link xlink:href="https://github.com/cstrahan/go2nix">go2nix</link>.</para>
800
-
<section xml:id="sec-language-java"><title>Java</title>
802
-
<para>Ant-based Java packages are typically built from source as follows:
805
-
stdenv.mkDerivation {
807
-
src = fetchurl { ... };
809
-
buildInputs = [ jdk ant ];
811
-
buildPhase = "ant";
815
-
Note that <varname>jdk</varname> is an alias for the OpenJDK.</para>
817
-
<para>JAR files that are intended to be used by other packages should
818
-
be installed in <filename>$out/share/java</filename>. The OpenJDK has
819
-
a stdenv setup hook that adds any JARs in the
820
-
<filename>share/java</filename> directories of the build inputs to the
821
-
<envar>CLASSPATH</envar> environment variable. For instance, if the
822
-
package <literal>libfoo</literal> installs a JAR named
823
-
<filename>foo.jar</filename> in its <filename>share/java</filename>
824
-
directory, and another package declares the attribute
827
-
buildInputs = [ jdk libfoo ];
830
-
then <envar>CLASSPATH</envar> will be set to
831
-
<filename>/nix/store/...-libfoo/share/java/foo.jar</filename>.</para>
834
-
should be installed in a location like
835
-
<filename>$out/share/<replaceable>package-name</replaceable></filename>.</para>
837
-
<para>If your Java package provides a program, you need to generate a
838
-
wrapper script to run it using the OpenJRE. You can use
839
-
<literal>makeWrapper</literal> for this:
842
-
buildInputs = [ makeWrapper ];
847
-
makeWrapper ${jre}/bin/java $out/bin/foo \
848
-
--add-flags "-cp $out/share/java/foo.jar org.foo.Main"
852
-
Note the use of <literal>jre</literal>, which is the part of the
853
-
OpenJDK package that contains the Java Runtime Environment. By using
854
-
<literal>${jre}/bin/java</literal> instead of
855
-
<literal>${jdk}/bin/java</literal>, you prevent your package from
856
-
depending on the JDK at runtime.</para>
858
-
<para>It is possible to use a different Java compiler than
859
-
<command>javac</command> from the OpenJDK. For instance, to use the
860
-
Eclipse Java Compiler:
863
-
buildInputs = [ jre ant ecj ];
866
-
(Note that here you don’t need the full JDK as an input, but just the
867
-
JRE.) The ECJ has a stdenv setup hook that sets some environment
868
-
variables to cause Ant to use ECJ, but this doesn’t work with all Ant
869
-
files. Similarly, you can use the GNU Java Compiler:
872
-
buildInputs = [ gcj ant ];
875
-
Here, Ant will automatically use <command>gij</command> (the GNU Java
876
-
Runtime) instead of the OpenJRE.</para>
881
-
<section xml:id="sec-language-lua"><title>Lua</title>
884
-
Lua packages are built by the <varname>buildLuaPackage</varname> function. This function is
886
-
in <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/lua-modules/generic/default.nix">
887
-
<filename>pkgs/development/lua-modules/generic/default.nix</filename></link>
888
-
and works similarly to <varname>buildPerlPackage</varname>. (See
889
-
<xref linkend="sec-language-perl"/> for details.)
893
-
Lua packages are defined
894
-
in <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/lua-packages.nix"><filename>pkgs/top-level/lua-packages.nix</filename></link>.
895
-
Most of them are simple. For example:
898
-
fileSystem = buildLuaPackage {
899
-
name = "filesystem-1.6.2";
901
-
url = "https://github.com/keplerproject/luafilesystem/archive/v1_6_2.tar.gz";
902
-
sha256 = "1n8qdwa20ypbrny99vhkmx8q04zd2jjycdb5196xdhgvqzk10abz";
905
-
homepage = "https://github.com/keplerproject/luafilesystem";
906
-
hydraPlatforms = stdenv.lib.platforms.linux;
907
-
maintainers = with maintainers; [ flosse ];
914
-
Though, more complicated package should be placed in a seperate file in
916
-
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/lua-modules"><filename>pkgs/development/lua-modules</filename></link>.
919
-
Lua packages accept additional parameter <varname>disabled</varname>, which defines
920
-
the condition of disabling package from luaPackages. For example, if package has
921
-
<varname>disabled</varname> assigned to <literal>lua.luaversion != "5.1"</literal>,
922
-
it will not be included in any luaPackages except lua51Packages, making it
923
-
only be built for lua 5.1.
928
-
<section xml:id="sec-language-coq"><title>Coq</title>
930
-
Coq libraries should be installed in
931
-
<literal>$(out)/lib/coq/${coq.coq-version}/user-contrib/</literal>.
932
-
Such directories are automatically added to the
933
-
<literal>$COQPATH</literal> environment variable by the hook defined
934
-
in the Coq derivation.
937
-
Some libraries require OCaml and sometimes also Camlp5. The exact
938
-
versions that were used to build Coq are saved in the
939
-
<literal>coq.ocaml</literal> and <literal>coq.camlp5</literal>
943
-
Here is a simple package example. It is a pure Coq library, thus it
944
-
only depends on Coq. Its <literal>makefile</literal> has been
945
-
generated using <literal>coq_makefile</literal> so we only have to
946
-
set the <literal>$COQLIB</literal> variable at install time.
949
-
{stdenv, fetchurl, coq}:
950
-
stdenv.mkDerivation {
952
-
url = http://coq.inria.fr/pylons/contribs/files/Karatsuba/v8.4/Karatsuba.tar.gz;
953
-
sha256 = "0ymfpv4v49k4fm63nq6gcl1hbnnxrvjjp7yzc4973n49b853c5b1";
956
-
name = "coq-karatsuba";
958
-
buildInputs = [ coq ];
960
-
installFlags = "COQLIB=$(out)/lib/coq/${coq.coq-version}/";
965
-
<section xml:id="sec-language-qt"><title>Qt</title>
967
-
<para>The information in this section applies to Qt 5.5 and later.</para>
969
-
<para>Qt is an application development toolkit for C++. Although it is
970
-
not a distinct programming language, there are special considerations
971
-
for packaging Qt-based programs and libraries. A small set of tools
972
-
and conventions has grown out of these considerations.</para>
974
-
<section xml:id="ssec-qt-libraries"><title>Libraries</title>
976
-
<para>Packages that provide libraries should be listed in
977
-
<varname>qt5LibsFun</varname> so that the library is built with each
978
-
Qt version. A set of packages is provided for each version of Qt; for
979
-
example, <varname>qt5Libs</varname> always provides libraries built
980
-
with the latest version, <varname>qt55Libs</varname> provides
981
-
libraries built with Qt 5.5, and so on. To avoid version conflicts, no
982
-
top-level attributes are created for these packages.</para>
986
-
<section xml:id="ssec-qt-programs"><title>Programs</title>
988
-
<para>Application packages do not need to be built with every Qt
989
-
version. To ensure consistency between the package's dependencies,
990
-
call the package with <literal>qt5Libs.callPackage</literal> instead
991
-
of the usual <literal>callPackage</literal>. An older version may be
992
-
selected in case of incompatibility. For example, to build with Qt
993
-
5.5, call the package with
994
-
<literal>qt55Libs.callPackage</literal>.</para>
996
-
<para>Several environment variables must be set at runtime for Qt
997
-
applications to function correctly, including:</para>
1000
-
<listitem><para><envar>QT_PLUGIN_PATH</envar></para></listitem>
1001
-
<listitem><para><envar>QML_IMPORT_PATH</envar></para></listitem>
1002
-
<listitem><para><envar>QML2_IMPORT_PATH</envar></para></listitem>
1003
-
<listitem><para><envar>XDG_DATA_DIRS</envar></para></listitem>
1006
-
<para>To ensure that these are set correctly, the program must be wrapped by
1007
-
invoking <literal>wrapQtProgram <replaceable>program</replaceable></literal>
1008
-
during installation (for example, during
1009
-
<literal>fixupPhase</literal>). <literal>wrapQtProgram</literal>
1010
-
accepts the same options as <literal>makeWrapper</literal>.
1015
-
<section xml:id="ssec-qt-kde"><title>KDE</title>
1017
-
<para>Many of the considerations above also apply to KDE packages,
1018
-
especially the need to set the correct environment variables at
1019
-
runtime. To ensure that this is done, invoke <literal>wrapKDEProgram
1020
-
<replaceable>program</replaceable></literal> during
1021
-
installation. <literal>wrapKDEProgram</literal> also generates a
1022
-
<literal>ksycoca</literal> database so that required data and services
1023
-
can be found. Like its Qt counterpart,
1024
-
<literal>wrapKDEProgram</literal> accepts the same options as
1025
-
<literal>makeWrapper</literal>.</para>
1032
-
<section><title>Haskell</title>
1039
-
<section><title>TeX / LaTeX</title>
1041
-
<para>* Special support for building TeX documents</para>