From 0b8304395bc790d555da23c802671d3abf93e6fe Mon Sep 17 00:00:00 2001 From: pleb Date: Sun, 15 Nov 2026 19:44:25 -0800 Subject: [PATCH] Remove presets Squirtle's settings from secure-node.nix and enable-tor.nix now live in nix-pleb's squirtle config. The other presets had no users. Co-Authored-By: Claude Opus 5.5 --- modules/presets/bitcoind-remote.nix | 27 --- modules/presets/enable-tor.nix | 36 ---- modules/presets/hardened-extended.nix | 141 --------------- modules/presets/hardened.nix | 15 -- modules/presets/secure-node.nix | 47 ----- modules/presets/wireguard.nix | 236 -------------------------- 6 files changed, 502 deletions(-) delete mode 100644 modules/presets/bitcoind-remote.nix delete mode 100644 modules/presets/enable-tor.nix delete mode 100644 modules/presets/hardened-extended.nix delete mode 100644 modules/presets/hardened.nix delete mode 100644 modules/presets/secure-node.nix delete mode 100644 modules/presets/wireguard.nix diff --git a/modules/presets/bitcoind-remote.nix b/modules/presets/bitcoind-remote.nix deleted file mode 100644 index 4ada69a..0000000 --- a/modules/presets/bitcoind-remote.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - cfg = config.services.bitcoind; - secretsDir = config.nix-bitcoin.secretsDir; -in { - services.bitcoind = { - # Make the local bitcoin-cli work with the remote node. - # Without this, bitcoin-cli would try to use the .cookie file in the local - # bitcoind data dir for authorization, which doesn't exist. - extraConfig = '' - rpcuser=${cfg.rpc.users.privileged.name} - ''; - }; - - systemd.services.bitcoind = { - preStart = lib.mkAfter '' - echo "rpcpassword=$(cat ${secretsDir}/bitcoin-rpcpassword-privileged)" >> '${cfg.dataDir}/bitcoin.conf' - ''; - postStart = lib.mkForce ""; - serviceConfig = { - Type = lib.mkForce "oneshot"; - ExecStart = lib.mkForce "${pkgs.coreutils}/bin/true"; - RemainAfterExit = true; - }; - }; -} diff --git a/modules/presets/enable-tor.nix b/modules/presets/enable-tor.nix deleted file mode 100644 index d81fcff..0000000 --- a/modules/presets/enable-tor.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ lib, config, ... }: -let - defaultTrue = lib.mkDefault true; - defaultEnableTorProxy = { - tor.proxy = defaultTrue; - tor.enforce = defaultTrue; - }; - defaultEnforceTor = { - tor.enforce = defaultTrue; - }; -in { - services.tor = { - enable = true; - client.enable = true; - }; - - services = { - # Use Tor as a proxy for outgoing connections - # and restrict all connections to Tor - # - bitcoind = defaultEnableTorProxy; - lnd = defaultEnableTorProxy; - mempool = defaultEnableTorProxy; - - # These services don't make outgoing connections - # but we restrict them to Tor just to be safe. - # - electrs = defaultEnforceTor; - }; - - # Add onion services for incoming connections - nix-bitcoin.onionServices = { - bitcoind.enable = defaultTrue; - electrs.enable = defaultTrue; - }; -} diff --git a/modules/presets/hardened-extended.nix b/modules/presets/hardened-extended.nix deleted file mode 100644 index e9093b6..0000000 --- a/modules/presets/hardened-extended.nix +++ /dev/null @@ -1,141 +0,0 @@ -# This preset adds additional hardening settings on top of the -# default ./hardened.nix preset. -# These settings trade even more functionality and performance for increased security. - -# This preset enables usbguard. Use `services.usbguard.rules` to whitelist -# select devices. -# -# See madaidan's Linux Hardening Guide for detailed explanations: -# https://madaidans-insecurities.github.io/guides/linux-hardening.html - -{ - imports = [ - # Build on standard hardened preset - ./hardened.nix - ]; - - boot.kernel.sysctl = { - # Prevent boot console kernel log information leaks - "kernel.printk" = "3 3 3 3"; - - # Restrict loading TTY line disciplines to the CAP_SYS_MODULE capability to - # prevent unprivileged attackers from loading vulnerable line disciplines with - # the TIOCSETD ioctl - "dev.tty.ldisc_autoload" = "0"; - - # The SysRq key exposes a lot of potentially dangerous debugging functionality - # to unprivileged users - "kernel.sysrq" = "4"; - - # Protect against time-wait assassination by dropping RST packets for sockets - # in the time-wait state - "net.ipv4.tcp_rfc1337" = "1"; - - # Disable accepting IPv6 router advertisements - "net.ipv6.conf.all.accept_ra" = "0"; - "net.ipv6.default.accept_ra" = "0"; - - # Disable TCP SACK. SACK is commonly exploited and unnecessary for many - # circumstances so it should be disabled if you don't require it - "net.ipv4.tcp_sack" = "0"; - "net.ipv4.tcp_dsack" = "0"; - - # Restrict usage of ptrace to only processes with the CAP_SYS_PTRACE - # capability - "kernel.yama.ptrace_scope" = "2"; - - # Prevent creating files in potentially attacker-controlled environments such - # as world-writable directories to make data spoofing attacks more difficult - "fs.protected_fifos" = "2"; - "fs.protected_regular" = "2"; - - # Avoid leaking system time with TCP timestamps - "net.ipv4.tcp_timestamps" = "0"; - - # Disable core dumps - "syskernel.core_pattern" = "|/bin/false"; - "fs.suid_dumpable" = "0"; - - # Only swap when absolutely necessary - "vm.swappiness" = "1"; - }; - - boot.kernelParams = [ - # Disable slab merging which significantly increases the difficulty of heap - # exploitation by preventing overwriting objects from merged caches and by - # making it harder to influence slab cache layout - "slab_nomerge" - - # Disable vsyscalls as they are obsolete and have been replaced with vDSO. - # vsyscalls are also at fixed addresses in memory, making them a potential - # target for ROP attacks - "vsyscall=none" - - # Disable debugfs which exposes a lot of sensitive information about the - # kernel - "debugfs=off" - - # Sometimes certain kernel exploits will cause what is known as an "oops". - # This parameter will cause the kernel to panic on such oopses, thereby - # preventing those exploits - "oops=panic" - - # Only allow kernel modules that have been signed with a valid key to be - # loaded, which increases security by making it much harder to load a - # malicious kernel module - "module.sig_enforce=1" - - # The kernel lockdown LSM can eliminate many methods that user space code - # could abuse to escalate to kernel privileges and extract sensitive - # information. This LSM is necessary to implement a clear security boundary - # between user space and the kernel - "lockdown=confidentiality" - - # These parameters prevent information leaks during boot and must be used - # in combination with the kernel.printk - "quiet" "loglevel=0" - ]; - - boot.blacklistedKernelModules = [ - # Obscure networking protocols - "dccp" - "sctp" - "rds" - "tipc" - "n-hdlc" - "x25" - "decnet" - "econet" - "af_802154" - "ipx" - "appletalk" - "psnap" - "p8023" - "p8022" - "can" - "atm" - # Various rare filesystems - "jffs2" - "hfsplus" - "squashfs" - "udf" - "cifs" - "nfs" - "nfsv3" - "nfsv4" - "gfs2" - # vivid driver is only useful for testing purposes and has been the cause - # of privilege escalation vulnerabilities - "vivid" - # Disable Bluetooth - "bluetooth" - "btusb" - # Disable webcam - "uvcvideo" - # Disable Thunderbolt and FireWire to prevent DMA attacks - "thunderbolt" - "firewire-core" - ]; - - services.usbguard.enable = true; -} diff --git a/modules/presets/hardened.nix b/modules/presets/hardened.nix deleted file mode 100644 index 123b0b9..0000000 --- a/modules/presets/hardened.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ modulesPath, ... }: { - imports = [ - # Source: - # https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/profiles/hardened.nix - (modulesPath + "/profiles/hardened.nix") - ]; - - ## Reset some options set by the hardened profile - - # Needed for sandboxed builds and services - security.allowUserNamespaces = true; - - # The "scudo" allocator is broken on NixOS >= 20.09 - environment.memoryAllocator.provider = "libc"; -} diff --git a/modules/presets/secure-node.nix b/modules/presets/secure-node.nix deleted file mode 100644 index 07ca605..0000000 --- a/modules/presets/secure-node.nix +++ /dev/null @@ -1,47 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; - -let - cfg = config.services; - nbLib = config.nix-bitcoin.lib; - operatorName = config.nix-bitcoin.operator.name; -in { - imports = [ - ../modules.nix - ./enable-tor.nix - ]; - - config = { - networking.firewall.enable = true; - - nix-bitcoin.security.dbusHideProcessInformation = true; - - # Use doas instead of sudo - security.doas.enable = true; - security.sudo.enable = false; - environment.shellAliases.sudo = "doas"; - - environment.systemPackages = with pkgs; [ - jq - ]; - - # Add a SSH onion service - services.tor.relay.onionServices.sshd = nbLib.mkOnionService { port = 22; }; - nix-bitcoin.onionAddresses.access.${operatorName} = [ "sshd" ]; - - services.bitcoind = { - enable = true; - listen = true; - dbCache = 1000; - }; - - nix-bitcoin.nodeinfo.enable = true; - - # operator - nix-bitcoin.operator.enable = true; - users.users.${operatorName} = { - openssh.authorizedKeys.keys = config.users.users.root.openssh.authorizedKeys.keys; - }; - }; -} diff --git a/modules/presets/wireguard.nix b/modules/presets/wireguard.nix deleted file mode 100644 index 47b7133..0000000 --- a/modules/presets/wireguard.nix +++ /dev/null @@ -1,236 +0,0 @@ -{ config, pkgs, lib, ... }: - -# Create a WireGuard server with a single peer. -# Private/public keys are created via the secrets system. -# Add helper binaries `nix-bitcoin-wg-connect` and optionally `lndconnect-wg`, -# `lnconnect-clnrest-wg`, `lndconnect-clightning-wg`. - -# See ../../docs/services.md ("Use Zeus (mobile lightning wallet) via WireGuard") -# for usage instructions. - -# This is a rather opinionated implementation that lacks the flexibility offered by -# other nix-bitcoin modules, so ship this as a `preset`. -# Some users will prefer to use `lndconnect` with their existing WireGuard or Tailscale setup. - -with lib; -let - options.nix-bitcoin.wireguard = { - subnet = mkOption { - type = types.str; - default = "10.10.0"; - description = "The /24 subnet of the wireguard network."; - }; - restrictPeer = mkOption { - type = types.bool; - default = true; - description = '' - Prevent the peer from connecting to any addresses except for the WireGuard server address. - ''; - }; - }; - - cfg = config.nix-bitcoin.wireguard; - wgSubnet = cfg.subnet; - inherit (config.networking.wireguard.interfaces) wg-nb; - inherit (config.services) - lnd - clightning - clightning-rest; - inherit (clightning.plugins) clnrest; - - lndconnect = lnd.enable && lnd.lndconnect.enable; - lnconnect-clnrest = clnrest.enable && clnrest.lnconnect.enable; - lndconnect-clightning = clightning-rest.enable && clightning-rest.lndconnect.enable; - - serverAddress = "${wgSubnet}.1"; - peerAddress = "${wgSubnet}.2"; - - secretsDir = config.nix-bitcoin.secretsDir; - - wgConnectUser = if config.nix-bitcoin.operator.enable - then config.nix-bitcoin.operator.name - else "root"; - - # A script that prints a QR code to connect a peer to the server. - # The QR code encodes a wg-quick config that can be imported by the wireguard - # mobile app. - wgConnect = pkgs.writers.writeBashBin "nix-bitcoin-wg-connect" '' - set -euo pipefail - text= - host= - for arg in "$@"; do - case $arg in - --text) - text=1 - ;; - *) - host=$arg - ;; - esac - done - - if [[ ! $host ]]; then - # Use lndconnect to fetch the external ip. - # This internally uses https://github.com/GlenDC/go-external-ip, which - # queries a set of external ip providers. - host=$( - ${getExe config.nix-bitcoin.pkgs.lndconnect} --url --nocert \ - --configfile=/dev/null --adminmacaroonpath=/dev/null \ - | sed -nE 's|.*?/(.*?):.*|\1|p' - ) - fi - - config="[Interface] - PrivateKey = $(cat ${secretsDir}/wg-peer-private-key) - Address = ${peerAddress}/24 - - [Peer] - PublicKey = $(cat ${secretsDir}/wg-server-public-key) - AllowedIPs = ${wgSubnet}.0/24 - Endpoint = $host:${toString wg-nb.listenPort} - PersistentKeepalive = 25 - " - - if [[ $text ]]; then - echo "$config" - else - echo "$config" | ${getExe pkgs.qrencode} -t UTF8 -o - - fi - ''; -in { - inherit options; - - config = { - assertions = [ - { - # Don't support `netns-isolation` for now to keep things simple - assertion = !(config.nix-bitcoin.netns-isolation.enable or false); - message = "`nix-bitcoin.wireguard` is not compatible with `netns-isolation`."; - } - ]; - - networking.wireguard.interfaces.wg-nb = { - ips = [ "${serverAddress}/24" ]; - listenPort = mkDefault 51820; - privateKeyFile = "${secretsDir}/wg-server-private-key"; - allowedIPsAsRoutes = false; - peers = [ - { - # To use the actual public key from the secrets file, use dummy pubkey - # `peer0` and replace it via `getPubkeyFromFile` (see further below) - # at peer service runtime. - publicKey = "peer0"; - allowedIPs = [ "${peerAddress}/32" ]; - } - ]; - }; - - systemd.services = { - wireguard-wg-nb = rec { - wants = [ "nix-bitcoin-secrets.target" ]; - after = wants; - }; - - # HACK: Modify start/stop scripts of the peer setup service to read - # the pubkey from a secrets file. - wireguard-wg-nb-peer-peer0 = let - getPubkeyFromFile = mkBefore '' - if [[ ! -v inPatchedSrc ]]; then - export inPatchedSrc=1 - publicKey=$(cat "${secretsDir}/wg-peer-public-key") - <"''${BASH_SOURCE[0]}" sed "s|\bpeer0\b|$publicKey|g" | ${pkgs.bash}/bin/bash -s - exit - fi - ''; - in { - script = getPubkeyFromFile; - postStop = getPubkeyFromFile; - }; - }; - - environment.systemPackages = [ - wgConnect - ] ++ (optional lndconnect - (pkgs.writers.writeBashBin "lndconnect-wg" '' - exec lndconnect --host "${serverAddress}" --nocert "$@" - '') - ) ++ (optional lnconnect-clnrest - (pkgs.writers.writeBashBin "lnconnect-clnrest-wg" '' - exec lnconnect-clnrest --host "${serverAddress}" --nocert "$@" - '') - ) ++ (optional lndconnect-clightning - (pkgs.writers.writeBashBin "lndconnect-clightning-wg" '' - exec lndconnect-clightning --host "${serverAddress}" --nocert "$@" - '') - ); - - networking.firewall = let - restrictPeerRule = "-s ${peerAddress} ! -d ${serverAddress} -j REJECT"; - in { - allowedUDPPorts = [ wg-nb.listenPort ]; - - extraCommands = - optionalString lndconnect '' - iptables -w -A nixos-fw -p tcp -s ${wgSubnet}.0/24 --dport ${toString lnd.restPort} -j nixos-fw-accept - '' - + optionalString lnconnect-clnrest '' - iptables -w -A nixos-fw -p tcp -s ${wgSubnet}.0/24 --dport ${toString clnrest.port} -j nixos-fw-accept - '' - + optionalString lndconnect-clightning '' - iptables -w -A nixos-fw -p tcp -s ${wgSubnet}.0/24 --dport ${toString clightning-rest.port} -j nixos-fw-accept - '' - + optionalString cfg.restrictPeer '' - iptables -w -A nixos-fw ${restrictPeerRule} - iptables -w -A FORWARD ${restrictPeerRule} - ''; - - extraStopCommands = - # Rules added to chain `nixos-fw` are automatically removed when restarting - # the NixOS firewall service. - mkIf cfg.restrictPeer '' - iptables -w -D FORWARD ${restrictPeerRule} || : - ''; - }; - - # Listen on all addresses, including `serverAddress`. - # This is safe because the listen ports are secured by the firewall. - services.lnd = mkIf lndconnect { - restAddress = "0.0.0.0"; - tor.enforce = false; - }; - - services.clightning.plugins.clnrest.address = mkIf lnconnect-clnrest "0.0.0.0"; - # clnrest runs inside `clightning.service` - services.clightning.tor.enforce = mkIf lnconnect-clnrest false; - - services.clightning-rest = mkIf lndconnect-clightning { - # clightning-rest always listens on "0.0.0.0" - tor.enforce = false; - }; - - nix-bitcoin.secrets = { - wg-server-private-key = {}; - wg-server-public-key = { user = wgConnectUser; group = "root"; }; - wg-peer-private-key = { user = wgConnectUser; group = "root"; }; - wg-peer-public-key = {}; - }; - - nix-bitcoin.generateSecretsCmds.wireguard = let - wg = "${pkgs.wireguard-tools}/bin/wg"; - in '' - makeWireguardKey() { - local name=$1 - local priv=wg-$name-private-key - local pub=wg-$name-public-key - if [[ ! -e $priv ]]; then - ${wg} genkey > $priv - fi - if [[ $priv -nt $pub ]]; then - ${wg} pubkey < $priv > $pub - fi - } - makeWireguardKey server - makeWireguardKey peer - ''; - }; -}