-
Notifications
You must be signed in to change notification settings - Fork 164
/
try-reflex
executable file
·64 lines (49 loc) · 2.69 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
#!/usr/bin/env bash
set -euo pipefail
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
. "$DIR/scripts/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..."
# This must be built first, so that the ghcjs.reflex-todomvc built below is built in parallel with everything else
prebuild_try_reflex_shell
SUGGESTION_GHC=$(cat <<EOF
To run a simple app:
$ ghc -dynamic -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
)
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
)
terminate_logging
try_reflex_shell --command "echo \"$INFO\" ; return" "$@"