1
0
Fork 0
mirror of https://github.com/NixOS/nix.dev.git synced 2024-10-18 14:32:43 -04:00
nix.dev/source/tutorials/first-shell.rst

57 lines
1.4 KiB
ReStructuredText
Raw Normal View History

2020-05-18 04:52:41 -04:00
Your first shell
================
Nix can create reproducible environments given a declarative
configuration called a Nix expression. Reproducible means you can share
the configuration with others and guarantee that they are using the same
software as you.
To get started, make a new folder and create a file called ``shell.nix``
with the following contents:
2020-05-18 05:41:12 -04:00
.. code:: nix
2020-05-18 04:52:41 -04:00
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.which
pkgs.htop
];
}
Basically we import our package channel ``nixpkgs`` and make a shell
with ``which`` and ``htop`` as inputs. To enter this environment, type
in:
2020-05-18 05:41:12 -04:00
.. code:: bash
2020-05-18 04:52:41 -04:00
nix-shell
The command will start downloading the missing packages from the cache.
This may take a few moments. When it is done, you are dropped into a new
shell. This shell provides the packages specified in ``shell.nix``.
Run ``htop`` to confirm it is present. Quit the program again by hitting
Q.
Now try ``which htop`` to check where the ``htop`` command is on-disk.
You should see something similar to this:
2020-05-18 05:41:12 -04:00
.. code:: bash
2020-05-18 04:52:41 -04:00
/nix/store/y3w2i8kfdbfj9rx287ad52rahjpgv423-htop-2.2.0/bin/htop
This is the path to the binary in the Nix store. Nix installs all
packages into the store using a combination of its hash, name and
version.
You can search for available packages using ``nix-env -qa``, for
example:
2020-05-18 05:41:12 -04:00
.. code:: bash
2020-05-18 04:52:41 -04:00
nix-env -qa python3
nix-env -qa nodejs
nix-env -qa ghc
nix-env -qa cargo