From 7e90f3dd8435f8a4ebc6b259869a22ce6e0bcfcd Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 9 Nov 2026 09:33:33 +0000 Subject: [PATCH] nix: add monero.nix --- nix/monero-use-system-libraries.patch | 11 +++ nix/monero.nix | 125 ++++++++++++++++++++++++++ nix/user-packages.nix | 2 +- 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 nix/monero-use-system-libraries.patch create mode 100644 nix/monero.nix diff --git a/nix/monero-use-system-libraries.patch b/nix/monero-use-system-libraries.patch new file mode 100644 index 00000000..48755ca7 --- /dev/null +++ b/nix/monero-use-system-libraries.patch @@ -0,0 +1,11 @@ +diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt +index 5bdd5d9b4..3af6c5f5a 100644 +--- a/external/CMakeLists.txt ++++ b/external/CMakeLists.txt +@@ -44,4 +44,5 @@ endif() + add_subdirectory(db_drivers) + add_subdirectory(easylogging++) + add_subdirectory(qrcodegen) +-add_subdirectory(randomx EXCLUDE_FROM_ALL) ++find_library(RANDOMX_LIBRARY randomx) ++find_package(RapidJSON) diff --git a/nix/monero.nix b/nix/monero.nix new file mode 100644 index 00000000..2bec30bd --- /dev/null +++ b/nix/monero.nix @@ -0,0 +1,125 @@ +{ + lib, + stdenv, + cmake, + pkg-config, + boost186, + libsodium, + openssl, + python3, + randomx, + rapidjson, + readline, + unbound, + zeromq, + + trezorSupport ? true, + hidapi, + libusb1, + protobuf_21, + udev, +}: + +let + # submodules; revs are taken from monero repo's `/external` + supercop = fetchGit { + url = "https://github.com/monero-project/supercop.git"; + # url = /path/to/repo/supercop.git; + rev = "e887b2fb4bfcfcc454b2005472ad1df6f2191f52"; + shallow = true; + }; + trezor-common = fetchGit { + url = "https://github.com/trezor/trezor-common.git"; + # url = /path/to/repo/trezor-common.git; + rev = "9b48064ca38bd6403b9db2727d955325429b0131"; + shallow = true; + }; +in + +stdenv.mkDerivation rec { + pname = "monero-cli"; + version = "0.18.5.4"; + + src = fetchGit { + url = "https://github.com/monero-project/monero.git"; + # url = /path/to/repo/monero.git; + ref = "refs/tags/v${version}"; + rev = "85f036ba7019cd36f08e8a38a27c37ea7b522618"; + shallow = true; + }; + + patches = [ + ./monero-use-system-libraries.patch + ]; + + postPatch = '' + # manually install submodules + rmdir external/{supercop,trezor-common} + ln -sf ${supercop} external/supercop + ln -sf ${trezor-common} external/trezor-common + # export patched source for monero-gui + cp -r . $source + ''; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + + buildInputs = [ + boost186 # uses boost/asio/io_service.hpp + libsodium + openssl + randomx + rapidjson + readline + unbound + zeromq + ] + ++ lib.optionals trezorSupport [ + python3 + hidapi + libusb1 + protobuf_21 + ] + ++ lib.optionals (trezorSupport && stdenv.hostPlatform.isLinux) [ udev ]; + + cmakeFlags = [ + # skip submodules init + "-DMANUAL_SUBMODULES=ON" + "-DBUILD_GUI_DEPS=OFF" + "-DReadline_ROOT_DIR=${readline.dev}" + "-Wno-dev" + ] + ++ lib.optional stdenv.hostPlatform.isDarwin "-DBoost_USE_MULTITHREADED=OFF" + ++ lib.optionals trezorSupport [ + "-DUSE_DEVICE_TREZOR=ON" + ]; + + outputs = [ + "out" + "source" + ]; + + meta = { + description = "Private, secure, untraceable currency"; + homepage = "https://getmonero.org/"; + license = lib.licenses.bsd3; + + platforms = with lib.platforms; linux; + + # macOS/ARM has a working `monerod` (at least), but `monero-wallet-cli` + # segfaults on start after entering the wallet password, when built in release mode. + # Building the same revision in debug mode to root-cause the above problem doesn't work + # because of https://github.com/monero-project/monero/issues/9486 + badPlatforms = [ "aarch64-darwin" ]; + + maintainers = with lib.maintainers; [ + pmw + rnhmjoj + ]; + mainProgram = "monero-wallet-cli"; + # internal build tool generate_translations_header is tricky to compile for the build platform + broken = !stdenv.buildPlatform.canExecute stdenv.hostPlatform; + }; +} diff --git a/nix/user-packages.nix b/nix/user-packages.nix index b8016e8a..a9ad0b45 100644 --- a/nix/user-packages.nix +++ b/nix/user-packages.nix @@ -15,7 +15,7 @@ rec { # python = pkgs.python313; system-packages = with pkgs; { - # monero-cli = monero-cli; # Monero daemon + # monero-cli = callPackage (bdir + /monero.nix) {}; # Monero daemon # go-ethereum = go-ethereum; # Geth # reth = callPackage (bdir + /reth.nix) {}; # Rust Ethereum daemon # solc = callPackage (bdir + /solc.nix) { old_pkgs=old_pkgs; }; # Solidity compiler