Skip to content
This repository was archived by the owner on Jun 13, 2018. It is now read-only.

Commit 5eedeb0

Browse files
committed
Prototype of Nix integration and solc picking
This pretty much works fine! I can run dapp in a clean Ubuntu Docker, and it will commence installing Nix, setting up the DappHub Nix channel, and then reinstalling dapp via Nix. It's kind of weird though that you would first download the dapp source code and install it, and then it would immediately reinstall itself in a different place using Nix. So I'm not sure, maybe there should be a separate easy install script, instead of the check in the main dapp program.
1 parent 263ea39 commit 5eedeb0

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

libexec/dapp/dapp

+22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ export DAPP_SRC=${DAPP_SRC-src}
44
export DAPP_LIB=${DAPP_LIB-lib}
55
export DAPP_OUT=${DAPP_OUT-out}
66

7+
function have() { command -v "$1" >/dev/null 2>&1 ; }
8+
9+
for dep in bc curl git node solc ethabi ethrun seth jshon; do
10+
if ! have $dep; then missing+=($dep); fi
11+
done
12+
13+
if [ ${#missing[@]} -gt 0 ]; then
14+
echo >&2 "${0##*/}: missing dependencies"
15+
echo >&2
16+
cat <<-EOF
17+
If you want to install missing dependencies by hand,
18+
then answer no to the following and install the following:
19+
20+
${missing[@]}
21+
22+
But we recommend that you let Dapp manage its own tools,
23+
and answer yes to the following.
24+
EOF
25+
26+
exec "${0##*/}-nix-setup"
27+
fi
28+
729
version=$(solc --version)
830
if grep -q 0.4.9 <<<"$version"; then
931
echo >&2 "${0##*/}: error: solc 0.4.9 not supported"

libexec/dapp/dapp---use

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
function usage() {
5+
echo >&2 "Usage: dapp --use <spec> <subcommand>..."
6+
echo >&2 "Example:"
7+
echo >&2
8+
echo >&2 " $ dapp --use solc:0.4.11 test"
9+
echo >&2
10+
exit 1
11+
}
12+
13+
[[ "$#" > 0 ]] || usage
14+
15+
function have() { command -v "$1" >/dev/null 2>&1 ; }
16+
if ! have nix-shell; then exec dapp nix-setup; fi
17+
18+
export NIX_PATH=dapphub=$HOME/.nix-defexpr/channels/dapphub:$NIX_PATH
19+
BINARY_CACHE=$(cat ~/.nix-defexpr/channels/binary-caches/dapphub)
20+
21+
shopt -s extglob
22+
case $1 in
23+
solc:[0-9].+([0-9.]))
24+
version=${1#solc:}
25+
version=${version//./_}
26+
override+=" solc = solc-versions.solc_$version;"
27+
;;
28+
*)
29+
echo >&2 "${0##*/}: unrecognized package spec: $1"
30+
exit 1
31+
esac
32+
shift
33+
34+
[[ "$#" > 0 ]] || usage
35+
36+
nix-shell \
37+
--option binary-caches "$BINARY_CACHE" \
38+
-p "with import <dapphub> {}; dapp.override {$override }" \
39+
--run "dapp $*"

libexec/dapp/dapp-nix-setup

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
function verify() {
5+
read -e -p "$1 [y/n] " answer
6+
[[ $answer == y ]] || [[ $answer == yes ]]
7+
}
8+
9+
if ! command -v nix-env >/dev/null 2>&1; then
10+
echo >&2
11+
cat >&2 <<"EOF"
12+
Dapp uses the Nix package manager to manage external tools.
13+
14+
Nix is a very useful meta-tool. All of its tools will be
15+
self-contained in the /nix directory in a robust way.
16+
17+
We can launch the automatic Nix installer that works on both Linux and
18+
OS X.
19+
20+
If you want to educate yourself first, please visit the Nix website
21+
and become convinced of its wholesome and beneficial nature.
22+
23+
https://nixos.org/nix
24+
25+
EOF
26+
if verify "Install Nix?"; then
27+
if ! command -v curl >/dev/null 2>&1; then
28+
echo >&2
29+
echo >&2 "Error: please first install curl."
30+
exit 1
31+
fi
32+
if ! command -v curl >/dev/null 2>&1; then
33+
echo >&2
34+
echo >&2 "Error: please first install bzip2."
35+
exit 1
36+
fi
37+
38+
echo >&2
39+
curl https://nixos.org/nix/install | bash
40+
41+
echo >&2 "${0##*/}: Congratulations -- Nix is installed."
42+
if verify "Setup shell profile?"; then
43+
( set +x
44+
echo ". ~/.nix-profile/etc/profile.d/nix.sh" >> ~/.profile
45+
)
46+
fi
47+
48+
. ~/.nix-profile/etc/profile.d/nix.sh
49+
50+
echo >&2 "${0##*/}: Configuring the DappHub channel..."
51+
nix-channel --add https://nix.dapphub.com/pkgs/dapphub
52+
nix-channel --update
53+
54+
echo >&2 "${0##*/}: Installing dapp via Nix..."
55+
nix-env -iA dapphub.dapp
56+
57+
echo >&2 "${0##*/}: Excellent! Log out or run the following:"
58+
echo >&2
59+
echo >&2 " source ~/.nix-profile/etc/profile.d/nix.sh"
60+
echo >&2
61+
echo >&2 "and you will be fully set up to develop dapps."
62+
fi
63+
fi

0 commit comments

Comments
 (0)