nix-bitcoin/modules/default.nix

49 lines
1.1 KiB
Nix
Raw Normal View History

2018-11-13 15:44:54 -08:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.bitcoin;
2018-11-13 16:33:34 -08:00
home = "/var/lib/bitcoin";
configFile = pkgs.writeText "bitcoin.conf" ''
listen=0
onlynet=onion
prune=1001
assumevalid=0000000000000000000726d186d6298b5054b9a5c49639752294b322a305d240
proxy=127.0.0.1:9050
'';
2018-11-13 15:44:54 -08:00
in {
options.services.bitcoin = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
If enabled, the bitcoin service will be installed.
'';
};
};
config = mkIf cfg.enable {
users.users.bitcoin =
{
2018-11-13 16:33:34 -08:00
description = "Bitcoind User";
2018-11-13 15:44:54 -08:00
createHome = true;
2018-11-13 16:33:34 -08:00
inherit home;
2018-11-13 15:44:54 -08:00
};
systemd.services.bitcoind =
{ description = "Run bitcoind";
path = [ pkgs.bitcoin ];
wantedBy = [ "multi-user.target" ];
2018-11-13 16:33:34 -08:00
preStart = ''
mkdir -p ${home}/.bitcoin
ln -sf ${configFile} ${home}/.bitcoin/bitcoin.conf
'';
2018-11-13 15:44:54 -08:00
serviceConfig =
2018-11-13 16:33:34 -08:00
{
ExecStart = "${pkgs.bitcoin}/bin/bitcoind";
2018-11-13 15:44:54 -08:00
User = "bitcoin";
};
};
};
}