Development environment with nix-shell: Difference between revisions
imported>Milahu add "dirty build" to stdenv.mkDerivation |
imported>Milahu + nix develop |
||
| Line 40: | Line 40: | ||
If you want to see how to manually run the various phases of a given derivation from a nix-shell (useful to debug), see [[Nixpkgs/Create_and_debug_packages#Using_nix-shell_for_package_development]]. | If you want to see how to manually run the various phases of a given derivation from a nix-shell (useful to debug), see [[Nixpkgs/Create_and_debug_packages#Using_nix-shell_for_package_development]]. | ||
=== stdenv.mkDerivation | == nix develop == | ||
For [[Flakes]]-based projects (<code>flake.nix</code> file in project root), | |||
we replace <code>nix-shell</code> with <code>nix develop</code> | |||
Example: Building Nix in a development shell, to get [[Incremental builds]] = faster recompiles | |||
<pre> | |||
git clone https://github.com/NixOS/nix --depth 1 | |||
cd nix | |||
nix develop | |||
</pre> | |||
Now what? Let's read the manual: | |||
<pre> | |||
less README.md | |||
less doc/manual/src/contributing/hacking.md | |||
</pre> | |||
The contributing guide for Nix says: | |||
<pre> | |||
To build all dependencies and start a shell in which all environment | |||
variables are set up so that those dependencies can be found: | |||
```console | |||
$ nix-shell | |||
``` | |||
To build Nix itself in this shell: | |||
```console | |||
[nix-shell]$ ./bootstrap.sh | |||
[nix-shell]$ ./configure $configureFlags --prefix=$(pwd)/outputs/out | |||
[nix-shell]$ make -j $NIX_BUILD_CORES | |||
``` | |||
</pre> | |||
So, in our <code>nix develop</code> shell, we run | |||
<pre> | |||
./bootstrap.sh | |||
./configure $configureFlags --prefix=$(pwd)/outputs/out | |||
make -j $NIX_BUILD_CORES | |||
</pre> | |||
This will compile Nix to <code>./outputs/out/bin/nix</code> | |||
Let's make some changes to the source code, and run <code>make</code> again.<br> | |||
Now the compilation should be much faster (see [[Incremental builds]]) | |||
== stdenv.mkDerivation == | |||
Let's assume you have a <code>default.nix</code> file | Let's assume you have a <code>default.nix</code> file | ||
| Line 78: | Line 130: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== cross env == | |||
The comments in the code snippets on <code>nativeBuildInputs</code> and <code>buildInputs</code> above might seem pedantic --- who cares about build-time vs run-time when we're just making a dev environment, not a real package! However, the distinction becomes of practical importance if one wants a cross compilation development environment. In that case one would begin file with something like: | The comments in the code snippets on <code>nativeBuildInputs</code> and <code>buildInputs</code> above might seem pedantic --- who cares about build-time vs run-time when we're just making a dev environment, not a real package! However, the distinction becomes of practical importance if one wants a cross compilation development environment. In that case one would begin file with something like: | ||