Tutorial: Install and configure NixOS for bitcoinix on a dedicated machine
This tutorial describes how to manage your Bitcoin node comfortably from your personal computer: you keep the node configuration in a Nix flake and deploy it over SSH with nixos-rebuild or Colmena.
The deployment tool krops is described as a legacy alternative.
However, bitcoinix is agnostic to the deployment method and can be used with different or without such tools (see examples).
0. Preparation
-
Find a machine to deploy bitcoinix on (see hardware.md).
-
Optional: Make sure you have the latest firmware for your system (BIOS, microcode updates).
-
Optional: Disable Simultaneous Multi-Threading (SMT) in the BIOS
Researchers recommend disabling (SMT), also known as Hyper-Threading Technology in the Intel® world to significantly reduce the impact of speculative execution-based attacks (https://mdsattacks.com/).
1. NixOS installation
-
Install NixOS on the node as described in the NixOS manual. Use the minimal ISO image for the platform of your node (
x86_64-linuxoraarch64-linux) from https://nixos.org/download/. To encrypt the disk, see LUKS-Encrypted File Systems. -
Before you run
nixos-install, enable SSH and add the SSH public key of the computer you deploy from to/mnt/etc/nixos/configuration.nix:services.openssh.enable = true; users.users.root.openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAA... you@your-computer" # FIXME ];The deployment logs in as root with this key. With the default
services.openssh.settings.PermitRootLogin = "prohibit-password", root can’t log in over SSH with a password. -
Finish the installation as described in the manual, and reboot.
2. Nix installation
Run these steps on the computer you deploy from, not on the node.
-
Install git, and install Nix in multi-user mode as described at https://nixos.org/download/. On NixOS, Nix is already installed.
-
Enable flakes, which the deployment below uses
mkdir -p ~/.config/nix echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.confOn NixOS, set
nix.settings.experimental-features = [ "nix-command" "flakes" ];instead. -
Optional: Disallow substitutes
You can put
substitute = falseto yournix.confusually found in/etc/nix/to build the packages from source. This eliminates an attack vector where Nix’s build server or binary cache is compromised.
3. Get and verify bitcoinix
-
Clone this project
git clone https://github.com/bitcoinix/bitcoinix cd bitcoinix -
Verify the release signing keys
A bitcoinix release is a signed git tag. The list of keys that may sign releases lives in the repository you just cloned, so it cannot vouch for itself. Print the fingerprints of the listed keys:
grep -v '^#' helper/release-keys/ssh-allowed-signers | cut -d' ' -f3- | ssh-keygen -lf -The release tag key,
SHA256:2o/0Op+64zKgF4oMaS0LGOiGPNDsibaqX6g8qMf5Hz0, is also published outside this repository at https://seberm.com/ssh.html. Verify that statement as described on that page and check that the same fingerprint is listed above. Do not continue if it is not. -
Verify and check out the latest release
git config gpg.ssh.allowedSignersFile helper/release-keys/ssh-allowed-signers git config gpg.ssh.revocationFile helper/release-keys/ssh-revoked-keys git tag -l 'v*' --sort=-v:refname | head -1 # the latest release, e.g. v0.1.0 git tag -v v<version> git checkout v<version> cd ..git tag -vmust reportGood "git" signaturewith the release tag key fingerprint from the previous step. Checking out the tag makes sure that the files used below, includingfetch-release.shand its key files, are the ones that were signed.
4. Deploy with a flake
Your node configuration is a Nix flake that has bitcoinix as an input. You deploy it from your
computer over SSH with nixos-rebuild or Colmena. CI builds both
examples on code-changing pull requests and pushes to master; documentation-only PRs skip these builds.
-
Copy an example to a new directory next to the bitcoinix clone
For
nixos-rebuild, useexamples/flakes. For Colmena, useexamples/colmena, a larger node. Both use the secure-node preset.cp -r bitcoinix/examples/flakes node-config # or bitcoinix/examples/colmena cd node-config git initFlakes only see files that git tracks, so
git addevery file you create. -
Pin the release that you verified in step 3
In
flake.nix, set thebitcoinixinput to the release tag:bitcoinix.url = "github:bitcoinix/bitcoinix/v<version>";Then lock the inputs and check that the locked commit is the one you verified:
nix flake lock nix flake metadata --json | nix run nixpkgs#jq -- -r .locks.nodes.bitcoinix.locked.rev git -C ../bitcoinix rev-parse 'v<version>^{commit}'Both commands must print the same commit. Commit
flake.lock, and repeat this step for every update. -
Adapt the configuration
Copy
hardware-configuration.nixfrom your node and import it in place of the example’s placeholders (in the Colmena example, replaceconfigs/fullnode/hardware-configuration.nix):scp root@<node>:/etc/nixos/hardware-configuration.nix .Edit all lines marked
FIXME. Above all, add your SSH public key tousers.users.root.openssh.authorizedKeys.keys: the deployment logs in as root, and without the key you lose remote access to the node. -
Deploy
With
nixos-rebuild:nix run nixpkgs#nixos-rebuild -- switch --flake .#fullnode --target-host root@<node>This builds the system on your computer and copies it to the node. To build on the node instead, for example when you deploy from macOS, add
--build-host root@<node>.With Colmena, set
deployment.targetHostinflake.nix, then:nix develop colmena apply --on fullnodeswitch(the Colmena default) activates the new system on the running node, which can cause problems. For updates, above all of bitcoinix, preferbootand a reboot: replaceswitchwithbootin thenixos-rebuildcommand, or runcolmena apply --on fullnode boot, thenssh root@<node> reboot. -
With the secure-node preset, you can now log in as the unprivileged
operatoruserssh operator@<node>bitcoinix authorizes the SSH keys of
rootforoperator. Useoperatorfor normal system management, and log in asrootas rarely as possible.
5. Alternative: deploy with krops (legacy)
Note
krops is the deployment tool of nix-bitcoin, the predecessor project. Support for it may be removed in a future release. Prefer a flake-based deployment.
Set up the deployment directory
These steps continue from step 3 above.
-
Create a new directory for your bitcoinix node config and copy initial files from bitcoinix
mkdir nix-bitcoin-node cd nix-bitcoin-node cp -r ../bitcoinix/examples/{configuration.nix,shell.nix,krops,.gitignore} . -
Obtain the hash of the latest bitcoinix release
../bitcoinix/helper/fetch-release.sh > nix-bitcoin-release.nixfetch-releasepicks the highest signed release tag, verifies it againsthelper/release-keys/ssh-allowed-signersandhelper/release-keys/ssh-revoked-keys, and refuses to emit a hash for an unsigned tag, or for a tag signed by an unknown or revoked key. PassreleaseVersion=<version>to pin a specific release. SetcheckDownload=1to additionally download the release archive into a throwaway Nix store and check that it is exactly the signed tree.
Optional: Specify the system of your node
This enables evaluating your node config on a machine that has a different system platform
than your node.
Examples: Deploying from macOS or deploying from an x86 desktop PC to an ARM node.
# Run this when your node has a 64-bit x86 CPU (e.g., an Intel or AMD CPU)
echo "x86_64-linux" > krops/system
# Run this when your node has a 64-bit ARM CPU
echo "aarch64-linux" > krops/system
Deploy with krops
-
Edit your SSH config
nano ~/.ssh/configand add the node with an entry similar to the following (make sure to fix
HostnameandIdentityFile):Host bitcoin-node # FIXME Hostname NODE_IP_ADDRESS_OR_HOST_NAME_HERE User root PubkeyAuthentication yes # FIXME IdentityFile ~/.ssh/id_... AddKeysToAgent yes -
Make sure you are in the deployment directory and edit
krops/deploy.nixnano krops/deploy.nixLocate the
FIXMEand set the target to the name of the SSH config entry created earlier, i.e.bitcoin-node.Note that any file imported by your
configuration.nixmust be copied to the target machine by krops. For example, if there is an import ofnetworking.nixyou must add it toextraSourcesinkrops/deploy.nixlike this:extraSources = { "hardware-configuration.nix".file = toString ../hardware-configuration.nix; "networking.nix".file = toString ../networking.nix; }; -
Optional: Disallow substitutes
If you prefer to build the system from source instead of copying binaries from the Nix cache, add the following line to
configuration.nix:nix.settings.substitute = false;If the build process fails for some reason when deploying with
krops-deploy(see later step), it may be difficult to find the cause due to the missing output. To see the build output, SSH into the target machine and runnixos-rebuild -I /var/src switch -
Copy
hardware-configuration.nixfrom your node to the deployment directory.scp root@bitcoin-node:/etc/nixos/hardware-configuration.nix . -
Adjust configuration by opening the
configuration.nixfile and enable/disable the modules you want by editing this file.nano configuration.nixPay attention to lines that are preceded by
FIXMEcomments. In particular:- Make sure to set your SSH pubkey. Otherwise, you lose remote access: root can only log in over SSH with a key.
- Uncomment the line
./hardware-configuration.nixby removing#.
-
Enter the deployment environment
nix-shell -
Deploy with krops in nix-shell
deployThis will now create a bitcoinix node on the target machine.
-
You can now access
bitcoin-nodevia SSHssh operator@bitcoin-nodeNote that you’re able to log in as the unprivileged
operatoruser because bitcoinix automatically authorizes the SSH key added toroot.
For security reasons, all normal system management tasks can and should be performed with the operator user. Logging in as root should be done as rarely as possible.
See also: