187ff884dbadd modules test (Erik Arvstedt)826245484emake secrets dir location configurable (Erik Arvstedt)b1e13e9415simplify secrets file format (Erik Arvstedt)314272a228lnd, nanopos: move user and group definitions to the bottom (Erik Arvstedt)766fa4f300travis: cache all build outputs with cachix (Erik Arvstedt)b0e759160dtravis: set NIX_PATH as early as possible (Erik Arvstedt)c51bbcf104travis: move comment (Erik Arvstedt)7092dce0c7travis: remove use of deprecated statements (Erik Arvstedt)190a92507ctravis: split up scripts into statements (Erik Arvstedt)10d6b04ac8support enabling clightning and lnd simultaneously (Erik Arvstedt)ad7a519284bitcoind: wait until RPC port is open (Erik Arvstedt)5536b64fb3lnd: wait until wallet is created (Erik Arvstedt)6f2a55d63clnd: wait until RPC port is open (Erik Arvstedt)1868bef462lnd: add option 'rpcPort' (Erik Arvstedt)120e3e8cfelnd postStart: suppress curl response output (Erik Arvstedt)3e86637327lnd postStart: poll for REST service availability (Erik Arvstedt)795c51dc01lnd postStart: make more idiomatic (Erik Arvstedt)6e58beae8alnd: use postStart option for script (Erik Arvstedt)86167c6e6dclightning: wait until the RPC socket appears (Erik Arvstedt)60c732a6a1onion-chef: set RemainAfterExit, fix tor dependency (Erik Arvstedt)2b9b3ba1c5systemPackages: improve readability with shorter service references (Erik Arvstedt)14ecb5511aliquid: add cli option (Erik Arvstedt)cd5ed39b9clnd: add cli option (Erik Arvstedt)1833b15888clightning: add cli option (Erik Arvstedt)b90bf6691badd generate-secrets.service (Erik Arvstedt)6447694214add generate-secrets pkg (Erik Arvstedt)e34093a8acgenerate_secrets.sh: add opensslConf option (Erik Arvstedt)9d14d5ba64generate_secrets.sh: write secrets to working directory (Erik Arvstedt)51fb054001generate_secrets.sh: extract makepw command (Erik Arvstedt)e3b47ce18aadd setup-secrets.service (Erik Arvstedt)437b268433extract make-secrets.nix (Erik Arvstedt)f9c29b9318simplify secret definitions (Erik Arvstedt)cd0fd6926bdon't copy secret files to store during nixops deployment (Erik Arvstedt)f0a36fe0c7add 'nix-bitcoin-services' option (Erik Arvstedt)7aaf30501cnix-bitcoin-services: simplify formatting (Erik Arvstedt)760da232e0add nix-bitcoin pkgs namespace (Erik Arvstedt)6def181dbcadd modules.nix (Erik Arvstedt)3b842e5fe7add nix-bitcoin-secrets.target (Erik Arvstedt)bbf2bbc04anetwork.nix: simplify import of main config (Erik Arvstedt)7e021a2629simplify overlay.nix (Erik Arvstedt)07dc3e04acmove bitcoinrpc group definition to bitcoind (Erik Arvstedt)d61b185c3asimplify user and group definitions (Erik Arvstedt) Pull request description: The nix-bitcoin modules consist of three fundamental components: 1. a set of bitcoin-related modules for general use. 2. an opinionated configuration of these modules (`nix-bitcoin.nix`), to be deployed on a dedicated machine. 3. machinery for nixops deployment. This PR removes dependencies that reach from top to bottom in the list. This means that 1. is now usable on its own and that 2. can be used without 3. Besides improving nix-bitcoin's general usefulness, this - simplifies testing. This PR includes a Travis-enabled modules test using the NixOS testing framework. - paves the way for krops deployment. - unlocks direct deployment in NixOS containers which allows for super fast experimentation. ### Details Here are the unnecessary inter-component dependencies and how they're resolved by the commits. I'm using the numbering from the list above. - `1. -> 3.` The modules (1.) use the nixops-specific (3.) `keys` group. Resolved by `add nix-bitcoin-secrets.target`. - `1. -> 3.` 1. requires nixops-specific key services. Resolved by `add nix-bitcoin-secrets.target`. - `1. -> 2.` bitcoind needs the bitcoinrpc group which is defined in `nix-bitcoin.nix` (2.). Resolved by `move bitcoinrpc group definition to bitcoind`. Further obstacles for standalone usage of 1.: - We can't easily import 1. as a standalone module set. Resolved by `add modules.nix`. - Users of 1. shouldn't be forced to import nix-bitcoin's packages as top-level items in the pkgs namespace. Resolved by `add nix-bitcoin pkgs namespace`. ### Non-nixops deployments Commit `add setup-secrets.service` simplifies non-nixops deployment methods like containers, NixOS VMs or krops. Secrets can now deployed as follows: 1. create local secrets. 2. transfer secrets to machine. 3. on the machine, `setup-secrets.service` creates extra secrets from `secrets.nix` and sets owner and permissions for all secrets. As krops integrates step 2. we now have all ingredients for automatic krops deployment. The service is complicated by the creation of secrets like `bitcoin-rpcpassword` that are composed of attrs from `secrets.nix` instead of being simply backed by a file like `lnd_key`. We could simplify this by creating all secret files locally. Running nix-bitcoin in NixOS containers gives you faster rebuild cycles when developing. [Here's](https://gist.github.com/5db4fa7dd3f1137920b58e39647116f6) an example. ### Test The last commits starting with `clightning: add cli option` are testing-related and mostly fix non-critical bugs that were exposed by the test. All `STABLE=1` builds from the Travis build matrix are implicit in the modules test. Should we remove these individual builds? Regarding commit `travis: cache all build outputs with cachix`: To replace my cache with a cache that's owned by you (maybe named `nix-bitcoin-ci`), run ``` nix-shell -p travis --run 'travis encrypt CACHIX_SIGNING_KEY=... -r fort-nix/nix-bitcoin' ``` where `...` is the value of `secretKey` in `~/.config/cachix/cachix.dhall`. Let me know the travis secret and I'll fixup the commit. ### Docs If you like the proposed changes, I'll add another PR with updates to the docs regarding the project layout, non-nixops deployment, and how to use nix-bitcoin within a larger NixOS config. ACKs for top commit: jonasnick: ACK187ff884dbTree-SHA512: f4be65215c592a4f41bb7fa991a6d8d7c463cf631b88bf53051ca57ba280e7a60b8b09d0d1521345d5b656f844daa2166fff5d00a3105077c9e263465eacfb0a
nix-bitcoin
Nix packages and nixos modules for easily installing Bitcoin nodes and higher layer protocols with an emphasis on security. This is a work in progress - don't expect it to be bug free or secure.
The default configuration sets up a Bitcoin Core node and c-lightning. The user can enable spark-wallet in configuration.nix to make c-lightning accessible with a smartphone using spark-wallet.
A simple webpage shows the lightning nodeid and links to nanopos letting the user receive donations.
It also includes elements-daemon.
Outbound peer-to-peer traffic is forced through Tor, and listening services are bound to onion addresses.
A demo installation is running at http://6tr4dg3f2oa7slotdjp4syvnzzcry2lqqlcvqkfxdavxo6jsuxwqpxad.onion. The following screen cast shows a fresh deployment of a nix-bitcoin node.
The goal is to make it easy to deploy a reasonably secure Bitcoin node with a usable wallet. It should allow managing bitcoin (the currency) effectively and providing public infrastructure. It should be a reproducible and extensible platform for applications building on Bitcoin.
Available modules
By default the configuration.nix provides:
- bitcoind with outbound connections through Tor and inbound connections through a hidden service. By default loaded with banlist of spy nodes.
- clightning with outbound connections through Tor, not listening
- includes "nodeinfo" script which prints basic info about the node
- adds non-root user "operator" which has access to bitcoin-cli and lightning-cli
In configuration.nix the user can enable:
- a clightning hidden service
- liquid
- lightning charge
- nanopos
- an index page using nginx to display node information and link to nanopos
- spark-wallet
- electrs
- recurring-donations, a module to repeatedly send lightning payments to recipients specified in the configuration.
- bitcoin-core-hwi.
- You no longer need extra software to connect your hardware wallet to Bitcoin Core. Use Bitcoin Core's own Hardware Wallet Interface with one
configuration.nixsetting.
- You no longer need extra software to connect your hardware wallet to Bitcoin Core. Use Bitcoin Core's own Hardware Wallet Interface with one
The data directories of the services can be found in /var/lib on the deployed machines.
Installation
The easiest way is to run nix-shell (on a Linux machine) in the nix-bitcoin directory and then create a NixOps deployment with the provided network.nix in the network directory.
Fix the FIXMEs in configuration.nix and deploy with nixops in nix-shell.
See install.md for a detailed tutorial.
Security
- Simplicity: Only services you select in
configuration.nixand their dependencies are installed, packages and dependencies are pinned, most packages are built from the nixos stable channel, with a few exceptions that are built from the nixpkgs unstable channel, builds happen in a sandboxed environment, code is continiously reviewed and refined. - Integrity: Nix package manager, NixOS and packages can be built from source to reduce reliance on binary caches, nix-bitcoin merge commits are signed, all commits are approved by multiple nix-bitcoin developers, upstream packages are cryptographically verified where possible, we use this software ourselves.
- Principle of Least Privilege: Services operate with least privileges; they each have their own user and are restricted further with systemd options, there's a non-root user operator to interact with the various services.
- Defense-in-depth: nix-bitcoin is built with a hardened kernel by default, services are confined through discretionary access control, Linux namespaces, and seccomp-bpf with continuous improvements.
Note that nix-bitcoin is still experimental. Also, by design if the machine you're deploying from is insecure, there is nothing nix-bitcoin can do to protect itself.
Hardware requirements
- Disk space: 300 GB (235GB for Bitcoin blockchain + some room)
- Bitcoin Core pruning is not supported at the moment because it's not supported by c-lightning. It's possible to use pruning but you need to know what you're doing.
- RAM: 2GB of memory. ECC memory is better. Additionally, it's recommended to use DDR4 memory with targeted row refresh (TRR) enabled (https://rambleed.com/).
Tested hardware includes pcengine's apu2c4, GB-BACE-3150, GB-BACE-3160. Some hardware (including Intel NUCs) may not be compatible with the hardened kernel turned on by default (see https://github.com/fort-nix/nix-bitcoin/issues/39#issuecomment-517366093 for a workaround).
Usage
For usage instructions, such as how to connect to spark-wallet, electrs and the ssh Tor Hidden Service, see usage.md.
Troubleshooting
If you are having problems with nix-bitcoin check the FAQ or submit an issue.
There's also a #nix-bitcoin IRC channel on freenode.
We are always happy to help.
