Skip to content

Commit 85338a0

Browse files
committed
Add Nix deployment support
nix-bitcoin is archived and no longer receives security fixes. Provide a maintained upstream path for reproducible builds and declarative NixOS deployment. The flake pins Nixpkgs and exports a package and NixOS module. The package builds the server and CLI, takes its version from Cargo, and installs shell completions. The module creates a service, user, configuration, state directory, and optional firewall ports for each named instance. The documentation covers local builds, deployment, secrets, and multiple instances. Generated with OpenAI Codex.
1 parent 1af5168 commit 85338a0

8 files changed

Lines changed: 649 additions & 0 deletions

File tree

.github/workflows/nix.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Nix Checks
2+
3+
on: [ push, pull_request ]
4+
5+
permissions:
6+
contents: read
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout source code
17+
uses: actions/checkout@v6
18+
- name: Install Nix
19+
uses: cachix/install-nix-action@v31
20+
- name: Check the flake
21+
run: nix flake check --print-build-logs

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ See [Getting Started](docs/getting-started.md) for a full walkthrough.
6464
| [API Guide](docs/api-guide.md) | gRPC transport, authentication, and endpoint reference |
6565
| [Tor](docs/tor.md) | Connecting to and receiving connections over Tor |
6666
| [Operations](docs/operations.md) | Production deployment, backups, and monitoring |
67+
| [Nix deployment](docs/nix.md) | Reproducible builds and a NixOS service module |
6768

6869
### API
6970

docs/nix.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Nix deployment
2+
3+
The flake builds `ldk-server` and `ldk-server-cli`. It also provides a NixOS
4+
module for the daemon.
5+
6+
## Run without installing
7+
8+
Build and run the server from this repository:
9+
10+
```bash
11+
nix run . -- /path/to/config.toml
12+
```
13+
14+
Run the command-line client:
15+
16+
```bash
17+
nix shell .#ldk-server -c ldk-server-cli --help
18+
```
19+
20+
## Deploy on NixOS
21+
22+
Add the flake to your system inputs:
23+
24+
```nix
25+
{
26+
inputs.ldk-server.url = "github:lightningdevkit/ldk-server";
27+
28+
outputs = { nixpkgs, ldk-server, ... }: {
29+
nixosConfigurations.my-host = nixpkgs.lib.nixosSystem {
30+
system = "x86_64-linux";
31+
modules = [
32+
ldk-server.nixosModules.default
33+
{
34+
services.ldk-server.instances = {
35+
mainnet = {
36+
enable = true;
37+
openFirewall = true;
38+
lightningPort = 9735;
39+
settings = {
40+
node = {
41+
network = "bitcoin";
42+
listening_addresses = [ "0.0.0.0:9735" ];
43+
grpc_service_address = "127.0.0.1:3536";
44+
};
45+
esplora.server_url = "https://mempool.space/api";
46+
log = {
47+
level = "Info";
48+
log_to_file = false;
49+
};
50+
};
51+
};
52+
53+
signet = {
54+
enable = true;
55+
lightningPort = 19735;
56+
grpcPort = 13536;
57+
settings = {
58+
node = {
59+
network = "signet";
60+
listening_addresses = [ "127.0.0.1:19735" ];
61+
grpc_service_address = "127.0.0.1:13536";
62+
};
63+
esplora.server_url = "https://mutinynet.com/api";
64+
};
65+
};
66+
};
67+
}
68+
];
69+
};
70+
};
71+
}
72+
```
73+
74+
By default, each instance gets a separate service, user, configuration, and
75+
data directory. For example, `mainnet` uses `ldk-server-mainnet.service` and
76+
stores data in `/var/lib/ldk-server/mainnet`.
77+
78+
Use different Lightning and gRPC addresses for each instance. The module sets
79+
each data path even if the TOML file contains a different storage path.
80+
81+
The example exposes the Lightning port but keeps the gRPC API on loopback.
82+
Before you expose gRPC, configure its certificate and client access as
83+
described in [Operations - TLS](operations.md#tls).
84+
85+
The `settings` option writes values to the Nix store. Do not put passwords or
86+
other secrets in this option. Use `environmentFiles` for secrets:
87+
88+
```nix
89+
services.ldk-server.instances.mainnet.environmentFiles = [
90+
"/run/secrets/ldk-server-mainnet"
91+
];
92+
```
93+
94+
The file can override supported settings with environment variables:
95+
96+
```text
97+
LDK_SERVER_BITCOIND_RPC_USER=rpc-user
98+
LDK_SERVER_BITCOIND_RPC_PASSWORD=rpc-password
99+
```
100+
101+
You can also set an instance's `configFile` to a complete TOML file. You
102+
cannot use `configFile` and `settings` on the same instance.
103+
104+
After deployment, inspect the service with this command:
105+
106+
```bash
107+
systemctl status ldk-server-mainnet
108+
```

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
description = "LDK Server";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
5+
6+
outputs =
7+
{ self, nixpkgs }:
8+
let
9+
supportedSystems = [
10+
"aarch64-darwin"
11+
"aarch64-linux"
12+
"x86_64-linux"
13+
];
14+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
15+
in
16+
{
17+
packages = forAllSystems (
18+
system:
19+
let
20+
pkgs = nixpkgs.legacyPackages.${system};
21+
in
22+
{
23+
default = self.packages.${system}.ldk-server;
24+
ldk-server = pkgs.callPackage ./nix/package.nix {
25+
gitHash = self.rev or self.dirtyRev or "unknown";
26+
};
27+
}
28+
);
29+
30+
checks = forAllSystems (
31+
system:
32+
let
33+
pkgs = nixpkgs.legacyPackages.${system};
34+
in
35+
{
36+
inherit (self.packages.${system}) ldk-server;
37+
}
38+
// nixpkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
39+
nixos-module = pkgs.testers.runNixOSTest (
40+
import ./nix/tests/module.nix {
41+
inherit pkgs;
42+
ldkServerModule = self.nixosModules.ldk-server;
43+
}
44+
);
45+
}
46+
);
47+
48+
nixosModules = {
49+
default = self.nixosModules.ldk-server;
50+
ldk-server =
51+
{ lib, pkgs, ... }:
52+
{
53+
imports = [ ./nix/module.nix ];
54+
services.ldk-server.package =
55+
lib.mkDefault
56+
self.packages.${pkgs.stdenv.hostPlatform.system}.ldk-server;
57+
};
58+
};
59+
60+
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-tree);
61+
};
62+
}

0 commit comments

Comments
 (0)