Development environment with nix-shell: Difference between revisions

Mightyiam (talk | contribs)
Link to relevant Nixcademy article
DHCP (talk | contribs)
m style improvements
 
Line 37: Line 37:


Then just run:
Then just run:
{{Commands|$ nix-shell}}
 
<syntaxhighlight lang="console">
$ nix-shell
</syntaxhighlight>


Or, to be more explicit:
Or, to be more explicit:
{{Commands|$ nix-shell shell.nix}}
 
<syntaxhighlight lang="console">
$ nix-shell shell.nix
</syntaxhighlight>


Now you have rustc available in your shell:
Now you have rustc available in your shell:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="console">
$ rustc --version
$ rustc --version
rustc 1.80.1 (3f5fd8dd4 2024-08-06) (built from a source tarball)
rustc 1.80.1 (3f5fd8dd4 2024-08-06) (built from a source tarball)
Line 84: Line 90:
Example: Building Nix in a development shell, to get [[Incremental builds]] = faster recompiles. This is because Nix evaluations are cached.
Example: Building Nix in a development shell, to get [[Incremental builds]] = faster recompiles. This is because Nix evaluations are cached.


<pre>
<syntaxhighlight lang="console">
git clone https://github.com/NixOS/nix --depth 1
$ git clone https://github.com/NixOS/nix --depth 1
cd nix
$ cd nix
nix develop
$ nix develop
</pre>
</syntaxhighlight>


Now what? Let's read the manual:
Now what? Let's read the manual:


<pre>
<syntaxhighlight lang="console">
less README.md
$ less README.md
less doc/manual/src/contributing/hacking.md
$ less doc/manual/src/contributing/hacking.md
</pre>
</syntaxhighlight>


The contributing guide for Nix says:
The contributing guide for Nix says:
Line 118: Line 124:
So, in our <code>nix develop</code> shell, we run
So, in our <code>nix develop</code> shell, we run


<pre>
<syntaxhighlight lang="console">
./bootstrap.sh
$ ./bootstrap.sh
./configure $configureFlags --prefix=$(pwd)/outputs/out
$ ./configure $configureFlags --prefix=$(pwd)/outputs/out
make -j $NIX_BUILD_CORES
$ make -j $NIX_BUILD_CORES
</pre>
</syntaxhighlight>


This will compile Nix to <code>./outputs/out/bin/nix</code>
This will compile Nix to <code>./outputs/out/bin/nix</code>
Line 146: Line 152:
Then you can start a development shell with
Then you can start a development shell with


<syntaxHighlight lang=bash>
<syntaxHighlight lang=console>
nix-shell -E 'with import <nixpkgs> { }; callPackage ./default.nix { }'
$ nix-shell -E 'with import <nixpkgs> { }; callPackage ./default.nix { }'
</syntaxHighlight>
</syntaxHighlight>


Line 159: Line 165:
# this is useful to make many small changes to a large project
# this is useful to make many small changes to a large project
# after each change, just run `buildPhase`
# after each change, just run `buildPhase`
#cd $HOME/path/to/project
# cd $HOME/path/to/project


configurePhase
configurePhase
Line 179: Line 185:


When compiling software which links against local files (e.g. when compiling with rust's cargo), you may encounter the following problem:
When compiling software which links against local files (e.g. when compiling with rust's cargo), you may encounter the following problem:
<syntaxHighlight lang=bash>
<syntaxHighlight lang=console>
= note: impure path `/[...]' used in link
= note: impure path `/[...]' used in link
</syntaxHighlight>
</syntaxHighlight>
Line 208: Line 214:
=== Icons not working ===
=== Icons not working ===
Similar to the Gsettings issue, icons can be added with XDG_DATA_DIRS:
Similar to the Gsettings issue, icons can be added with XDG_DATA_DIRS:
<pre> XDG_DATA_DIRS=...:${hicolor-icon-theme}/share:${gnome3.adwaita-icon-theme}/share</pre>
<syntaxhighlight lang=bash>
XDG_DATA_DIRS=...:${hicolor-icon-theme}/share:${gnome3.adwaita-icon-theme}/share
</syntaxhighlight>


== See Also ==
== See Also ==