add flake support

This change is fully backwards compatible.

We continue to use the standard non-flake evaluation mode in our
examples and internal tooling until the flakes design has stabilized.

'clightning-plugins = pkgs.recurseIntoAttrs' in pkgs/default.nix is
needed by flake-utils.lib.flattenTree in flake.nix.
It transforms the packages in `clightning-plugins` to top-level packages
named like `clightning-plugins/summary`. (The flake attr `packages`
must be a non-nested attrset of derivations.)
This commit is contained in:
Erik Arvstedt 2021-08-16 10:42:07 +02:00
parent de77281cba
commit f7c2133250
No known key found for this signature in database
GPG key ID: 33312B944DD97846
7 changed files with 246 additions and 13 deletions

View file

@ -69,9 +69,17 @@ c systemctl status bitcoind
```
See [`run-tests.sh`](../test/run-tests.sh) for a complete documentation.
### Real-world example
Check the [server repo](https://github.com/fort-nix/nixbitcoin.org) for https://nixbitcoin.org
to see the configuration of a nix-bitcoin node that's used in production.
The commands in `shell.nix` allow you to locally run the node in a VM or container.
### Flakes
Flakes make it easy to include `nix-bitcoin` in an existing NixOS config.
The [flakes example](./flakes/flake.nix) shows how to use `nix-bitcoin` as an input to a system flake.
Run `nix run` or `nix run .#vm` from the nix-bitcoin root directory to start an example
nix-bitcoin node VM.
This command is defined by the nix-bitcoin flake (in [flake.nix](../flake.nix)).

49
examples/flakes/flake.nix Normal file
View file

@ -0,0 +1,49 @@
{
description = "A basic nix-bitcoin node";
inputs.nix-bitcoin.url = "github:fort-nix/nix-bitcoin";
outputs = { self, nix-bitcoin }: {
nixosConfigurations.mynode = nix-bitcoin.inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
## Note:
## If you use a custom nixpkgs version for evaluating your system,
## consider using `withLockedPkgs` instead of `withSystemPkgs` to use the exact
## pkgs versions for nix-bitcoin services that are tested by nix-bitcoin.
## The downsides are increased evaluation times and increased system
## closure size.
#
# nix-bitcoin.nixosModules.withLockedPkgs
nix-bitcoin.nixosModules.withSystemPkgs
## Optional:
## Import the secure-node preset, an opinionated config to enhance security
## and privacy.
#
# "${nix-bitcoin}/modules/presets/secure-node.nix"
{
nix-bitcoin.generateSecrets = true;
services.bitcoind.enable = true;
# When using nix-bitcoin as part of a larger NixOS configuration, set the following to enable
# interactive access to nix-bitcoin features (like bitcoin-cli) for your system's main user
nix-bitcoin.operator = {
enable = true;
name = "main"; # Set this to your system's main user
};
# The system's main unprivileged user. This setting is usually part of your
# existing NixOS configuration.
users.users.main = {
isNormalUser = true;
password = "a";
};
}
];
};
};
}