From 01dbfc69a51a2cad0b391300282a99c4cddf199b Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 11 Mar 2026 11:01:25 -0400 Subject: [PATCH] p2pool: init --- configuration.nix | 1 + flake.lock | 18 +++++++++++++++++ flake.nix | 8 ++++++++ service-configs.nix | 7 +++++++ services/monero.nix | 1 + services/p2pool.nix | 48 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+) create mode 100644 services/p2pool.nix diff --git a/configuration.nix b/configuration.nix index b744729..674ca57 100644 --- a/configuration.nix +++ b/configuration.nix @@ -52,6 +52,7 @@ ./services/livekit.nix ./services/monero.nix + ./services/p2pool.nix ./services/xmrig.nix # KEEP UNTIL 2028 diff --git a/flake.lock b/flake.lock index be196fa..ee14063 100644 --- a/flake.lock +++ b/flake.lock @@ -330,6 +330,23 @@ "type": "github" } }, + "nixpkgs-p2pool-module": { + "flake": false, + "locked": { + "lastModified": 1764744779, + "narHash": "sha256-15mhGU8HZq4e6U2WnIhQvJNuUmU5aIO0RHMjzv9gVZs=", + "owner": "JacoMalan1", + "repo": "nixpkgs", + "rev": "3784f8a0dc56806ffbc550701d3aa27436ebb3e5", + "type": "github" + }, + "original": { + "owner": "JacoMalan1", + "ref": "create-p2pool-service", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1764517877, @@ -381,6 +398,7 @@ "nix-minecraft": "nix-minecraft", "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs", + "nixpkgs-p2pool-module": "nixpkgs-p2pool-module", "senior_project-website": "senior_project-website", "srvos": "srvos", "trackerlist": "trackerlist", diff --git a/flake.nix b/flake.nix index 65817d5..5fb257a 100644 --- a/flake.nix +++ b/flake.nix @@ -73,6 +73,11 @@ url = "git+ssh://gitea@git.gardling.com/titaniumtown/arr-init"; inputs.nixpkgs.follows = "nixpkgs"; }; + + nixpkgs-p2pool-module = { + url = "github:JacoMalan1/nixpkgs/create-p2pool-service"; + flake = false; + }; }; outputs = @@ -89,6 +94,7 @@ deploy-rs, impermanence, arr-init, + nixpkgs-p2pool-module, ... }@inputs: let @@ -167,6 +173,8 @@ arr-init.nixosModules.default + (import "${nixpkgs-p2pool-module}/nixos/modules/services/networking/p2pool.nix") + home-manager.nixosModules.home-manager ( { diff --git a/service-configs.nix b/service-configs.nix index aa90032..f96d603 100644 --- a/service-configs.nix +++ b/service-configs.nix @@ -21,6 +21,7 @@ rec { livekit = 7880; # TCP soulseek_listen = 50300; # TCP monero = 18080; # TCP + p2pool_p2p = 37889; # TCP murmur = 64738; # TCP + UDP # private @@ -41,6 +42,8 @@ rec { bazarr = 6767; # TCP jellyseerr = 5055; # TCP monero_rpc = 18081; # TCP + monero_zmq = 18083; # TCP + p2pool_stratum = 3334; # TCP }; https = { @@ -96,6 +99,10 @@ rec { dataDir = services_dir + "/monero"; }; + p2pool = { + dataDir = services_dir + "/p2pool"; + }; + matrix = { dataDir = "/var/lib/continuwuity"; domain = "matrix.${https.domain}"; diff --git a/services/monero.nix b/services/monero.nix index 1e4d792..e7820ea 100644 --- a/services/monero.nix +++ b/services/monero.nix @@ -23,6 +23,7 @@ }; extraConfig = '' p2p-bind-port=${builtins.toString service_configs.ports.monero} + zmq-pub=tcp://127.0.0.1:${builtins.toString service_configs.ports.monero_zmq} db-sync-mode=fast:async:1000000000bytes public-node=1 confirm-external-bind=1 diff --git a/services/p2pool.nix b/services/p2pool.nix new file mode 100644 index 0000000..6609050 --- /dev/null +++ b/services/p2pool.nix @@ -0,0 +1,48 @@ +{ + config, + service_configs, + lib, + ... +}: +let + walletAddress = lib.strings.trim (builtins.readFile ../secrets/xmrig-wallet); +in +{ + imports = [ + (lib.serviceMountWithZpool "p2pool" service_configs.zpool_hdds [ + service_configs.p2pool.dataDir + ]) + (lib.serviceFilePerms "p2pool" [ + "Z ${service_configs.p2pool.dataDir} 0700 p2pool p2pool" + ]) + ]; + + services.p2pool = { + enable = true; + dataDir = service_configs.p2pool.dataDir; + walletAddress = walletAddress; + sidechain = "nano"; + host = "127.0.0.1"; + rpcPort = service_configs.ports.monero_rpc; + zmqPort = service_configs.ports.monero_zmq; + extraArgs = [ + "--stratum 0.0.0.0:${builtins.toString service_configs.ports.p2pool_stratum}" + ]; + }; + + # Ensure p2pool starts after monero is ready + systemd.services.p2pool = { + after = [ "monero.service" ]; + wants = [ "monero.service" ]; + }; + + # Stop p2pool on UPS battery to conserve power + services.apcupsd.hooks = lib.mkIf config.services.apcupsd.enable { + onbattery = "systemctl stop p2pool"; + offbattery = "systemctl start p2pool"; + }; + + networking.firewall.allowedTCPPorts = [ + service_configs.ports.p2pool_p2p + ]; +}