Skip to content

Commit

Permalink
fix rust and haskell build for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Andika Demas Riyandi committed Dec 16, 2020
1 parent 65e5276 commit f532df7
Show file tree
Hide file tree
Showing 26 changed files with 2,763 additions and 2,094 deletions.
82 changes: 58 additions & 24 deletions devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ with pkgs;

mkDevShell {
name = "todomvc-nix";
motd = "otherthing";
motd = ''
Welcome to the todomvc-nix application.
If you see this message, it means your are inside the Nix shell.
Command available:
- pginit: initial PostgreSQL setup
- pgstart: start psql service
- pgstop: stop psql service
- migrate: migrate the database
- deletdb: remove the database completely.
'';
commands = [
{
name = "pginit";
Expand Down Expand Up @@ -42,54 +53,77 @@ mkDevShell {
};

env = {
DATABASE_URL="postgresql://todomvc_dbuser:todomvc_dbpass@localhost:5432/todomvc_db";
PGHOST="localhost";
PGPORT="5432";
PGDATABASE="todomvc_db";
PGUSER="todomvc_dbuser";
PGPASSWORD="todomvc_dbpass";
DATABASE_URL = "postgresql://todomvc_dbuser:todomvc_dbpass@localhost:5432/todomvc_db";
PGHOST = "localhost";
PGPORT = "5432";
PGDATABASE = "todomvc_db";
PGUSER = "todomvc_dbuser";
PGPASSWORD = "todomvc_dbpass";
OPENSSL_DIR = "${openssl.bin}/bin";
OPENSSL_LIB_DIR = "${openssl.out}/lib";
OPENSSL_INCLUDE_DIR = "${openssl.out.dev}/include";
};

packages = [
# project executable
# Haskell

# todomvc.reflexDev.ghc.frontend
todomvc.todoHaskellMisoDev.haskell.packages.ghc865.cabal-install
(todomvc.todoHaskellMisoDev.haskell.packages.ghc865.ghcWithPackages (p: with p; [
jsaddle jsaddle-warp transformers warp websockets todo-common servant-jsaddle miso-jsaddle lens text http-proxy http-client mtl
])
)
todomvc.todoHaskell.haskell.packages.ghc865.cabal-install
(todomvc.todoHaskell.haskell.packages.ghc865.ghcWithPackages (p: with p; [
aeson
aeson-pretty
http-types
todo-common
zlib
polysemy
todo-haskell
unliftio
wai
wai-logger
wai-extra
servant
servant-server
postgresql-simple
jsaddle
jsaddle-warp
transformers
warp
websockets
todo-common
servant-jsaddle
miso-jsaddle
lens
text
http-proxy
http-client
mtl
]))

# build tools
## Rust
todomvc.nix.rust

## haskell tools
### haskellPackages
# todomvc.nix.haskellBackend
# (todomvc.todoHaskellPackages.ghcWithPackages
# (p: with p; [
# aeson aeson-pretty http-types todo-common warp zlib lens polysemy text
# unliftio wai wai-logger wai-extra warp servant servant-server postgresql-simple
# ])
# )
# todomvc.todoHaskellPackages.cabal-install
todomvc.nix.rustOverlay
wasm-bindgen-cli
binaryen

### Others
binutils
pkgconfig
openssl
openssl.dev
gcc
glibc
zlib.dev
ncurses
icu.dev
gmp.dev
nixpkgs-fmt

# frontend
nodejs-12_x
yarn
yarn2nix
nodePackages.node2nix

# database
postgresql
Expand Down
46 changes: 23 additions & 23 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
# $ nix flake update --recreate-lock-file
inputs.nixpkgs.url = "github:NixOS/nixpkgs/master";
inputs.flake-utils = {
url = "github:numtide/flake-utils";
inputs = {
nixpkgs.follows = "nixpkgs";
};
url = "github:numtide/flake-utils";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
inputs.devshell = {
url = "github:numtide/devshell/master";
inputs = {
nixpkgs.follows = "nixpkgs";
};
url = "github:numtide/devshell/master";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
inputs.naersk = {
url = "github:nmattia/naersk";
inputs = {
nixpkgs.follows = "nixpkgs";
};
url = "github:nmattia/naersk";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
# Only for example, use the .url for simplicity
inputs.mozilla-overlay = {
Expand All @@ -38,7 +38,7 @@

outputs = { self, nixpkgs, naersk, mozilla-overlay, flake-utils, devshell, polysemy, http-media, servant, miso, servant-jsaddle }:
{
overlay = import ./overlay.nix { inherit polysemy http-media servant miso servant-jsaddle; };
overlay = import ./overlay.nix { inherit polysemy http-media servant miso servant-jsaddle; };
}
//
(
Expand All @@ -48,24 +48,24 @@
inherit system;
# Makes the config pure as well. See <nixpkgs>/top-level/impure.nix:
config = {
allowBroken = true;
permittedInsecurePackages = [
"openssl-1.0.2u"
];
allowBroken = true;
permittedInsecurePackages = [
"openssl-1.0.2u"
];
};
overlays = [
(import mozilla-overlay)
devshell.overlay
(import mozilla-overlay)
devshell.overlay

naersk.overlay
self.overlay
];
naersk.overlay
self.overlay
];
};
in
{
legacyPackages = pkgs.todomvc;

defaultPackage = pkgs.todomvc.nix.haskellBackend;
defaultPackage = pkgs.todomvc.nix.rustFrontend;

packages = flake-utils.lib.flattenTree pkgs.todomvc;

Expand Down
3 changes: 0 additions & 3 deletions haskell/backend/todo-haskell.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ common core
build-depends:
-- Local Dependencies
todo-common

, aeson
, aeson-pretty
, base
, http-types
, lens
Expand Down
7 changes: 7 additions & 0 deletions haskell/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
with-compiler: ghc
packages:
backend/
frontend/
common/
tests: false
benchmarks: false
4 changes: 2 additions & 2 deletions nix/database/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ pkgs }:
{
pgutil = pkgs.callPackage ./pgutil.nix {};
migrate = pkgs.callPackage ./migrate.nix {};
pgutil = pkgs.callPackage ./pgutil.nix { };
migrate = pkgs.callPackage ./migrate.nix { };
}
100 changes: 50 additions & 50 deletions nix/database/pgutil.nix
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
{ writeScript, stdenv }:
# 1. Change .pgdata location to $HOME/.pgdata to anticipate permission error
{
start_pg = writeScript "start-pg"
''
#!${stdenv.shell}
pg_pid=""
set -euo pipefail
# TODO: explain what's happening here
LOCAL_PGHOST=$PGHOST
LOCAL_PGPORT=$PGPORT
LOCAL_PGDATABASE=$PGDATABASE
LOCAL_PGUSER=$PGUSER
LOCAL_PGPASSWORD=$PGPASSWORD
unset PGUSER PGPASSWORD
# TODO: port
pg_ctl -D "$HOME/.pgdata" -w start || (echo pg_ctl failed; exit 1)
until psql postgres -c "SELECT 1" > /dev/null 2>&1 ; do
echo waiting for pg
sleep 0.5
done
'';
init_pg = writeScript "init-pg"
''
#!${stdenv.shell}
pg_pid=""
set -euo pipefail
# TODO: explain what's happening here
LOCAL_PGHOST=$PGHOST
LOCAL_PGPORT=$PGPORT
LOCAL_PGDATABASE=$PGDATABASE
LOCAL_PGUSER=$PGUSER
LOCAL_PGPASSWORD=$PGPASSWORD
unset PGUSER PGPASSWORD
initdb -D $HOME/.pgdata
echo "unix_socket_directories = '$(mktemp -d)'" >> $HOME/.pgdata/postgresql.conf
# TODO: port
pg_ctl -D "$HOME/.pgdata" -w start || (echo pg_ctl failed; exit 1)
until psql postgres -c "SELECT 1" > /dev/null 2>&1 ; do
echo waiting for pg
sleep 0.5
done
psql postgres -w -c "CREATE DATABASE $LOCAL_PGDATABASE"
psql postgres -w -c "CREATE ROLE $LOCAL_PGUSER WITH LOGIN PASSWORD '$LOCAL_PGPASSWORD'"
psql postgres -w -c "GRANT ALL PRIVILEGES ON DATABASE $LOCAL_PGDATABASE TO $LOCAL_PGUSER"
'';
start_pg = writeScript "start-pg"
''
#!${stdenv.shell}
pg_pid=""
set -euo pipefail
# TODO: explain what's happening here
LOCAL_PGHOST=$PGHOST
LOCAL_PGPORT=$PGPORT
LOCAL_PGDATABASE=$PGDATABASE
LOCAL_PGUSER=$PGUSER
LOCAL_PGPASSWORD=$PGPASSWORD
unset PGUSER PGPASSWORD
# TODO: port
pg_ctl -D "$HOME/.pgdata" -w start || (echo pg_ctl failed; exit 1)
until psql postgres -c "SELECT 1" > /dev/null 2>&1 ; do
echo waiting for pg
sleep 0.5
done
'';
init_pg = writeScript "init-pg"
''
#!${stdenv.shell}
pg_pid=""
set -euo pipefail
# TODO: explain what's happening here
LOCAL_PGHOST=$PGHOST
LOCAL_PGPORT=$PGPORT
LOCAL_PGDATABASE=$PGDATABASE
LOCAL_PGUSER=$PGUSER
LOCAL_PGPASSWORD=$PGPASSWORD
unset PGUSER PGPASSWORD
initdb -D $HOME/.pgdata
echo "unix_socket_directories = '$(mktemp -d)'" >> $HOME/.pgdata/postgresql.conf
# TODO: port
pg_ctl -D "$HOME/.pgdata" -w start || (echo pg_ctl failed; exit 1)
until psql postgres -c "SELECT 1" > /dev/null 2>&1 ; do
echo waiting for pg
sleep 0.5
done
psql postgres -w -c "CREATE DATABASE $LOCAL_PGDATABASE"
psql postgres -w -c "CREATE ROLE $LOCAL_PGUSER WITH LOGIN PASSWORD '$LOCAL_PGPASSWORD'"
psql postgres -w -c "GRANT ALL PRIVILEGES ON DATABASE $LOCAL_PGDATABASE TO $LOCAL_PGUSER"
'';

stop_pg = writeScript "stop-pg"
''
#!${stdenv.shell}
pg_pid=""
set -euo pipefail
pg_ctl -D $HOME/.pgdata -w -m immediate stop
'';
stop_pg = writeScript "stop-pg"
''
#!${stdenv.shell}
pg_pid=""
set -euo pipefail
pg_ctl -D $HOME/.pgdata -w -m immediate stop
'';
}
8 changes: 5 additions & 3 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{ pkgs }:
{
haskellBackend = pkgs.callPackage ./haskell { };
haskellMiso = pkgs.callPackage ./haskell-miso { };
rust = pkgs.callPackage ./rust { };
haskellBackend = pkgs.callPackage ./haskell-backend { };
haskellMiso = pkgs.callPackage ./haskell-frontend { };
rustOverlay = pkgs.callPackage ./rust-overlay { };
rustBackend = pkgs.callPackage ./rust-backend { };
rustFrontend = pkgs.callPackage ./rust-frontend { };
database = pkgs.callPackage ./database { };
}
Loading

0 comments on commit f532df7

Please sign in to comment.