shesek / spark-wallet

⚡️ A minimalistic wallet GUI for c-lightning, accessible over the web or through mobile and desktop apps.
MIT License
344 stars 77 forks source link

Running v0.2.8 with --onion crashes on NixOS #108

Open hkjn opened 5 years ago

hkjn commented 5 years ago

Using the Nix package of spark-wallet from https://github.com/fort-nix/nix-bitcoin causes a crash with v0.2.8 on NixOS (and possibly other distros), due to the app not having write permissions to a local directory where it tries to download Tor:

$ spark-wallet --no-rates -onion
Connected to c-lightning v0.7.1 with id 03a9c46ddacd373f78b6679f9dec6adb10b3dc78ca1602a685e09b2ce6101bc18c on network bitcoin at /home/user/.lightning/lightning-rpc
Loading login credentials from /home/user/.spark-wallet/cookie
Loaded TLS certificate with fingerprint 85:67:53:df:72:21:bf:32:5a:d5:a5:fe:18:6a:01:9f:1d:fe:37:06 from /home/user/.spark-wallet/tls

Tor Hidden Service enabled (via --onion) for the first time, downloading the Tor Bundle...
The Spark .onion server will start automatically when its ready.

In the meanwhile, you can access the local HTTP server directly.

uncaughtException, stopping process
Error: getaddrinfo ENOTFOUND true
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)

$ [..................] | rollbackFailedOptional: vernpm WARN checkPermissions Missing write access to 
/nix/store/xrpqwni739bs8c1qphal5593sc6vf7ca-node-spark-wallet-0.2.8/lib/node_modules/spark-wallet/dist/transport/granax-dep
npm ERR! path /nix/store/xrpqwni739bs8c1qphal5593sc6vf7ca-node-spark-wallet-0.2.8/lib/node_modules/spark-wallet/dist/transport/granax-dep
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/nix/store/xrpqwni739bs8c1qphal5593sc6vf7ca-node-spark-wallet-0.2.8/lib/node_modules/spark-wallet/dist/transport/granax-dep'
npm ERR!  { [Error: EACCES: permission denied, access '/nix/store/xrpqwni739bs8c1qphal5593sc6vf7ca-node-spark-wallet-0.2.8/lib/node_modules/spark-wallet/dist/transport/granax-dep']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/nix/store/xrpqwni739bs8c1qphal5593sc6vf7ca-node-spark-wallet-0.2.8/lib/node_modules/spark-wallet/dist/transport/granax-dep\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path:
npm ERR!    '/nix/store/xrpqwni739bs8c1qphal5593sc6vf7ca-node-spark-wallet-0.2.8/lib/node_modules/spark-wallet/dist/transport/granax-dep' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2019-08-24T11_24_52_679Z-debug.log

(Mangled output in original as well.)

On NixOS, install paths for packages are read-only, so any changes to disk would need to happen in a mutable data directory. In this case, optional dependencies like tor-browser-bundle-bin would be better listed as dependencies of the package rather than being downloaded dynamically by the application.

In my case, I in fact already have the tor as well as tor-browser-bundle-bin packages installed on my system, so ideally spark-wallet would detect that the binaries or libraries it needs are on $PATH and make use of them in this situation.

shesek commented 5 years ago

In this case, optional dependencies like tor-browser-bundle-bin would be better listed as dependencies of the package rather than being downloaded dynamically by the application.

The reason its downloaded dynamically is to avoid the extra 200MB+ for users who aren't going to be using onion...

Perhaps the NixOS packaging process could run npm install inside the src/transport/granax-dep directory to have the tor binaries as part of the package? (I'm not too familiar with NixOS, not sure how this works there)

binaries or libraries it needs are on $PATH and make use of them

Setting GRANAX_USE_SYSTEM_TOR=1 as an env variable (or --granax-use-system-tor 1 as an argument) should do the trick, but I haven't had the chance to try that. Can you try and report if that works?

hkjn commented 5 years ago

Perhaps the NixOS packaging process could run npm install inside the src/transport/granax-dep directory to have the tor binaries as part of the package? (I'm not too familiar with NixOS, not sure how this works there)

There should be a way to specify that tor package is a dependency for the spark-wallet package on Nix. (Or optionally that a separate spark-wallet-full package or similar provides Tor, if the weight of the dependency makes it desirable to offer a package without it as well).

I'm not super familiar with Nix yet either, but it looks like the nix-bitcoin project defines a list of node packages created by the node2nix tool, so perhaps the correct way to improve this is to modify the package definition over in nix-bitcoin:

I can continue looking at that and open an issue over in their repo if necessary, since they are the ones maintaining the Nix package for spark-wallet.

Setting GRANAX_USE_SYSTEM_TOR=1 as an env variable (or --granax-use-system-tor 1 as an argument) should do the trick, but I haven't had the chance to try that. Can you try and report if that works?

I tried both methods, but it still seems that spark-wallet is attempting to fetch Tor:

$ spark-wallet --granax-use-system-tor 1 --no-rates --onion
Connected to c-lightning v0.7.1 with id 03a9c46ddacd373f78b6679f9dec6adb10b3dc78ca1602a685e09b2ce6101bc18c on network bitcoin at /home/user/.lightning/lightning-rpc
Loading login credentials from /home/user/.spark-wallet/cookie

Tor Hidden Service enabled (via --onion) for the first time, downloading the Tor Bundle...
[...]
npm WARN checkPermissions Missing write access to /nix/store/xrpqwni739bs8c1qphal5593sc6vf7ca-node-spark-wallet-0.2.8/lib/node_modules/spark-wallet/dist/transport/granax-dep
npm ERR! path /nix/store/xrpqwni739bs8c1qphal5593sc6vf7ca-node-spark-wallet-0.2.8/lib/node_modules/spark-wallet/dist/transport/granax-dep
npm ERR! code EACCES
[...]

$ GRANAX_USE_SYSTEM_TOR=1 spark-wallet --no-rates --onion
Connected to c-lightning v0.7.1 with id 03a9c46ddacd373f78b6679f9dec6adb10b3dc78ca1602a685e09b2ce6101bc18c on network bitcoin at /home/user/.lightning/lightning-rpc
Loading login credentials from /home/user/.spark-wallet/cookie

Tor Hidden Service enabled (via --onion) for the first time, downloading the Tor Bundle...
[...]
npm WARN checkPermissions Missing write access to /nix/store/xrpqwni739bs8c1qphal5593sc6vf7ca-node-spark-wallet-0.2.8/lib/node_modules/spark-wallet/dist/transport/granax-dep
npm ERR! path /nix/store/xrpqwni739bs8c1qphal5593sc6vf7ca-node-spark-wallet-0.2.8/lib/node_modules/spark-wallet/dist/transport/granax-dep