Add support for ledger and trezor with bitcoin-core/HWI
This commit is contained in:
69
modules/hardware-wallets.nix
Normal file
69
modules/hardware-wallets.nix
Normal file
@@ -0,0 +1,69 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.hardware-wallets;
|
||||
dataDir = "/var/lib/hardware-wallets/";
|
||||
enabled = cfg.ledger || cfg.trezor;
|
||||
in {
|
||||
options.services.hardware-wallets = {
|
||||
ledger = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
If enabled, the ledger udev rules will be installed.
|
||||
'';
|
||||
};
|
||||
trezor = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
If enabled, the trezor udev rules will be installed.
|
||||
'';
|
||||
};
|
||||
group = mkOption {
|
||||
type = types.string;
|
||||
default = "hardware-wallets";
|
||||
description = ''
|
||||
Group the hardware wallet udev rules apply to.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkMerge [
|
||||
{
|
||||
# Create group
|
||||
users.groups."${cfg.group}" = {};
|
||||
}
|
||||
(mkIf cfg.ledger {
|
||||
# Ledger Nano S according to https://github.com/LedgerHQ/udev-rules/blob/master/add_udev_rules.sh
|
||||
# Don't use rules from nixpkgs because we want to use our own group.
|
||||
services.udev.packages = lib.singleton (pkgs.writeTextFile {
|
||||
name = "ledger-udev-rules";
|
||||
destination = "/etc/udev/rules.d/20-ledger.rules";
|
||||
text = ''
|
||||
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0001", MODE="0660", GROUP="${cfg.group}"
|
||||
'';
|
||||
});
|
||||
})
|
||||
(mkIf cfg.trezor {
|
||||
# Don't use rules from nixpkgs because we want to use our own group.
|
||||
services.udev.packages = lib.singleton (pkgs.writeTextFile {
|
||||
name = "trezord-udev-rules";
|
||||
destination = "/etc/udev/rules.d/52-trezor.rules";
|
||||
text = ''
|
||||
# TREZOR v1 (One)
|
||||
SUBSYSTEM=="usb", ATTR{idVendor}=="534c", ATTR{idProduct}=="0001", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess", SYMLINK+="trezor%n"
|
||||
KERNEL=="hidraw*", ATTRS{idVendor}=="534c", ATTRS{idProduct}=="0001", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess"
|
||||
|
||||
# TREZOR v2 (T)
|
||||
SUBSYSTEM=="usb", ATTR{idVendor}=="1209", ATTR{idProduct}=="53c0", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess", SYMLINK+="trezor%n"
|
||||
SUBSYSTEM=="usb", ATTR{idVendor}=="1209", ATTR{idProduct}=="53c1", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess", SYMLINK+="trezor%n"
|
||||
KERNEL=="hidraw*", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="53c1", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess"
|
||||
'';
|
||||
});
|
||||
services.trezord.enable = true;
|
||||
})
|
||||
];
|
||||
}
|
||||
@@ -27,6 +27,7 @@ in {
|
||||
./electrs.nix
|
||||
./onion-chef.nix
|
||||
./recurring-donations.nix
|
||||
./hardware-wallets.nix
|
||||
];
|
||||
|
||||
options.services.nix-bitcoin = {
|
||||
@@ -98,7 +99,9 @@ in {
|
||||
isNormalUser = true;
|
||||
extraGroups = [ config.services.bitcoind.group ]
|
||||
++ (if config.services.clightning.enable then [ "clightning" ] else [ ])
|
||||
++ (if config.services.liquidd.enable then [ config.services.liquidd.group ] else [ ]);
|
||||
++ (if config.services.liquidd.enable then [ config.services.liquidd.group ] else [ ])
|
||||
++ (if (config.services.hardware-wallets.ledger || config.services.hardware-wallets.trezor)
|
||||
then [ config.services.hardware-wallets.group ] else [ ]);
|
||||
};
|
||||
# Give operator access to onion hostnames
|
||||
services.onion-chef.enable = true;
|
||||
@@ -174,7 +177,15 @@ in {
|
||||
++ optionals config.services.nix-bitcoin-webindex.enable [nginx]
|
||||
++ optionals config.services.liquidd.enable [liquidd]
|
||||
++ optionals config.services.spark-wallet.enable [spark-wallet]
|
||||
++ optionals config.services.electrs.enable [electrs];
|
||||
++ optionals config.services.electrs.enable [electrs]
|
||||
++ optionals (config.services.hardware-wallets.ledger || config.services.hardware-wallets.trezor) [
|
||||
hwi
|
||||
# To allow debugging issues with lsusb:
|
||||
usbutils
|
||||
]
|
||||
++ optionals config.services.hardware-wallets.trezor [
|
||||
python35.pkgs.trezor
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user