IHP
IHP is a batteries-included full-stack web framework written in Haskell.
Creating a new basic IHP project can be easily done directly from Shipnix with the IHP starter. The IHP starter comes with a fresh IHP project and a self-hosted PostgreSQL server already plugged in.
If you are already hosted at IHP cloud, and want to migrate, we have a migration guide.
Add a domain and https
As soon as you create a new IHP server, it will only be available through your public IP address.
Follow these guides to add a domain name and https
In addition, you would have to go to the Environment tab in your server dashboard and set the primary domain name in the environment variables.
IHP_BASEURL=https://yourdomain.com
Enable jobs
IHP jobs must be enabled in the site.nix
file.
{ config, lib, pkgs, docs, environment, ... }:
let
ihpApp = import ../.;
# TODO: Enable SSL
# By enabling SSL, you accept the terms and conditions of LetsEncrypt
isHttpEnabled = true;
jobsEnabled = true;
in
Deploy IHP in optimized mode
The default ghc compilation flag for IHP is -01
.
According to GHC docs, the -01
flags means Generate good-quality code without taking too long about it.
In other words, more than good enough for most usecases, and rebuilds are very quick on Shipnix.
Optimized mode compiles your IHP project in GHC optimization flag -02
.
-02
translates to Apply every non-dangerous optimisation, even if it means significantly longer compile times.
. And it delivers on significantly longer, especially in an IHP project.
To enable optimized mode, go to your default.nix
add the optimize
option.
...
];
otherDeps = p: with p; [
# Native dependencies, e.g. imagemagick
];
projectPath = ./.;
+ optimized = true;
};
in
haskellEnv
Ask yourself: Will my users notice this optimization?
Shipnix's opinion: Beware of premature optimization.
Must run in impure mode
IHP is packaged with Nix, but have not yet been updated to work with Nix flakes yet.
IHP servers must be run with the --impure
flag, meaning this switch must be turned on like this in the IHP dashboard.
Switch to a managed/external database
You can switch to a managed or other external database if you don’t wish to host the database on your server.
Just go to the Environment
tab in your server dashboard and change the DATABASE_URL
key.
- DATABASE_URL=postgres://shipadmin:[password]@0.0.0.0:5432/defaultdb
+ DATABASE_URL=postgresql://doadmin:[password]@[...]forexampledigitalocean.com:25060/defaultdb?sslmode=require
SSH into your server and run the before-rebuild
script:
~/server/nixos/scripts/before-rebuild
Then go to your server dashboard on Shipnix and click Deploy
.
You can delete your self-hosted postgresql database if you wish. It will be completely gone after your next garbage-collection.
- services.postgresql = {
- enable = true;
- package = pkgs.postgresql;
- ensureDatabases = [ "defaultdb" ];
- ensureUsers = [
- {
- name = "shipadmin";
- ensurePermissions = {
- "DATABASE defaultdb" = "ALL PRIVILEGES";
- };
- }
- ];
- enableTCPIP = true;
- authentication = ''
- host all all 0.0.0.0/0 md5
- '';
- };