Packaging/Quirks and Caveats: Difference between revisions

imported>Mic92
No edit summary
imported>Fadenb
m Syntax highlighting
Line 7: Line 7:
Add <code>autoreconfHook</code> to <code>buildInputs</code> to automatically build software which uses <code>automake</code> and <code>autoconf</code>:
Add <code>autoreconfHook</code> to <code>buildInputs</code> to automatically build software which uses <code>automake</code> and <code>autoconf</code>:


<pre> buildInputs = [ ...  autoreconfHook ];</pre>
<syntaxhighlight lang="nix">
buildInputs = [ ...  autoreconfHook ];
</syntaxhighlight>
Examples in nixpkgs: * [https://github.com/NixOS/nixpkgs/blob/f4c253ff2f68fbe3e302f944e8347233d9dc8c9d/pkgs/tools/networking/samplicator/default.nix samplicator]
Examples in nixpkgs: * [https://github.com/NixOS/nixpkgs/blob/f4c253ff2f68fbe3e302f944e8347233d9dc8c9d/pkgs/tools/networking/samplicator/default.nix samplicator]


=== Package simple python scripts ===
=== Package simple python scripts ===


For scripts like a single Python file, it is not necessary to specify <code>src</code> in <code>mkDerivation</code>. When you want to use <code>buildPythonPackage</code> the sources need to provide a <code>setup.py</code> file which also is overkill for a lot of projects. The default <code>mkDerivation</code> will attempt to unpack your source code. This can be prevented that by applying <code>unpackPhase = &quot;:&quot;;</code> (<code>:</code> is a no-op in shell scripts).
For scripts like a single Python file, it is not necessary to specify <code>src</code> in <code>mkDerivation</code>. When you want to use <code>buildPythonPackage</code> the sources need to provide a <code>setup.py</code> file which also is overkill for a lot of projects. The default <code>mkDerivation</code> will attempt to unpack your source code. This can be prevented that by applying <code>unpackPhase = ":";</code> (<code>:</code> is a no-op in shell scripts).


<pre class="nix">myscript-package = pkgs.stdenv.mkDerivation {
<syntaxhighlight lang="nix">myscript-package = pkgs.stdenv.mkDerivation {
   name = &quot;myscript&quot;;
   name = "myscript";
   buildInputs = [
   buildInputs = [
     (pkgs.python36.withPackages (pythonPackages: with pythonPackages; [
     (pkgs.python36.withPackages (pythonPackages: with pythonPackages; [
Line 23: Line 25:
     ]))
     ]))
   ];
   ];
   unpackPhase = &quot;:&quot;;
   unpackPhase = ":";
   installPhase = &quot;install -m755 -D ${./myscript.py} $out/bin/myscript&quot;;
   installPhase = "install -m755 -D ${./myscript.py} $out/bin/myscript";
};</pre>
};</syntaxhighlight>
<code>nix</code> will automatically replace shebangs, for ex. <code>#!/usr/bin/env python3</code> with dependencies given in <code>buildInputs</code>. As the derivation got <code>pkgs.python36.withPackages (...)</code> in <code>buildInputs</code>, it will create a [https://virtualenv.pypa.io/en/stable/ virtualenv]-like python wrapper. The python wrapper will have all specified dependencies and will be used to call the script.
<code>nix</code> will automatically replace shebangs, for ex. <code>#!/usr/bin/env python3</code> with dependencies given in <code>buildInputs</code>. As the derivation got <code>pkgs.python36.withPackages (...)</code> in <code>buildInputs</code>, it will create a [https://virtualenv.pypa.io/en/stable/ virtualenv]-like python wrapper. The python wrapper will have all specified dependencies and will be used to call the script.