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

Prototype of Nix integration and solc picking #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions libexec/dapp/dapp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ export DAPP_SRC=${DAPP_SRC-src}
export DAPP_LIB=${DAPP_LIB-lib}
export DAPP_OUT=${DAPP_OUT-out}

function have() { command -v "$1" >/dev/null 2>&1 ; }

for dep in bc curl git node solc ethabi ethrun seth jshon; do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demanding ethrun here is stupid since Nix dapp doesn't use ethrun...

if ! have $dep; then missing+=($dep); fi
done

if [ ${#missing[@]} -gt 0 ]; then
echo >&2 "${0##*/}: missing dependencies"
echo >&2
cat <<-EOF
If you want to install missing dependencies by hand,
then answer no to the following and install the following:

${missing[@]}

But we recommend that you let Dapp manage its own tools,
and answer yes to the following.
EOF

exec "${0##*/}-nix-setup"
fi

version=$(solc --version)
if grep -q 0.4.9 <<<"$version"; then
echo >&2 "${0##*/}: error: solc 0.4.9 not supported"
Expand Down
39 changes: 39 additions & 0 deletions libexec/dapp/dapp---use
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -e

function usage() {
echo >&2 "Usage: dapp --use <spec> <subcommand>..."
echo >&2 "Example:"
echo >&2
echo >&2 " $ dapp --use solc:0.4.11 test"
echo >&2
exit 1
}

[[ "$#" > 0 ]] || usage

function have() { command -v "$1" >/dev/null 2>&1 ; }
if ! have nix-shell; then exec dapp nix-setup; fi

export NIX_PATH=dapphub=$HOME/.nix-defexpr/channels/dapphub:$NIX_PATH
BINARY_CACHE=$(cat ~/.nix-defexpr/channels/binary-caches/dapphub)

shopt -s extglob
case $1 in
solc:[0-9].+([0-9.]))
version=${1#solc:}
version=${version//./_}
override+=" solc = solc-versions.solc_$version;"
;;
*)
echo >&2 "${0##*/}: unrecognized package spec: $1"
exit 1
esac
shift

[[ "$#" > 0 ]] || usage

nix-shell \
--option binary-caches "$BINARY_CACHE" \
-p "with import <dapphub> {}; dapp.override {$override }" \
--run "dapp $*"
63 changes: 63 additions & 0 deletions libexec/dapp/dapp-nix-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
set -e

function verify() {
read -e -p "$1 [y/n] " answer
[[ $answer == y ]] || [[ $answer == yes ]]
}

if ! command -v nix-env >/dev/null 2>&1; then
echo >&2
cat >&2 <<"EOF"
Dapp uses the Nix package manager to manage external tools.

Nix is a very useful meta-tool. All of its tools will be
self-contained in the /nix directory in a robust way.

We can launch the automatic Nix installer that works on both Linux and
OS X.

If you want to educate yourself first, please visit the Nix website
and become convinced of its wholesome and beneficial nature.

https://nixos.org/nix

EOF
if verify "Install Nix?"; then
if ! command -v curl >/dev/null 2>&1; then
echo >&2
echo >&2 "Error: please first install curl."
exit 1
fi
if ! command -v bzcat >/dev/null 2>&1; then
echo >&2
echo >&2 "Error: please first install bzip2."
exit 1
fi

echo >&2
curl https://nixos.org/nix/install | bash

echo >&2 "${0##*/}: Congratulations -- Nix is installed."
if verify "Setup shell profile?"; then
( set +x
echo ". ~/.nix-profile/etc/profile.d/nix.sh" >> ~/.profile
)
fi

. ~/.nix-profile/etc/profile.d/nix.sh

echo >&2 "${0##*/}: Configuring the DappHub channel..."
nix-channel --add https://nix.dapphub.com/pkgs/dapphub
nix-channel --update

echo >&2 "${0##*/}: Installing dapp via Nix..."
nix-env -iA dapphub.dapp

echo >&2 "${0##*/}: Excellent! Log out or run the following:"
echo >&2
echo >&2 " source ~/.nix-profile/etc/profile.d/nix.sh"
echo >&2
echo >&2 "and you will be fully set up to develop dapps."
fi
fi