From abbc9c843ad2944bedebf6f250a090e4f46cad6e Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 3 Jan 2025 14:23:20 +0000 Subject: [PATCH] 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 --- MANIFEST.in | 2 +- mmgen/data/release_date | 2 +- mmgen/data/version | 2 +- nix/README | 54 ++++++++ .../bitcoin-cash-node.nix | 0 nix/default.nix | 1 + .../mmgen-wallet-nix => nix}/go-ethereum.nix | 0 .../mmgen-wallet-nix => nix}/litecoin.nix | 0 nix/merged-packages.nix | 30 +++++ nix/nixos-packages.nix | 5 + .../nixpkgs-24.05.nix | 0 nix/packages.nix | 50 ++++++++ {scripts/mmgen-wallet-nix => nix}/shell.nix | 12 +- nix/user-packages.nix | 48 +++++++ .../vanitygen-plusplus.nix | 0 .../mmgen-wallet-nix => nix}/zcash-mini.nix | 0 scripts/mmgen-wallet-nix/nixos-packages.nix | 5 - scripts/mmgen-wallet-nix/packages.nix | 118 ------------------ 18 files changed, 199 insertions(+), 130 deletions(-) create mode 100644 nix/README rename {scripts/mmgen-wallet-nix => nix}/bitcoin-cash-node.nix (100%) create mode 100644 nix/default.nix rename {scripts/mmgen-wallet-nix => nix}/go-ethereum.nix (100%) rename {scripts/mmgen-wallet-nix => nix}/litecoin.nix (100%) create mode 100644 nix/merged-packages.nix create mode 100644 nix/nixos-packages.nix rename {scripts/mmgen-wallet-nix => nix}/nixpkgs-24.05.nix (100%) create mode 100644 nix/packages.nix rename {scripts/mmgen-wallet-nix => nix}/shell.nix (66%) create mode 100644 nix/user-packages.nix rename {scripts/mmgen-wallet-nix => nix}/vanitygen-plusplus.nix (100%) rename {scripts/mmgen-wallet-nix => nix}/zcash-mini.nix (100%) delete mode 100644 scripts/mmgen-wallet-nix/nixos-packages.nix delete mode 100644 scripts/mmgen-wallet-nix/packages.nix diff --git a/MANIFEST.in b/MANIFEST.in index e8872929..ffb665c3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -9,7 +9,7 @@ include mmgen/proto/eth/*/LICENSE include mmgen/data/* include scripts/* -include scripts/mmgen-wallet-nix/* +include nix/* include test/*.py include test/*/*.py diff --git a/mmgen/data/release_date b/mmgen/data/release_date index 9eecad06..19033e3d 100644 --- a/mmgen/data/release_date +++ b/mmgen/data/release_date @@ -1 +1 @@ -December 2024 +January 2025 diff --git a/mmgen/data/version b/mmgen/data/version index 23f811ff..04b34c4a 100644 --- a/mmgen/data/version +++ b/mmgen/data/version @@ -1 +1 @@ -15.1.dev8 +15.1.dev9 diff --git a/nix/README b/nix/README new file mode 100644 index 00000000..4490e539 --- /dev/null +++ b/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 + +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. diff --git a/scripts/mmgen-wallet-nix/bitcoin-cash-node.nix b/nix/bitcoin-cash-node.nix similarity index 100% rename from scripts/mmgen-wallet-nix/bitcoin-cash-node.nix rename to nix/bitcoin-cash-node.nix diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 00000000..eb4511c8 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1 @@ +import ./merged-packages.nix { add_pkgs_path = null; } diff --git a/scripts/mmgen-wallet-nix/go-ethereum.nix b/nix/go-ethereum.nix similarity index 100% rename from scripts/mmgen-wallet-nix/go-ethereum.nix rename to nix/go-ethereum.nix diff --git a/scripts/mmgen-wallet-nix/litecoin.nix b/nix/litecoin.nix similarity index 100% rename from scripts/mmgen-wallet-nix/litecoin.nix rename to nix/litecoin.nix diff --git a/nix/merged-packages.nix b/nix/merged-packages.nix new file mode 100644 index 00000000..0af97d20 --- /dev/null +++ b/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) + ); +} diff --git a/nix/nixos-packages.nix b/nix/nixos-packages.nix new file mode 100644 index 00000000..9137cf66 --- /dev/null +++ b/nix/nixos-packages.nix @@ -0,0 +1,5 @@ +{ config, lib, pkgs, ... }: + +{ + environment.systemPackages = builtins.attrValues (import ./default.nix); +} diff --git a/scripts/mmgen-wallet-nix/nixpkgs-24.05.nix b/nix/nixpkgs-24.05.nix similarity index 100% rename from scripts/mmgen-wallet-nix/nixpkgs-24.05.nix rename to nix/nixpkgs-24.05.nix diff --git a/nix/packages.nix b/nix/packages.nix new file mode 100644 index 00000000..bd73bc90 --- /dev/null +++ b/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 + }; +} diff --git a/scripts/mmgen-wallet-nix/shell.nix b/nix/shell.nix similarity index 66% rename from scripts/mmgen-wallet-nix/shell.nix rename to nix/shell.nix index dfe9143b..d6e5b55a 100644 --- a/scripts/mmgen-wallet-nix/shell.nix +++ b/nix/shell.nix @@ -1,11 +1,13 @@ # Nix shell environment for mmgen-wallet +{ add_pkgs_path ? null }: + let pkgs = import {}; in pkgs.mkShellNoCC { - packages = builtins.attrValues (import ./packages.nix); + packages = builtins.attrValues (import ./merged-packages.nix { add_pkgs_path = add_pkgs_path; }); shellHook = '' 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 } pwd=$(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 ''; diff --git a/nix/user-packages.nix b/nix/user-packages.nix new file mode 100644 index 00000000..413579fb --- /dev/null +++ b/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) + }; +} diff --git a/scripts/mmgen-wallet-nix/vanitygen-plusplus.nix b/nix/vanitygen-plusplus.nix similarity index 100% rename from scripts/mmgen-wallet-nix/vanitygen-plusplus.nix rename to nix/vanitygen-plusplus.nix diff --git a/scripts/mmgen-wallet-nix/zcash-mini.nix b/nix/zcash-mini.nix similarity index 100% rename from scripts/mmgen-wallet-nix/zcash-mini.nix rename to nix/zcash-mini.nix diff --git a/scripts/mmgen-wallet-nix/nixos-packages.nix b/scripts/mmgen-wallet-nix/nixos-packages.nix deleted file mode 100644 index 9cc79544..00000000 --- a/scripts/mmgen-wallet-nix/nixos-packages.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - environment.systemPackages = builtins.attrValues (import ./packages.nix); -} diff --git a/scripts/mmgen-wallet-nix/packages.nix b/scripts/mmgen-wallet-nix/packages.nix deleted file mode 100644 index 130b0cdb..00000000 --- a/scripts/mmgen-wallet-nix/packages.nix +++ /dev/null @@ -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 -# -# 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 - # 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 -}