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/declarative-and-reproducible-developer-environments.rst

62 lines
1.5 KiB
ReStructuredText
Raw Normal View History

2020-05-22 04:17:14 -04:00
Declarative and reproducible developer environments
===================================================
2020-05-18 04:52:41 -04:00
Nix can create reproducible environments given a declarative
configuration called a Nix expression.
Reproducible means you can share
2020-05-18 04:52:41 -04:00
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 default binary cache.
2020-06-25 05:49:16 -04:00
Once it's done, you are dropped into a new
2020-05-18 04:52:41 -04:00
shell. This shell provides the packages specified in ``shell.nix``.
2020-06-25 05:49:16 -04:00
Run ``htop`` to confirm it is present. Quit the program by hitting
2020-05-18 04:52:41 -04:00
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