Browse Source

Nix support improvements

Quick Start for BTC:

    $ git clone https://github.com/mmgen/mmgen-wallet
    $ cd mmgen-wallet
    $ nix-shell --pure nix

Enable altcoins and additional packages:

    $ mkdir -p ~/.mmgen
    $ cp nix/user-packages.nix ~/.mmgen
    # ... edit ~/.mmgen/user-packages.nix as required ...
    $ nix-shell --pure nix

For NixOS installation and other information, see:

    nix/README
The MMGen Project 2 months ago
parent
commit
abbc9c843a

+ 1 - 1
MANIFEST.in

@@ -9,7 +9,7 @@ include mmgen/proto/eth/*/LICENSE
 include mmgen/data/*
 include mmgen/data/*
 
 
 include scripts/*
 include scripts/*
-include scripts/mmgen-wallet-nix/*
+include nix/*
 
 
 include test/*.py
 include test/*.py
 include test/*/*.py
 include test/*/*.py

+ 1 - 1
mmgen/data/release_date

@@ -1 +1 @@
-December 2024
+January 2025

+ 1 - 1
mmgen/data/version

@@ -1 +1 @@
-15.1.dev8
+15.1.dev9

+ 54 - 0
nix/README

@@ -0,0 +1,54 @@
+Nix configuration directory for the MMGen Wallet suite
+
+Only BTC and a bare minimum of packages are enabled by default.
+
+For altcoin and additional package support, copy the file ‘user-packages.nix’ to
+your MMGen datadir (~/.mmgen) and edit, uncommenting the relevant lines.  For an
+XMR-enabled setup, for example, you’d uncomment the system package ‘monero-cli’
+and Python packages ‘monero’, ‘pycryptodome’ and ‘pysocks’.
+
+From the mmgen-wallet repo root, you may build individual system packages in the
+MMGen Wallet environment as follows (we’ll use the curl package in this example):
+
+   $ nix-build nix --attr curl
+
+To build all configured packages in one go, run ‘nix-build nix’ without
+additional arguments.
+
+The last lines of nix-build’s output are store paths in ‘/nix/store/’, which
+you may optionally install into your default environment as follows:
+
+   $ nix-env --install <store path>
+
+Note that use of MMGen Wallet from the default environment is discouraged in
+favor of the custom shell environment, which we’ll now describe.
+
+From the mmgen-wallet repo root, execute:
+
+   $ nix-shell nix
+
+This will build any unbuilt configured packages and drop you to the custom shell
+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 from your native environment inaccessible within the
+shell, so you may need to add some additional tools to your environment such as
+a text editor.  For examples, refer to ‘user-packages.nix’
+
+NixOS:
+
+  To install the MMGen Wallet environment under NixOS, copy the contents of the ‘nix’
+  directory to ‘/etc/nixos/mmgen-project’ and add ‘./mmgen-project/nixos-packages.nix’
+  to your imports list in ‘configuration.nix’.  If altcoin support or additional
+  packages are required, edit ‘user-packages.nix’ in ‘/etc/nixos/mmgen-project’ as
+  described above for the copy of that file in the MMGen datadir.  Rebuild NixOS.
+  From the mmgen-wallet repo root, execute:
+
+      export PYTHONPATH=$(pwd)
+      export PATH=$(pwd)/cmds:$PATH
+
+  You can now test and use MMGen Wallet in your native shell environment.

+ 0 - 0
scripts/mmgen-wallet-nix/bitcoin-cash-node.nix → nix/bitcoin-cash-node.nix


+ 1 - 0
nix/default.nix

@@ -0,0 +1 @@
+import ./merged-packages.nix { add_pkgs_path = null; }

+ 0 - 0
scripts/mmgen-wallet-nix/go-ethereum.nix → nix/go-ethereum.nix


+ 0 - 0
scripts/mmgen-wallet-nix/litecoin.nix → nix/litecoin.nix


+ 30 - 0
nix/merged-packages.nix

@@ -0,0 +1,30 @@
+{ add_pkgs_path }:
+
+let
+    dfl_nixpkgs = import ./nixpkgs-24.05.nix {};
+    dfl_python = pkgs.python312;
+    null_pkgs = {
+        system-packages = {};
+        python-packages = {};
+    };
+    usr_pkgs_path = if builtins.pathExists ~/.mmgen/user-packages.nix then
+        ~/.mmgen/user-packages.nix else ./user-packages.nix;
+    usr_pkgs = import usr_pkgs_path { pkgs = dfl_nixpkgs; python = dfl_python; bdir = ./.; };
+    pkgs = if usr_pkgs?pkgs then usr_pkgs.pkgs else dfl_nixpkgs;
+    python = if usr_pkgs?pkgs then usr_pkgs.python else dfl_python;
+    wallet_pkgs = import ./packages.nix { pkgs = pkgs; python = python; };
+    add_pkgs = if add_pkgs_path == null then null_pkgs else
+        (import add_pkgs_path { pkgs = pkgs; python = python; });
+in
+
+wallet_pkgs.system-packages //
+add_pkgs.system-packages //
+usr_pkgs.system-packages //
+{
+    pyenv = python.withPackages (ps:
+        builtins.attrValues (
+            wallet_pkgs.python-packages //
+            add_pkgs.python-packages //
+            usr_pkgs.python-packages)
+    );
+}

+ 5 - 0
nix/nixos-packages.nix

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

+ 0 - 0
scripts/mmgen-wallet-nix/nixpkgs-24.05.nix → nix/nixpkgs-24.05.nix


+ 50 - 0
nix/packages.nix

@@ -0,0 +1,50 @@
+{ pkgs, python }:
+
+{
+    system-packages = with pkgs; {
+        bitcoind     = bitcoind;                        # Bitcoin Core daemon
+        vanitygen    = (callPackage ./vanitygen-plusplus.nix {}); # test suite
+        curl         = curl;
+        git          = git;
+        gcc          = gcc;
+        libtool      = libtool;
+        autoconf     = autoconf;
+        gmp          = gmp;
+        gmp4         = gmp4;
+        openssl      = openssl;
+        pcre         = pcre;
+        mpfr         = mpfr;
+        secp256k1    = secp256k1.overrideAttrs {
+            pname = "secp256k1-v0.6.0";
+            src = fetchGit {
+                url = "https://github.com/bitcoin-core/secp256k1.git";
+                ref = "refs/tags/v0.6.0";
+            };
+        };
+        less         = less;   # test suite (cmdtest.py regtest)
+        procps       = procps; # test suite (pgrep)
+        ruff         = ruff;
+
+        ## For test suite with --pure:
+        e2fsprogs  = e2fsprogs;
+        util-linux = util-linux; # losetup
+        ncurses    = ncurses;    # infocmp
+    };
+
+    python-packages = with python.pkgs; {
+        pip              = pip;
+        setuptools       = setuptools;
+        build            = build;
+        wheel            = wheel;
+        gmpy2            = gmpy2;
+        cryptography     = cryptography;
+        pynacl           = pynacl;
+        ecdsa            = ecdsa;
+        aiohttp          = aiohttp;
+        requests         = requests;
+        py-scrypt        = py-scrypt;
+        semantic-version = semantic-version;
+        pexpect          = pexpect;         # test suite
+        pycoin           = pycoin;          # test suite
+    };
+}

+ 8 - 4
scripts/mmgen-wallet-nix/shell.nix → nix/shell.nix

@@ -1,11 +1,13 @@
 # Nix shell environment for mmgen-wallet
 # Nix shell environment for mmgen-wallet
 
 
+{ add_pkgs_path ? null }:
+
 let
 let
     pkgs = import <nixpkgs> {};
     pkgs = import <nixpkgs> {};
 in
 in
 
 
 pkgs.mkShellNoCC {
 pkgs.mkShellNoCC {
-    packages = builtins.attrValues (import ./packages.nix);
+    packages = builtins.attrValues (import ./merged-packages.nix { add_pkgs_path = add_pkgs_path; });
     shellHook = ''
     shellHook = ''
         do_sudo_override() {
         do_sudo_override() {
             (
             (
@@ -20,14 +22,16 @@ pkgs.mkShellNoCC {
             )
             )
         }
         }
 
 
-        [ "$(python3 ./setup.py --name 2>/dev/null)" == "mmgen-wallet" ] || {
-            echo "Error: this script must be executed in the mmgen-wallet repository root"
+        read _ _ name <<<$(grep ^name setup.cfg)
+
+        [[ "$name" =~ ^mmgen-(wallet|node-tools)$ ]] || {
+            echo "Error: this script must be executed in the mmgen-wallet or mmgen-node-tools repository root"
             exit 1
             exit 1
         }
         }
 
 
         pwd=$(pwd)
         pwd=$(pwd)
         export PYTHONPATH=$pwd
         export PYTHONPATH=$pwd
-        export PATH=$pwd/cmds:$pwd/.bin-override:$PATH
+        export PATH=$pwd/cmds:$pwd/.bin-override:$HOME/.local/bin:$PATH
 
 
         [ "$UID" == 0 ] || do_sudo_override
         [ "$UID" == 0 ] || do_sudo_override
     '';
     '';

+ 48 - 0
nix/user-packages.nix

@@ -0,0 +1,48 @@
+# Nix environment user configuration for the MMGen Project
+#
+# In addition to setting new attributes, this file may be used to override the defaults
+# in nix/packages.nix of the mmgen-wallet repository
+
+{ pkgs, python, bdir }:
+
+rec {
+    ### Set nixpkgs globally for the MMGen environment.
+    ### If you set it, make sure to uncomment the python variable assignment below.
+    # pkgs = import (bdir + /nixpkgs-24.05.nix) {};
+
+    ### Set python version globally for the MMGen environment.
+    ### Must be set if pkgs is set.
+    # python = pkgs.python312;
+
+    system-packages = with pkgs; {
+        # monero-cli  = monero-cli;                      # Monero daemon
+        # # go-ethereum = go-ethereum;                     # Geth - latest version for transacting on mainnet
+        # go-ethereum = callPackage (bdir + /go-ethereum.nix) { # Geth - old version for test suite (ethdev)
+        #     buildGoModule = buildGo122Module;
+        #     tag_version = "v1.13.15";
+        #     vendor_hash = "sha256-LWNFuF66KudxrpWBBXjMbrWP5CwEuPE2h3kGfILIII0";
+        # };
+        # litecoin     = callPackage (bdir + /litecoin.nix) {};           # Litecoin daemon
+        # bitcoin-cash = callPackage (bdir + /bitcoin-cash-node.nix) {};  # Bitcoin Cash Node daemon
+        # zcash-mini   = callPackage (bdir + /zcash-mini.nix) {};         # ZEC (test suite)
+
+        ### For development with --pure (add/remove packages for your setup):
+        # neovim-qt    = neovim-qt;
+        # rxvt-unicode = rxvt-unicode;
+        # which        = which;
+        # ctags        = ctags;
+        # xclip        = xclip;
+
+        ### For test suite with --pure:
+        # openssh      = openssh; # XMR tests
+    };
+
+    python-packages = with python.pkgs; {
+        # pycryptodome     = pycryptodome;    # altcoins
+        # py-ecc           = py-ecc;          # ETH, ETC
+        # mypy-extensions  = mypy-extensions; # ETH, ETC
+        # pysocks          = pysocks;         # XMR
+        # monero           = monero;          # XMR (test suite)
+        # eth-keys         = eth-keys;        # ETH, ETC (test suite)
+    };
+}

+ 0 - 0
scripts/mmgen-wallet-nix/vanitygen-plusplus.nix → nix/vanitygen-plusplus.nix


+ 0 - 0
scripts/mmgen-wallet-nix/zcash-mini.nix → nix/zcash-mini.nix


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

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

+ 0 - 118
scripts/mmgen-wallet-nix/packages.nix

@@ -1,118 +0,0 @@
-# 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
-        # 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)
-    ruff         = pkgs.ruff;
-
-    ## 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
-}