From d69fee71c1d19ea5b2228f23e9945178ec71dc4a Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 30 Dec 2024 11:31:40 +0000 Subject: [PATCH] support Nix and NixOS Quick Start for BTC: $ git clone https://github.com/mmgen/mmgen-wallet $ cd mmgen-wallet $ nix-shell --pure scripts/mmgen-wallet-nix/shell.nix For altcoin support and additional installation options, see: scripts/mmgen-wallet-nix/packages.nix Tested on Linux/x86_64. On other platforms your mileage may vary. Note that Nix support is under development, and the installation process is subject to change. --- MANIFEST.in | 1 + mmgen/data/release_date | 2 +- mmgen/data/version | 2 +- .../mmgen-wallet-nix/bitcoin-cash-node.nix | 48 +++++++ scripts/mmgen-wallet-nix/go-ethereum.nix | 51 ++++++++ scripts/mmgen-wallet-nix/litecoin.nix | 44 +++++++ scripts/mmgen-wallet-nix/nixos-packages.nix | 5 + scripts/mmgen-wallet-nix/nixpkgs-24.05.nix | 7 ++ scripts/mmgen-wallet-nix/packages.nix | 118 ++++++++++++++++++ scripts/mmgen-wallet-nix/shell.nix | 34 +++++ .../mmgen-wallet-nix/vanitygen-plusplus.nix | 15 +++ scripts/mmgen-wallet-nix/zcash-mini.nix | 29 +++++ 12 files changed, 354 insertions(+), 2 deletions(-) create mode 100644 scripts/mmgen-wallet-nix/bitcoin-cash-node.nix create mode 100644 scripts/mmgen-wallet-nix/go-ethereum.nix create mode 100644 scripts/mmgen-wallet-nix/litecoin.nix create mode 100644 scripts/mmgen-wallet-nix/nixos-packages.nix create mode 100644 scripts/mmgen-wallet-nix/nixpkgs-24.05.nix create mode 100644 scripts/mmgen-wallet-nix/packages.nix create mode 100644 scripts/mmgen-wallet-nix/shell.nix create mode 100644 scripts/mmgen-wallet-nix/vanitygen-plusplus.nix create mode 100644 scripts/mmgen-wallet-nix/zcash-mini.nix diff --git a/MANIFEST.in b/MANIFEST.in index 04e41c4c..e8872929 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -9,6 +9,7 @@ include mmgen/proto/eth/*/LICENSE include mmgen/data/* include scripts/* +include scripts/mmgen-wallet-nix/* include test/*.py include test/*/*.py diff --git a/mmgen/data/release_date b/mmgen/data/release_date index 922a67b5..9eecad06 100644 --- a/mmgen/data/release_date +++ b/mmgen/data/release_date @@ -1 +1 @@ -October 2024 +December 2024 diff --git a/mmgen/data/version b/mmgen/data/version index f3f95d67..23f811ff 100644 --- a/mmgen/data/version +++ b/mmgen/data/version @@ -1 +1 @@ -15.1.dev7 +15.1.dev8 diff --git a/scripts/mmgen-wallet-nix/bitcoin-cash-node.nix b/scripts/mmgen-wallet-nix/bitcoin-cash-node.nix new file mode 100644 index 00000000..bb5789a2 --- /dev/null +++ b/scripts/mmgen-wallet-nix/bitcoin-cash-node.nix @@ -0,0 +1,48 @@ +{ pkgs }: + +pkgs.stdenv.mkDerivation rec { + pname = "bitcoin-cash-node"; + version = "v28.0.0"; + src = fetchGit { + url = "https://gitlab.com/bitcoin-cash-node/bitcoin-cash-node"; + ref = "refs/tags/${version}"; + }; + nativeBuildInputs = [ + pkgs.cmake + pkgs.ninja + pkgs.help2man + pkgs.python3 + ]; + buildInputs = [ + pkgs.boost + pkgs.libevent + pkgs.db + pkgs.gmp + pkgs.openssl + pkgs.miniupnpc + pkgs.libnatpmp + pkgs.zeromq + pkgs.zlib + ]; + cmakeFlags = [ + "-GNinja" + "-DBUILD_BITCOIN_QT=OFF" + "-DVERBOSE_CONFIGURE=ON" + ]; + doCheck = false; + postConfigure = '' + chmod ug+x config/run_native_cmake.sh + chmod ug+x src/secp256k1/build_native_gen_context.sh + sed -e 's@/usr/bin/env python3@${pkgs.python3}/bin/python3@' -i ../cmake/utils/gen-ninja-deps.py + sed -e 's@/usr/bin/env bash@${pkgs.bash}/bin/bash@' -i doc/man/gen-doc-man-footer.sh + sed -e 's@/usr/bin/env bash@${pkgs.bash}/bin/bash@' -i doc/man/gen-doc-man.sh + ''; + postInstall= '' + rm -f $out/bin/* + install -v --mode=755 src/bitcoind $out/bin/bitcoind-bchn + install -v --mode=755 src/bitcoin-cli $out/bin/bitcoin-cli-bchn + rm -f $out/share/man/man1/bitcoin-{tx,seeder}* + mv $out/share/man/man1/bitcoind.1 $out/share/man/man1/bitcoind-bchn.1 + mv $out/share/man/man1/bitcoin-cli.1 $out/share/man/man1/bitcoin-cli-bchn.1 + ''; +} diff --git a/scripts/mmgen-wallet-nix/go-ethereum.nix b/scripts/mmgen-wallet-nix/go-ethereum.nix new file mode 100644 index 00000000..95cdb236 --- /dev/null +++ b/scripts/mmgen-wallet-nix/go-ethereum.nix @@ -0,0 +1,51 @@ +## adapted from go-ethereum.nix in nixpkgs repository + +{ + pkgs, + lib, + stdenv, + buildGoModule, + # nixosTests, + tag_version, + vendor_hash, +}: + +buildGoModule { + pname = "go-ethereum"; + version = tag_version; + + src = fetchGit { + url = "https://github.com/ethereum/go-ethereum.git"; + ref = "refs/tags/${tag_version}"; + }; + + proxyVendor = false; + + vendorHash = vendor_hash; + + doCheck = false; + + subPackages = [ "cmd/geth" ]; + + ## Following upstream: https://github.com/ethereum/go-ethereum/blob/v1.11.6/build/ci.go#L218 + tags = [ "urfave_cli_no_docs" ]; + + ## Fix for usb-related segmentation faults on darwin + propagatedBuildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ + pkgs.libobjc + pkgs.IOKit + ]; + + # passthru.tests = { inherit (nixosTests) geth; }; + + meta = with lib; { + homepage = "https://geth.ethereum.org/"; + description = "Official golang implementation of the Ethereum protocol"; + license = with licenses; [ + lgpl3Plus + gpl3Plus + ]; + maintainers = with maintainers; [ RaghavSood ]; + mainProgram = "geth"; + }; +} diff --git a/scripts/mmgen-wallet-nix/litecoin.nix b/scripts/mmgen-wallet-nix/litecoin.nix new file mode 100644 index 00000000..05bab04f --- /dev/null +++ b/scripts/mmgen-wallet-nix/litecoin.nix @@ -0,0 +1,44 @@ +{ pkgs }: + +pkgs.stdenv.mkDerivation rec { + pname = "litecoin"; + version = "v0.21.4"; + src = fetchGit { + url = "https://github.com/litecoin-project/litecoin.git"; + ref = "refs/tags/${version}"; + }; + nativeBuildInputs = [ + pkgs.autoconf + pkgs.automake + pkgs.libtool + pkgs.pkg-config + # pkgs.hexdump # for tests + ]; + buildInputs = [ + pkgs.boost + pkgs.libevent + pkgs.fmt + pkgs.db4 + pkgs.openssl + pkgs.sqlite + ]; + preConfigure = [ + "./autogen.sh" + ]; + configureFlags = [ + "--without-gui" + "--with-sqlite" + "--disable-bench" + "--disable-tests" + "--with-boost-libdir=${pkgs.boost.out}/lib" + ]; + buildFlags = [ + "src/litecoind" + "src/litecoin-cli" + ]; + enableParallelBuilding = true; + installPhase = '' + mkdir -p $out/bin + install -D --mode=755 src/litecoind src/litecoin-cli $out/bin + ''; +} diff --git a/scripts/mmgen-wallet-nix/nixos-packages.nix b/scripts/mmgen-wallet-nix/nixos-packages.nix new file mode 100644 index 00000000..9cc79544 --- /dev/null +++ b/scripts/mmgen-wallet-nix/nixos-packages.nix @@ -0,0 +1,5 @@ +{ config, lib, pkgs, ... }: + +{ + environment.systemPackages = builtins.attrValues (import ./packages.nix); +} diff --git a/scripts/mmgen-wallet-nix/nixpkgs-24.05.nix b/scripts/mmgen-wallet-nix/nixpkgs-24.05.nix new file mode 100644 index 00000000..12ebf949 --- /dev/null +++ b/scripts/mmgen-wallet-nix/nixpkgs-24.05.nix @@ -0,0 +1,7 @@ +import ( + fetchGit { + url = "https://github.com/NixOS/nixpkgs.git"; + rev = "63dacb46bf939521bdc93981b4cbb7ecb58427a0"; # refs/tags/24.05 + shallow = true; + } +) diff --git a/scripts/mmgen-wallet-nix/packages.nix b/scripts/mmgen-wallet-nix/packages.nix new file mode 100644 index 00000000..437d43e7 --- /dev/null +++ b/scripts/mmgen-wallet-nix/packages.nix @@ -0,0 +1,118 @@ +# mmgen-wallet-nix: Nix packages directory for mmgen-wallet +# +# Copy the ‘mmgen-wallet-nix’ directory and its files to a location outside the +# mmgen-wallet repo and edit the file ‘packages.nix’, which contains all the +# system and Python packages MMGen Wallet depends on. By default, altcoin +# packages are commented out. To enable the coins you need, uncomment the +# relevant lines. For an XMR-enabled setup, for example, you’ll need the +# system package ‘monero-cli’ and Python packages ‘monero’, ‘pycryptodome’ +# and ‘pysocks’. +# +# Individual system packages are built as follows: +# +# $ nix-build /path/to/mmgen-wallet-nix/packages.nix --attr +# +# The last line of nix-build’s output is a store path in ‘/nix/store/’, which +# you may optionally install into your default environment as follows: +# +# $ nix-env --install +# +# To build all configured packages in one go, run nix-build without ‘--attr’ and +# package name. +# +# The file ‘shell.nix’ contains a shell environment specially created for use +# with MMGen Wallet. From the mmgen-wallet repo root, execute: +# +# $ nix-shell /path/to/mmgen-wallet-nix/shell.nix +# +# This will build any unbuilt configured packages and drop you to the custom +# environment. At this point you may run the test suite: +# +# [nix-shell:... $] test/test-release -FA +# +# or proceed to use MMGen Wallet as with any conventional installation. +# +# For greater isolation, you can invoke nix-shell with the ‘--pure’ option. This +# will make executables in your native environment inaccessible within the +# shell, so you may need to install some additional tools, such as a text +# editor. See the related comments below. +# +# NixOS: +# +# To install mmgen-wallet under NixOS, copy the ‘mmgen-wallet-nix’ directory +# to ‘/etc/nixos’, edit ‘packages.nix’ to suit and add +# ‘mmgen-wallet-nix/nixos-packages.nix’ to your imports list in +# ‘configuration.nix’. From the mmgen-wallet repo root, execute: +# +# export PYTHONPATH=$(pwd) +# export PATH=$(pwd)/cmds:$PATH +# +# You can now use MMGen Wallet in your native shell environment. + +let + pkgs = import ./nixpkgs-24.05.nix {}; + pythonEnv = pkgs.python312.withPackages (ps: with ps; [ + pip + setuptools + build + wheel + gmpy2 + cryptography + pynacl + ecdsa + aiohttp + requests + py-scrypt + semantic-version + # pycryptodome # altcoins + # py-ecc # ETH, ETC + # mypy-extensions # ETH, ETC + # pysocks # XMR + pexpect # test suite + pycoin # test suite + pylint # test suite (requires ==3.1.1) + # monero # XMR (test suite) + # eth-keys # ETH, ETC (test suite) + ]); +in + +{ + pymods = pythonEnv; + bitcoind = pkgs.bitcoind; # Bitcoin Core daemon + # monero-cli = pkgs.monero-cli; # Monero daemon + # go-ethereum = pkgs.go-ethereum; # Geth - latest version for mainnet transacting + # go-ethereum = (pkgs.callPackage ./go-ethereum.nix { # Geth - old version for test suite (ethdev) + # buildGoModule = pkgs.buildGo122Module; + # tag_version = "v1.13.15"; + # vendor_hash = "sha256-LWNFuF66KudxrpWBBXjMbrWP5CwEuPE2h3kGfILIII0"; + # }); + # litecoin = (pkgs.callPackage ./litecoin.nix {}); # Litecoin daemon + # bitcoin-cash = (pkgs.callPackage ./bitcoin-cash-node.nix {}); # Bitcoin Cash Node daemon + # zcash-mini = (pkgs.callPackage ./zcash-mini.nix {}); # ZEC (test suite) + vanitygen = (pkgs.callPackage ./vanitygen-plusplus.nix {}); # test suite + curl = pkgs.curl; + git = pkgs.git; + gcc = pkgs.gcc; + libtool = pkgs.libtool; + autoconf = pkgs.autoconf; + gmp = pkgs.gmp; + gmp4 = pkgs.gmp4; + openssl = pkgs.openssl; + pcre = pkgs.pcre; + mpfr = pkgs.mpfr; + secp256k1 = pkgs.secp256k1; + less = pkgs.less; # test suite (cmdtest.py regtest) + procps = pkgs.procps; # test suite (pgrep) + + ## For development with --pure (add/remove packages for your setup): + neovim-qt = pkgs.neovim-qt; + rxvt-unicode = pkgs.rxvt-unicode; + which = pkgs.which; + ctags = pkgs.ctags; + + ## For test suite with --pure: + openssh = pkgs.openssh; # XMR tests + e2fsprogs = pkgs.e2fsprogs; + util-linux = pkgs.util-linux; # losetup + ncurses = pkgs.ncurses; # infocmp +} diff --git a/scripts/mmgen-wallet-nix/shell.nix b/scripts/mmgen-wallet-nix/shell.nix new file mode 100644 index 00000000..dfe9143b --- /dev/null +++ b/scripts/mmgen-wallet-nix/shell.nix @@ -0,0 +1,34 @@ +# Nix shell environment for mmgen-wallet + +let + pkgs = import {}; +in + +pkgs.mkShellNoCC { + packages = builtins.attrValues (import ./packages.nix); + shellHook = '' + do_sudo_override() { + ( + rm -rf .bin-override + mkdir .bin-override + cd .bin-override + if [ -x /bin/sudo ]; then + ln -s /bin/sudo + elif [ -x /run/wrappers/bin/sudo ]; then + ln -s /run/wrappers/bin/sudo + fi + ) + } + + [ "$(python3 ./setup.py --name 2>/dev/null)" == "mmgen-wallet" ] || { + echo "Error: this script must be executed in the mmgen-wallet repository root" + exit 1 + } + + pwd=$(pwd) + export PYTHONPATH=$pwd + export PATH=$pwd/cmds:$pwd/.bin-override:$PATH + + [ "$UID" == 0 ] || do_sudo_override + ''; +} diff --git a/scripts/mmgen-wallet-nix/vanitygen-plusplus.nix b/scripts/mmgen-wallet-nix/vanitygen-plusplus.nix new file mode 100644 index 00000000..9805f3b5 --- /dev/null +++ b/scripts/mmgen-wallet-nix/vanitygen-plusplus.nix @@ -0,0 +1,15 @@ +{ pkgs }: + +pkgs.stdenv.mkDerivation { + pname = "vanitygen-plusplus"; + version = "e7858035"; + src = fetchGit { + url = "https://github.com/10gic/vanitygen-plusplus"; + rev = "e7858035d092f9b9d6468e2b812475faaf7c69c6"; + }; + buildInputs = [ pkgs.openssl pkgs.pcre ]; + installPhase = '' + mkdir -p $out/bin + install -sv --mode=755 vanitygen keyconv $out/bin + ''; +} diff --git a/scripts/mmgen-wallet-nix/zcash-mini.nix b/scripts/mmgen-wallet-nix/zcash-mini.nix new file mode 100644 index 00000000..dfad3d11 --- /dev/null +++ b/scripts/mmgen-wallet-nix/zcash-mini.nix @@ -0,0 +1,29 @@ +{ pkgs }: + +pkgs.stdenvNoCC.mkDerivation { + pname = "zcash-mini"; + version = "a2b35042"; + src = fetchGit { + url = "https://github.com/FiloSottile/zcash-mini"; + rev = "a2b35042ad3a3bc22b925ecfc45e768a376bd29a"; + }; + buildInputs = [ pkgs.go pkgs.binutils ]; + patchPhase = '' + sed -e "s@github.com/FiloSottile/@@" -i main.go + sed -e "s@github.com/FiloSottile/@@" -i zcash/address.go + sed -e "s@github.com/btcsuite@zcash-mini@" -i zcash/address.go + sed -e "s@golang.org/x@zcash-mini@" -i zcash/address.go + mv vendor/github.com/btcsuite/btcutil . + mv vendor/golang.org/x/crypto . + ''; + dontConfigure = true; + dontBuild = true; + installPhase = '' + export HOME=$TMPDIR + go mod init zcash-mini + go build -mod=mod + mkdir --parents $out/bin + install --strip --mode=755 zcash-mini $out/bin + ''; + dontFixup = true; +}