Merge remote-tracking branch 'upstream-pull/5/head'

This commit is contained in:
Jonas Nick 2019-01-04 14:50:21 +00:00
commit 986ebc8f88
No known key found for this signature in database
GPG Key ID: 4861DBF262123605
5 changed files with 111 additions and 2 deletions

View File

@ -34,7 +34,7 @@ in {
dataDir = mkOption {
type = types.path;
default = "/var/lib/clightning";
description = "The data directory for bitcoind.";
description = "The data directory for clightning.";
};
};

60
modules/electrs.nix Normal file
View File

@ -0,0 +1,60 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.electrs;
in {
options.services.electrs = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
If enabled, the electrs service will be installed.
'';
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/electrs";
description = "The data directory for electrs.";
};
};
config = mkIf cfg.enable {
users.users.electrs = {
description = "electrs User";
group = "electrs";
extraGroups = [ "bitcoinrpc" "keys" ];
home = cfg.dataDir;
};
users.groups.electrs = {
name = "electrs";
};
systemd.services.electrs = {
description = "Run electrs";
wantedBy = [ "multi-user.target" ];
requires = [ "bitcoind.service" ];
after = [ "bitcoind.service" ];
# create shell script to start up electrs safely with password parameter
preStart = ''
mkdir -m 0770 -p ${cfg.dataDir}
chown 'electrs:electrs' ${cfg.dataDir}
echo "${pkgs.electrs}/bin/electrs -vvv --timestamp --db-dir ${cfg.dataDir} --daemon-dir /var/lib/bitcoind --cookie=${config.services.bitcoind.rpcuser}:$(cat /secrets/bitcoin-rpcpassword)" > /var/lib/electrs/startscript.sh
chown -R 'electrs:electrs' ${cfg.dataDir}
chmod u+x ${cfg.dataDir}/startscript.sh
'';
serviceConfig = {
PermissionsStartOnly = "true";
ExecStart = "${pkgs.bash}/bin/bash ${cfg.dataDir}/startscript.sh";
User = "electrs";
Restart = "on-failure";
RestartSec = "10s";
PrivateTmp = "true";
ProtectSystem = "full";
NoNewPrivileges = "true";
PrivateDevices = "true";
};
};
};
}

View File

@ -16,6 +16,7 @@ let
lightning-charge.package
nanopos.package
spark-wallet.package
electrs
nodejs-8_x
nginx
];
@ -38,6 +39,7 @@ in {
./nix-bitcoin-webindex.nix
./liquid.nix
./spark-wallet.nix
./electrs.nix
];
options.services.nix-bitcoin = {
@ -83,7 +85,7 @@ in {
addnode=ecoc5q34tmbq54wl.onion
discover=0
'';
services.bitcoind.prune = 2000;
services.bitcoind.prune = if (cfg.modules == "minimal") then 2000 else 0;
services.bitcoind.dbCache = 1000;
services.tor.hiddenServices.bitcoind = {
map = [{
@ -146,6 +148,7 @@ in {
services.nix-bitcoin-webindex.enable = cfg.modules == "all";
services.clightning.autolisten = cfg.modules == "all";
services.spark-wallet.enable = cfg.modules == "all";
services.electrs.enable = cfg.modules == "all";
services.tor.hiddenServices.spark-wallet = {
map = [{
port = 80; toPort = 9737;

View File

@ -12,6 +12,7 @@
lightning-charge = import pkgs/lightning-charge.nix { inherit pkgs; };
nanopos = import pkgs/nanopos.nix { inherit pkgs; };
spark-wallet = import pkgs/spark-wallet.nix { inherit pkgs; };
electrs = pkgs.callPackage (import pkgs/electrs.nix) { };
liquidd = pkgs.callPackage (import pkgs/liquidd.nix) { };
in {
disabledModules = [ "services/security/tor.nix" ];
@ -31,6 +32,7 @@ in {
inherit lightning-charge;
inherit nanopos;
inherit spark-wallet;
inherit electrs;
inherit liquidd;
};
}

44
pkgs/electrs.nix Normal file
View File

@ -0,0 +1,44 @@
let
PkgsSource = builtins.fetchGit { url = "https://github.com/nixos/nixpkgs-channels"; ref = "nixos-18.09"; };
defaultPkgs = import PkgsSource {overlays = [(import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz)) ]; };
defaultRust = defaultPkgs.latest.rustChannels.nightly.rust;
defaultCargo = defaultPkgs.latest.rustChannels.nightly.cargo;
defaultBuildRustPackage = defaultPkgs.callPackage (import "${PkgsSource}/pkgs/build-support/rust") {
rust = {
rustc = defaultRust;
cargo = defaultCargo;
};
};
in { pkgs ? defaultPkgs, rust ? defaultRust, buildRustPackage ? defaultBuildRustPackage }:
pkgs.lib.flip pkgs.callPackage { inherit buildRustPackage; } (
{ lib, buildRustPackage, fetchFromGitHub, llvmPackages, clang }:
let
version = "0.4.2";
in buildRustPackage {
name = "electrs-${version}";
src = fetchFromGitHub {
owner = "romanz";
repo = "electrs";
rev = "5f2d4289dcb98ef283725b3d12f8733a7b9e832b";
sha256 = "1lqhrcyd8hdaja5k01a2banvjcbxxcwvb2p7zh05984fpzzs02gr";
};
cargoSha256 = "0v0cc62mx728cqfyz3x1bfh2436yiw2hkv58672j2f45cafcgp2h";
LIBCLANG_PATH = "${llvmPackages.libclang}/lib";
buildInputs = [ clang ];
meta = with lib; {
description = "An efficient re-implementation of Electrum Server in Rust";
homepage = https://github.com/romanz/electrs;
maintainers = with maintainers; [ tailhook ];
platforms = platforms.all;
};
}
)