examples: add importable-configuration.nix

This replaces minimal-configuration.nix.
importable-configuration.nix can be directly added to an existing
NixOS configuration. This makes it easy for users to get started quickly.
This commit is contained in:
Erik Arvstedt 2021-09-23 16:51:34 +02:00
parent 020d9486dd
commit d713e7b15c
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
6 changed files with 81 additions and 35 deletions

View File

@ -25,9 +25,9 @@ By default, [`configuration.nix`](configuration.nix) enables `bitcoind` and `cli
Requires: [Nix](https://nixos.org/nix/)
- [`./deploy-container-minimal.sh`](deploy-container-minimal.sh) creates a
container defined by [minimal-configuration.nix](minimal-configuration.nix) that
doesn't use the [secure-node.nix](../modules/presets/secure-node.nix) preset.
Also shows how to use nix-bitcoin in an existing NixOS config.\
container defined by [importable-configuration.nix](importable-configuration.nix).\
You can copy and import this file to use nix-bitcoin in an existing NixOS configuration.\
The configuration doesn't use the [secure-node.nix](../modules/presets/secure-node.nix) preset.\
Requires: [Nix](https://nixos.org/), a systemd-based Linux distro and root privileges
Run the examples with option `--interactive` or `-i` to start a shell for interacting with

View File

@ -1,3 +1,33 @@
#!/usr/bin/env bash
exec "${BASH_SOURCE[0]%/*}/deploy-container.sh" --minimal-config "$@"
if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then
echo "Running script in nix shell env..."
cd "${BASH_SOURCE[0]%/*}"
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
else
cd "$NIX_BITCOIN_EXAMPLES_DIR"
fi
tmpDir=$(mktemp -d /tmp/nix-bitcoin-minimal-container.XXX)
trap "rm -rf $tmpDir" EXIT
# Modify importable-configuration.nix to use the local <nix-bitcoin>
# source instead of fetchTarball
<importable-configuration.nix sed '
s|nix-bitcoin = .*|nix-bitcoin = toString <nix-bitcoin>;|;
s|system.extraDependencies = .*||
' > $tmpDir/importable-configuration.nix
cat > $tmpDir/configuration.nix <<EOF
{
imports = [ $tmpDir/importable-configuration.nix ];
users.users.main = {
isNormalUser = true;
password = "a";
};
# When WAN is disabled, DNS bootstrapping slows down service startup by ~15 s
services.clightning.extraConfig = "disable-dns";
}
EOF
"${BASH_SOURCE[0]%/*}/deploy-container.sh" $tmpDir/configuration.nix "$@"

View File

@ -28,14 +28,14 @@ if [[ $EUID != 0 ]]; then
fi
interactive=
minimalConfig=
configuration=
for arg in "$@"; do
case $arg in
-i|--interactive)
interactive=1
;;
--minimal-config)
minimalConfig=1
*)
configuration=$arg
;;
esac
done
@ -61,9 +61,7 @@ echo "Node info:"
c nodeinfo
'
if [[ $minimalConfig ]]; then
configuration=minimal-configuration.nix
else
if [[ ! $configuration ]]; then
configuration=configuration.nix
demoCmds="${demoCmds}${nodeInfoCmd}"
fi
@ -84,7 +82,7 @@ read -d '' src <<EOF || true
extra.enableWAN = true;
config = { pkgs, config, lib, ... }: {
imports = [
<${configuration}>
$(realpath "$configuration")
];
nix-bitcoin.generateSecrets = true;
};

View File

@ -25,8 +25,12 @@
# "${nix-bitcoin}/modules/presets/secure-node.nix"
{
# Automatically generate all secrets required by services.
# The secrets are stored in /etc/nix-bitcoin-secrets
nix-bitcoin.generateSecrets = true;
# Enable services.
# See ../configuration.nix for all available features.
services.bitcoind.enable = true;
# When using nix-bitcoin as part of a larger NixOS configuration, set the following to enable

View File

@ -0,0 +1,38 @@
# You can directly copy and import this file to use nix-bitcoin
# in an existing NixOS configuration.
# Make sure to check and edit all lines marked by 'FIXME:'
# See ./flakes/flake.nix on how to include nix-bitcoin in a flake-based
# system configuration.
let
# FIXME:
# Overwrite `builtins.fetchTarball {}` with the output of
# command ../helper/fetch-release
nix-bitcoin = builtins.fetchTarball {};
in
{ config, pkgs, lib, ... }: {
imports = [
"${nix-bitcoin}/modules/modules.nix"
];
# Automatically generate all secrets required by services.
# The secrets are stored in /etc/nix-bitcoin-secrets
nix-bitcoin.generateSecrets = true;
# Enable some services.
# See ./configuration.nix for all available features.
services.bitcoind.enable = true;
services.clightning.enable = true;
# Enable interactive access to nix-bitcoin features (like bitcoin-cli) for
# your system's main user
nix-bitcoin.operator = {
enable = true;
# FIXME: Set this to your system's main user
name = "main";
};
# Prevent garbage collection of the nix-bitcoin source
system.extraDependencies = [ nix-bitcoin ];
}

View File

@ -1,24 +0,0 @@
{ config, pkgs, lib, ... }: {
imports = [
<nix-bitcoin/modules/modules.nix>
];
nix-bitcoin.generateSecrets = true;
services.bitcoind.enable = true;
services.clightning.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";
};
}