Getting Started¶
Welcome! It's great to see that you're interested in Nix and also in Ethereum.nix. These installation instructions are intended to have a basic installation of Nix on your system ready to be used alongside Ethereum.nix.
Of course, if you're a seasoned Nix user, these installation instructions can be safely skipped (as you probably know what you're doing!).
What is exactly Nix?
Some people might need clarification on what exactly is Nix. To clarify:
- Nix is a cross-platform package manager that utilizes a purely functional deployment model where software is installed into unique directories generated through cryptographic hashes.
- Nix is also the name of the tool's programming language.
- NixOS is a Linux distribution based on the Nix package manager.
We recommend you have a look at the following sources to get yourself familiar with the Nix ecosystem and mechanics first before starting with Ethereum.nix:
- Zero to Nix: A well-written guide with insightful information about using Nix and several important concepts.
- Nix Reference Manual: This is a more comprenhensive guide (and also more notoriosly difficult) about Nix.
Installation¶
Nix, the package manager, can be installed quite easily using the official installation script. We have left the installation instructions here for your convenience1. Still, we recommend looking at the official source should you have more questions or want to customize the installation experience.
On non-Nix systems (Linux, MacOS, Windows WSL2, Docker)¶
For some systems, there are two installation methods:
Which type of installation should you choose? Multi-user or Single user?
This depends on your requirements, but here is a short list of reasons why it's recommended the multi-user installation:
Pros:
- Better build isolation (and that is what Nix is all about).
- Better security (a build can not write somewhere in your home).
- Sharing builds between users.
Cons:
- Requires root to run the daemon.
- More involved installation (creation of
nixbld*
users, installing a systemd unit, ...). - Harder to uninstall.
To run the installer:
Info
Above command will perform a single-user installation of Nix, meaning that /nix
is owned by the invoking user. You should run this under your usual user account, not as root
. The script will invoke sudo to create /nix
if it doesn’t already exist.
Info
WSL versions 0.67.6 and above have systemd support. Follow Microsoft's systemd guide to configure it, and then install Nix using
Open a new terminal session, and the nix executable should be in your $PATH
. To verify that:
This should print the version information for Nix.
On NixOS¶
If you're running NixOS, you don't need to install Nix, as it's already included!
Enable Flakes Support¶
Make sure Nix Flakes functionality is enabled to ease your operations when using Ethereum.nix.
Aren't Nix Flakes experimental?
Nix flakes are still in the experimental stage within Nix, and there's no defined timeline for their official launch. While we don't expect significant changes to the user interface for flakes during the experimental phase, there could still be some minor changes.
We believe that enabling Flakes is the best form of learning Nix for those new to the ecosystem.
On non-Nix systems (Linux, MacOS, Windows WSL2, Docker)¶
Edit (or create) either ~/.config/nix/nix.conf
or /etc/nix/nix.conf
and add the following entry:
If the Nix installation is in multi-user mode, don’t forget to restart the nix-daemon
.
To verify that Nix flakes are enabled just type the following on the terminal:
It should display what we already wrote on the config file:
On NixOS¶
To do so, edit your configuration.nix
and add the following:
And rebuild your system closure! That's it!
Add Ethereum.nix to your Flake registry¶
When dealing with Ethereum.nix, we can use of flakes registries. Flake registries are a convenience feature that allows you to refer to flakes using symbolic identifiers such as nixpkgs
, rather than full URLs such as git://github.com/NixOS/nixpkgs
. You can use these identifiers on the command line (e.g. when you do nix run nixpkgs#hello
) or in flake input specifications in flake.nix
files.
If you're curious, you can list all registries that are available in your system with the following command:
We do recommend adding Ethereum.nix to your flake registry. To do so:
You can verify that this works by just typing the following:
After a while (the first invocation, the command will take a little bit), the current version of geth should appear!
- You can choose another alias instead of
enix
. We named itenix
because it's short and sweet!
-
Thanks to the Nix/NixOS documentation team. ↩