@@ -3,17 +3,16 @@
33[](http://www.haskell.org)
44[](https://tldrlegal.com/license/bsd-3-clause-license-%28revised%29)
55
6+<p align="center"><img src="docs/obelisk-logo-640.png" width="50%" alt="Obelisk Logo"></p>
67
7−Obelisk provides an easy way to develop and deploy your [Reflex](https://github.com/reflex-frp/reflex) project as web apps and as mobile apps.
8+Obelisk is an opinionated, batteries-included framework for building production-ready web and mobile applications in [Haskell](https://www.haskell.org/). Its goal is to represent a cohesive, highly-curated set of choices that [Obsidian Systems](https://obsidian.systems/) has made for building these types of applications in a way that is extremely fast but does not compromise on production readiness.
89
10+- [Overview](#installing-obelisk)
11+ - [Why would I use it?](#why-would-i-use-it)
12+ - [Who should consider using it?](#who-should-consider-using-it)
913- [Installing Obelisk](#installing-obelisk)
1014- [Developing an Obelisk project](#developing-an-obelisk-project)
11− - [Adding Packages](#adding-packages)
12− - [Adding Package Overrides](#adding-package-overrides)
13− - [Running over HTTPS](#running-over-https)
1415 - [IDE Support](#ide-support)
15− - [Terminal-based feedback](#terminal-based-feedback)
16− - [Experimental `ghcide` support](#experimental-ghcide-support)
1716- [Deploying](#deploying)
1817 - [Locally](#locally)
1918 - [Default EC2 Deployment](#default-ec2-deployment)
@@ -24,74 +23,52 @@ Obelisk provides an easy way to develop and deploy your [Reflex](https://github.
2423- [Mobile](#mobile)
2524 - [iOS](#ios)
2625 - [Android](#android)
26+- [Frequently Asked Questions (FAQ)](#frequently-asked-questions-faq)
27+- [Contributing](#contributing)
28+
29+## Overview
30+
31+Obelisk allows you to build high-quality web and mobile applications very quickly using [Reflex](https://reflex-frp.org/). In minutes you can go from an empty directory to an interactive application that works on web, iOS, and Android, all sharing the same Haskell codebase! Obelisk's development environment also enables extremely rapid development and feedback. You can take advantage of Haskell's type system across the frontend and backend boundary. This means changes to your backend that would break your frontend are immediately detected during development and vice versa. Obelisk uses Haskell's compiler to give you a complete "TODO list" of what needs to be updated.
32+
33+Obelisk is targeted primarily at Haskell developers who want to build high-quality web and/or mobile applications in Haskell, without the distractions of manually choosing and integrating technology for every piece of the system.
34+
35+### Who should consider using it?
36+
37+Obelisk assumes basic knowledge of [Haskell](https://www.haskell.org/) and [Reflex/Reflex-DOM](https://reflex-frp.org/), web technologies like [HTML](https://developer.mozilla.org/en-US/docs/Web/HTML) and [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS), and a terminal shell like [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)). Knowledge of [Nix](https://nixos.org/) helps but is not strictly necessary.
38+
2739
2840## Installing Obelisk
41+
29421. [Install Nix](https://nixos.org/nix/).
3043 If you already have Nix installed, make sure you have version 2.0 or higher. To check your current version, run `nix-env --version`.
31441. Set up nix caches
3245 1. If you are running NixOS, add this to `/etc/nixos/configuration.nix`:
33− ```
46+ ```nix
3447 nix.binaryCaches = [ "https://nixcache.reflex-frp.org" ];
3548 nix.binaryCachePublicKeys = [ "ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=" ];
3649 ```
3750 and rebuild your NixOS configuration (e.g. `sudo nixos-rebuild switch`).
38− 1. If you are using another operating system or linux distribution, ensure that these lines are present in your Nix configuration file (`/etc/nix/nix.conf` on most systems; [see full list](https://nixos.org/nix/manual/#sec-conf-file)):
39− ```
40− binary-caches = https://cache.nixos.org https://nixcache.reflex-frp.org
41− binary-cache-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=
42− binary-caches-parallel-connections = 40
51+ 1. If you are using another operating system or Linux distribution, ensure that these lines are present in your Nix configuration file (`/etc/nix/nix.conf` on most systems; [see full list](https://nixos.org/nix/manual/#sec-conf-file)):
52+ ```nix
53+ binary-caches = https://cache.nixos.org https://nixcache.reflex-frp.org
54+ binary-cache-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=
55+ binary-caches-parallel-connections = 40
4356 ```
44− * other Linux: enable sandboxing (see these [issue172](https://github.com/obsidiansystems/obelisk/issues/172#issuecomment-411507818) or [issue6](https://github.com/obsidiansystems/obelisk/issues/6) if you run into build problems)
45− ```
57+ * If you're on a Linux distribution other than NixOS, enable sandboxing (see these [issue 172](https://github.com/obsidiansystems/obelisk/issues/172#issuecomment-411507818) or [issue 6](https://github.com/obsidiansystems/obelisk/issues/6) if you run into build problems) by adding the following:
58+ ```nix
4659 sandbox = true
4760 ```
48− * MacOS: disable sandboxing (there are still some impure dependencies for now)
49− ```
61+ * If you're on MacOS, disable sandboxing (there are still some impure dependencies for now) by adding the following:
62+ ```nix
5063 sandbox = false
5164 ```
5265 then restart the nix daemon
53− ```
66+ ```bash
5467 sudo launchctl stop org.nixos.nix-daemon
5568 sudo launchctl start org.nixos.nix-daemon
5669 ```
57701. Install obelisk: `nix-env -f https://github.com/obsidiansystems/obelisk/archive/master.tar.gz -iA command`
5871
59−### Contributing to Obelisk
60−
61−When developing on obelisk itself you may launch `ghcid` for the corresponding project as follows. For example to launch ghcid for `lib/backend` project:
62−
63−```bash
64−nix-shell -A obeliskEnvs.obelisk-backend --run "cd lib/backend && ghcid -c 'cabal new-repl'"
65−```
66−
67−Or to launch ghcid for `lib/command` project:
68−
69−```bash
70−nix-shell -A obeliskEnvs.obelisk-command --run "cd lib/command && ghcid -c 'cabal new-repl'"
71−```
72−
73−To re-install `ob` from source do
74−```bash
75−nix-env -f /path/to/obelisk -iA command
76−```
77−
78−Note that `ob` will defer to the version found in your project's `.obelisk/impl` directory. To update that version specifically:
79−
80−```bash
81−ob thunk unpack ./.obelisk/impl
82−cd ./.obelisk/impl
83−# apply your changes
84−```
85−
86−If you want to commit your changes, first push them to your fork of obelisk and then
87−
88−```bash
89−cd /your/project/root
90−ob thunk pack .obelisk/impl
91−git add .obelisk/impl
92−git commit -m "Bump obelisk"
93−```
94−
9572### Accessing private repositories
9673
9774To allow the Nix builder to access private git repositories, you must be set up
@@ -120,119 +97,12 @@ Firefox will not be able to properly run the development website due to [issue 4
12097
12198Every time you change the Haskell source files in frontend, common or backend, `ob run` will automatically recompile the modified files and reload the server. Furthermore, it will display on screen compilation errors and warnings if any.
12299
123−### Adding packages
124−
125−In order to add package dependencies, declare them under the build-depends field in the appropriate cabal files (backend, common, and frontend each have their own). The corresponding Nix packages will automatically be selected when building.
126−
127−### Adding package overrides
128−
129−To add a version override to any Haskell package, or to add a Haskell package that doesn't exist in the nixpkgs used by Obelisk, use the `overrides` attribute in your project's `default.nix`. For example, to use a specific version of the `aeson` package fetched from GitHub and a specific version of the `waargonaut` package fetched from Hackage, your `default.nix` will look like:
130−
131−```nix
132−# ...
133−project ./. ({ pkgs, ... }: {
134−# ...
135− overrides = self: super: let
136− aesonSrc = pkgs.fetchFromGitHub {
137− owner = "obsidiansystems";
138− repo = "aeson-gadt-th";
139− rev = "ed573c2cccf54d72aa6279026752a3fecf9c1383";
140− sha256 = "08q6rnz7w9pn76jkrafig6f50yd0f77z48rk2z5iyyl2jbhcbhx3";
141− };
142− in
143− {
144− aeson = self.callCabal2nix "aeson" aesonSrc {};
145− waargonaut = self.callHackageDirect {
146− pkg = "waargonaut";
147− ver = "0.8.0.1";
148− sha256 = "1zv28np3k3hg378vqm89v802xr0g8cwk7gy3mr77xrzy5jbgpa39";
149− } {};
150− };
151−# ...
152−```
153−
154−For further information see [the Haskell section](https://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell-infrastructure) of nixpkgs Contributors Guide.
155−
156−### Adding extra local packages
157−
158−If the standard packages (`frontend`, `backend`, and `common`) are not
159−enough, to add more local Haskell packages, define them with the
160−`packages` parameter. The sources of these packages will be
161−automatically reloaded by `ob run`.
162−
163−```nix
164−# ...
165−project ./. ({ pkgs, ... }: {
166−# ...
167− packages = {
168− another = ./another;
169− };
170−# ...
171−```
172−
173−### Running over HTTPS
174−
175−To run your app locally over HTTPS, update the protocol in `config/common/route` to `https`, and then use `ob run` as normal.
176−
177−Since Obelisk generates a self-signed certificate for running HTTPS, the browser will issue a warning about using an invalid certificate. On Chrome, you can go to `chrome://flags/#allow-insecure-localhost` to enable invalid certificates for localhost.
178−
179100### IDE Support
180101
181−#### Terminal-based feedback
182−
183102Obelisk officially supports terminal-based feedback (akin to [`ghcid`](https://github.com/ndmitchell/ghcid)) in `ob run` and `ob watch`.
184103
185−#### **Experimental** `ghcide` support
186−
187−> **NOTE:** `ghcide` support is strictly **experimental** and **not officially supported**. There is no guarantee that it will work for you or that this support will be maintained over time.
188−
189−To try out the **experimental** [`ghcide`](https://github.com/digital-asset/ghcide) support:
190−
191− * Install a `ghcide` plugin for your editor.
192− * Add `__withGhcide = true;` to your Obelisk project's `default.nix` (inside the call to `project`). With this setting, `ob shell` will provide `ghcide` as well.
193− * Add `hie-bios.sh` to the root of your project:
194− ```shell
195− cat > hie-bios.sh <<'EOF'
196− #!/usr/bin/env bash
197− source "$HOME/.bash_profile"; # NOTE: Some editors need help finding 'ob' and this assumes that `ob` is made available on your `$PATH` in `.bash_profile`
198− ob internal export-ghci-configuration > "$HIE_BIOS_OUTPUT"
199− EOF
200− chmod +x hie-bios.sh
201− ```
202− * **Note:** In some projects you need to use `ob internal export-ghci-configuration --use-relative-paths` in this script instead. This is known to happen when your project contains symlinks to other packages.
203− * Add `hie.yaml` to the root of your project:
204− ```shell
205− echo 'cradle: { bios: { program: hie-bios.sh } }' > hie.yaml
206− ```
207− * Test the configuration with `ob shell ghcide`. Assuming your project compiles and works with `ghcide` otherwise, this should succeed.
208− * Start your editor in a way that it can access the appropriate `ghcide`:
209− * This can sometimes be achieved with `ob shell 'start my editor'`.
210− * If you can't easily start your editor in a way that it inherits your shell, you may need to customize how your `ghcide` plugin finds `ghcide` or create a custom `ghcide` replacement script that you install globally. For example, for Visual Studio Code on macOS adding a script called `ghcide` to your `PATH` like the one below will cause `ghcide` from each project's `ob shell` to be used:
211− ```shell
212− #!/usr/bin/env bash
213− source "$HOME/.bash_profile" # NOTE: This assumes that `ob` is made available on your `$PATH` in `.bash_profile`
214− ob shell "ghcide $@"
215− ```
216−
217104## Deploying
218105
219−### Locally
220−
221−Build everything:
222−
223−```bash
224−nix-build -A exe --no-out-link
225−```
226−
227−Copy the result to a new directory, add configuration, and run!
228−
229−```bash
230−mkdir test-app
231−ln -s $(nix-build -A exe --no-out-link)/* test-app/
232−cp -r config test-app
233−(cd test-app && ./backend)
234−```
235−
236106### Default EC2 Deployment
237107
238108In this section we will demonstrate how to deploy your Obelisk app to an Amazon EC2 instance. Obelisk deployments are configured for EC2 by default (see [Custom Non-EC2 Deployment](#custom-non-ec2-deployment)).
@@ -249,7 +119,7 @@ At this stage your instance should be booting and become accessible shortly. Not
249119Now go to your Obelisk project directory (`~/code/myapp`), and initialize a deployment config (`~/code/myapp-deploy`):
250120Your project directory must be "thunkable", i.e. something on which `ob thunk pack` can be called. Usually it will be a git repository whose current revision has been pushed upstream.
251121
252−```
122+```bash
253123cd ~/code/myapp
254124SERVER=ec2-35-183-22-197.ca-central-1.compute.amazonaws.com
255125ROUTE=https://myapp.com # Publicly accessible route to your app
@@ -268,7 +138,7 @@ This step will also require that you manually verify the authenticity of the hos
268138
269139Next, go to the deployment directory that you just initialized and deploy!
270140
271−```
141+```bash
272142cd ~/code/myapp-deploy
273143ob deploy push
274144```
@@ -297,6 +167,25 @@ Here's a `module.nix` that is configured for deployment to a VirtualBox VM (runn
297167
298168The `{...}:` and following is the [NixOS module](https://nixos.org/nixos/manual/index.html#sec-writing-modules) definition.
299169
170+### Locally
171+
172+If you want deploy your application locally or test a production-oriented build you can build and deploy the app as described below.
173+
174+Build the application:
175+
176+```bash
177+nix-build -A exe --no-out-link
178+```
179+
180+Copy the result to a new directory, add configuration, and run!
181+
182+```bash
183+mkdir test-app
184+ln -s $(nix-build -A exe --no-out-link)/* test-app/
185+cp -r config test-app
186+(cd test-app && ./backend)
187+```
188+
300189### From macOS
301190
302191Deploying from macOS requires some extra setup:
@@ -423,3 +312,13 @@ This should copy over and install the application on your device (if you see a
423312##### Build a release version
424313
425314After having configured signing for your app, you may proceed to build a release version of the app. This is no different to how you build the non-release version, so consult the section [Android](#android) further above for exact instructions on building and deploying to your device.
315+
316+
317+## Frequently Asked Questions (FAQ)
318+
319+Refer to [FAQ](FAQ.md).
320+
321+
322+## Contributing
323+
324+Contributions and issue reports are encouraged and appreciated! Refer to the [Contributing](CONTRIBUTING.md) guide for information about getting started.