forked from reflex-frp/reflex-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
try-reflex
executable file
·67 lines (53 loc) · 2.9 KB
/
try-reflex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
set -eu
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
. "$DIR/common-setup.sh"
ROOT_PERMISSION_FIX_SUGGESTION="please use your operating system's \"repair permissions\" feature, if it has one, or manually remove write permissions for your user from the '/' directory."
if [ -e /homeless-shelter ] ; then
echo "It looks like your system has a directory or file at '/homeless-shelter'. This will cause the try-reflex build to fail, because the Nix package manager assumes that /homeless-shelter does not exist and cannot be created."
echo
echo "If you intentionally created /homeless-shelter, please submit an issue at $REPO/issues, and we will try to find a workaround for this situation. However, usually, this directory is created by accident when a Nix script is run by a user who has write permissions to the root directory."
echo
echo "If this is the case, please remove the /homeless-shelter directory, then ensure that your root directory is not writable by the current user. To do this, $ROOT_PERMISSION_FIX_SUGGESTION"
exit 1
elif mkdir /homeless-shelter 2>/dev/null ; then
rmdir /homeless-shelter
echo "It looks like your filesystem's root directory is writable by the current user. This will cause nix to fail building try-reflex, and may also indicate a security vulnerability. Note that you should not run try-reflex as root."
echo
echo "To fix this problem, $ROOT_PERMISSION_FIX_SUGGESTION"
exit 1
fi
echo "Entering the reflex sandbox..."
# TODO: Use a better check that actually checks for each platform's availability
if [ ! "$(nix-instantiate --eval -E '(import <nixpkgs> {}).stdenv.isDarwin')" = "true" ] ; then
SUGGESTION_GHC=$(cat <<EOF
To run a simple GUI as a native binary:
$ ghc -XOverloadedStrings -e 'import Reflex.Dom' -e 'mainWidget $ text \"Hello, world!\"'
Or to see a more complex native binary GUI example (based on the source at https://github.com/reflex-frp/reflex-todomvc/blob/master/src/Main.hs):
$ reflex-todomvc
EOF
)
else
SUGGESTION_GHC=""
fi
SUGGESTION_GHCJS=$(cat <<EOF2
To create a simple web GUI:
$ cat >hello.hs <<EOF
{-# LANGUAGE OverloadedStrings #-}
import Reflex.Dom
main = mainWidget $ text \"Hello, world!\"
EOF
$ ghcjs hello.hs
Then navigate your browser to file://$(pwd)/hello.jsexe/index.html
Or to see a more complex GUI example (based on the source at https://github.com/reflex-frp/reflex-todomvc/blob/master/src/Main.hs), navigate your browser to file://$(nix-build $NIXOPTS --no-out-link "$DIR" -A ghcjs.reflex-todomvc)/bin/reflex-todomvc.jsexe/index.html
EOF2
)
INFO=$(cat <<EOF
You are now in a shell with access to the Reflex functional reactive programming engine.
$SUGGESTION_GHC
$SUGGESTION_GHCJS
EOF
)
nix-build "$DIR/shell.nix" --drv-link "$DIR/gc-roots/shell.drv" $NIXOPTS --indirect --add-root "$DIR/gc-roots/shell.out" >/dev/null
terminate_logging
nix-shell "$DIR/gc-roots/shell.drv" $NIXOPTS --command "echo \"$INFO\" ; return" "$@"