Skip to content

Commit a264a01

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 a264a01

6 files changed

Lines changed: 498 additions & 0 deletions

File tree

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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
grpcPort = 3536;
40+
settings = {
41+
node = {
42+
network = "bitcoin";
43+
listening_addresses = [ "0.0.0.0:9735" ];
44+
grpc_service_address = "0.0.0.0:3536";
45+
};
46+
esplora.server_url = "https://mempool.space/api";
47+
log = {
48+
level = "Info";
49+
log_to_file = false;
50+
};
51+
};
52+
};
53+
54+
signet = {
55+
enable = true;
56+
lightningPort = 19735;
57+
grpcPort = 13536;
58+
settings = {
59+
node = {
60+
network = "signet";
61+
listening_addresses = [ "127.0.0.1:19735" ];
62+
grpc_service_address = "127.0.0.1:13536";
63+
};
64+
esplora.server_url = "https://mutinynet.com/api";
65+
};
66+
};
67+
};
68+
}
69+
];
70+
};
71+
};
72+
}
73+
```
74+
75+
By default, each instance gets a separate service, user, configuration, and
76+
data directory. For example, `mainnet` uses `ldk-server-mainnet.service` and
77+
stores data in `/var/lib/ldk-server/mainnet`.
78+
79+
Use different Lightning and gRPC addresses for each instance. The module sets
80+
each data path even if the TOML file contains a different storage path.
81+
82+
The `settings` option writes values to the Nix store. Do not put passwords or
83+
other secrets in this option. Use `environmentFiles` for secrets:
84+
85+
```nix
86+
services.ldk-server.instances.mainnet.environmentFiles = [
87+
"/run/secrets/ldk-server-mainnet"
88+
];
89+
```
90+
91+
The file can override supported settings with environment variables:
92+
93+
```text
94+
LDK_SERVER_BITCOIND_RPC_USER=rpc-user
95+
LDK_SERVER_BITCOIND_RPC_PASSWORD=rpc-password
96+
```
97+
98+
You can also set an instance's `configFile` to a complete TOML file. You
99+
cannot use `configFile` and `settings` on the same instance.
100+
101+
After deployment, inspect the service with this command:
102+
103+
```bash
104+
systemctl status ldk-server-mainnet
105+
```

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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 (system: {
31+
inherit (self.packages.${system}) ldk-server;
32+
});
33+
34+
nixosModules = {
35+
default = self.nixosModules.ldk-server;
36+
ldk-server = import ./nix/module.nix;
37+
};
38+
39+
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-tree);
40+
};
41+
}

0 commit comments

Comments
 (0)