Merge branch 'lightning'

This commit is contained in:
Bryan Ramos 2025-07-05 20:08:55 -04:00
commit ec4753b737
Signed by: bryan
GPG key ID: 6ABDCD144D6643C8
7 changed files with 155 additions and 25 deletions

View file

@ -11,6 +11,10 @@
bitcoin = { bitcoin = {
enable = true; enable = true;
electrum.enable = true; electrum.enable = true;
clightning = {
enable = true;
rest.enable = true;
};
}; };
}; };
}; };

View file

@ -1,5 +1,9 @@
{ {
imports = [ imports = [
<<<<<<<< HEAD:src/system/machines/wsl/modules/home-manager/default.nix
./home.nix ./home.nix
========
./c-lightning-REST
>>>>>>>> lightning:src/system/modules/bitcoin/modules/clightning/plugins/default.nix
]; ];
} }

View file

@ -0,0 +1 @@
test

View file

@ -0,0 +1,92 @@
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.modules.system.bitcoin.clightning;
btc = config.modules.system.bitcoin;
clnConfig = pkgs.writeTextFile {
name = "lightning.conf";
text = builtins.readFile ./config/lightning.conf;
};
in
{ options.modules.system.bitcoin.clightning = { enable = mkEnableOption "Core Lightning Server"; };
imports = [ ./plugins ];
config = mkIf (cfg.enable && btc.enable) {
#nixpkgs.overlays = [
# (final: prev: {
# clightning = prev.electrs.overrideAttrs (old: rec {
# version = "24.08";
# src = pkgs.fetchFromGitHub {
# owner = "ElementsProject";
# repo = "lightning";
# rev = "82f4ad68e34a2428c556e63fc2632d48a914968c";
# hash = "sha256-MWU75e55Zt/P4aaIuMte7iRcrFGMw0P81b8VNHQBe2g";
# };
# cargoDeps = old.cargoDeps.overrideAttrs (lib.const {
# name = "lightning-vendor.tar.gz";
# inherit src;
# outputHash = "sha256-MWU75e55Zt/P4aaIuMte7iRcrFGMw0P81b8VNHQBe2g=";
# });
# });
# })
#];
environment.systemPackages = with pkgs; [
clightning
];
users = {
users = {
"clightning" = {
home = "/var/lib/clightning";
description = "Core Lightning system user";
isSystemUser = true;
group = "bitcoin";
createHome = true;
};
};
groups = {
"bitcoin" = {
members = mkAfter [
"clightning"
];
};
};
};
programs.bash.shellAliases = {
cln = "lightningd";
};
systemd.services.lightningd = {
description = "Core Lightning Daemon";
script = "${pkgs.clightning}/bin/lightningd";
scriptArgs = ''
--conf=${clnConfig}
'';
after = [
"bitcoind-btc.service"
];
serviceConfig = {
User = "clightning";
Group = "bitcoin";
Type = "simple";
KillMode = "process";
TimeoutSec = 60;
Restart = "always";
RestartSec = 60;
};
requisite = [
"bitcoind-btc.service"
"network.target"
];
};
};
}

View file

@ -0,0 +1,35 @@
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.modules.system.bitcoin.clightning.rest;
cln = config.modules.system.bitcoin.clightning;
in
{ options.modules.system.bitcoin.clightning.rest = { enable = mkEnableOption "C-Lightning REST API Server"; };
config = mkIf (cfg.enable && cln.enable) {
nixpkgs.overlays = [
(final: prev: {
clightning-REST = prev.buildNpmPackage rec {
pname = "c-lightning-rest";
version = "0.10.7";
src = prev.fetchFromGitHub {
owner = "Ride-The-Lightning";
repo = "c-lightning-REST";
rev = "v${version}";
hash = "sha256-Z3bLH/nqhO2IPE1N4TxYhEDh2wHR0nT801kztfYoj+s=";
};
npmDepsHash = "sha256-svt5hjhTriGhehxC36yGwrqcjax/9UqqVzxEhHnoM0M=";
dontNpmBuild = true;
meta = with lib; {
description = "REST APIs for Core Lightning written with node.js ";
homepage = "https://github.com/Ride-The-Lightning/c-lightning-REST";
license = licenses.mit;
};
};
})
];
};
}

View file

@ -3,8 +3,6 @@
with lib; with lib;
let let
cfg = config.modules.system.bitcoin.electrum; cfg = config.modules.system.bitcoin.electrum;
home = "/var/lib/electrs";
btc = config.modules.system.bitcoin; btc = config.modules.system.bitcoin;
electrsConfig = pkgs.writeTextFile { electrsConfig = pkgs.writeTextFile {
@ -15,27 +13,24 @@ let
in in
{ options.modules.system.bitcoin.electrum = { enable = mkEnableOption "Electrs Server"; }; { options.modules.system.bitcoin.electrum = { enable = mkEnableOption "Electrs Server"; };
config = mkIf (cfg.enable && btc.enable) { config = mkIf (cfg.enable && btc.enable) {
#TODO: Fix the failing overlay due to `cargoHash/cargoSha256` nixpkgs.overlays = [
#nixpkgs.overlays = [ (final: prev: {
# (final: prev: { electrs = prev.electrs.overrideAttrs (old: rec {
# electrs = prev.electrs.overrideAttrs (old: rec { version = "0.10.6";
# pname = "electrs"; src = pkgs.fetchFromGitHub {
# version = "0.10.8"; owner = "romanz";
# src = pkgs.fetchFromGitHub { repo = "electrs";
# owner = "romanz"; rev = "v${version}";
# repo = pname; hash = "sha256-yp9fKD7zH9Ne2+WQUupaxvUx39RWE8RdY4U6lHuDGSc=";
# rev = "v${version}"; };
# hash = "sha256-L26jzAn8vwnw9kFd6ciyYS/OLEFTbN8doNKy3P8qKRE="; cargoDeps = old.cargoDeps.overrideAttrs (lib.const {
# }; name = "electrs-vendor.tar.gz";
# #cargoDeps = old.cargoDeps.overrideAttrs (const { inherit src;
# # name = "electrs-${version}.tar.gz"; outputHash = "sha256-qQKAQHOAeYWQ5YVtx12hIAjNA7Aj1MW1m+WimlBWPv0=";
# # inherit src; });
# # sha256 = ""; });
# #}); })
# cargoHash = "sha256-lBRcq73ri0HR3duo6Z8PdSjnC8okqmG5yWeHxH/LmcU="; ];
# });
# })
#];
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
electrs electrs
@ -44,7 +39,7 @@ in
users = { users = {
users = { users = {
"electrs" = { "electrs" = {
inherit home; home = "/var/lib/electrs";
description = "Electrs system user"; description = "Electrs system user";
isSystemUser = true; isSystemUser = true;
group = "bitcoin"; group = "bitcoin";

View file

@ -8,7 +8,6 @@ let
builtins.pathExists path && builtins.pathExists path &&
builtins.readFileType path == "directory" && builtins.readFileType path == "directory" &&
builtins.baseNameOf path != "config"; builtins.baseNameOf path != "config";
isModule = file: file == "default.nix"; isModule = file: file == "default.nix";
isNix = file: builtins.match ".*\\.nix" file != null && file != "default.nix"; isNix = file: builtins.match ".*\\.nix" file != null && file != "default.nix";