Browse Source

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.
The MMGen Project 2 months ago
parent
commit
d69fee71c1

+ 1 - 0
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

+ 1 - 1
mmgen/data/release_date

@@ -1 +1 @@
-October 2024
+December 2024

+ 1 - 1
mmgen/data/version

@@ -1 +1 @@
-15.1.dev7
+15.1.dev8

+ 48 - 0
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
+    '';
+}

+ 51 - 0
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";
+    };
+}

+ 44 - 0
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
+    '';
+}

+ 5 - 0
scripts/mmgen-wallet-nix/nixos-packages.nix

@@ -0,0 +1,5 @@
+{ config, lib, pkgs, ... }:
+
+{
+    environment.systemPackages = builtins.attrValues (import ./packages.nix);
+}

+ 7 - 0
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;
+    }
+)

+ 118 - 0
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 <package name>
+#
+# 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 <store path>
+#
+# 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
+}

+ 34 - 0
scripts/mmgen-wallet-nix/shell.nix

@@ -0,0 +1,34 @@
+# Nix shell environment for mmgen-wallet
+
+let
+    pkgs = import <nixpkgs> {};
+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
+    '';
+}

+ 15 - 0
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
+    '';
+}

+ 29 - 0
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;
+}