-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
3,803 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
nix_direnv_manual_reload | ||
watch_file *.cabal | ||
use flake | ||
watch_file *.cabal, env_config/* | ||
use flake .#backend --impure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Main where | ||
|
||
import Api | ||
import Api.Tag (mockTag) | ||
import MyPrelude | ||
import Network.Wai | ||
import Network.Wai.Handler.Warp | ||
import Servant | ||
import Types | ||
|
||
main :: IO () | ||
main = do | ||
logOptions <- logOptionsHandle stderr True | ||
portStr <- getEnv "SERVER_PORT" | ||
let port = | ||
fromMaybe | ||
(error $ "Could not parse port: " <> portStr) | ||
(readMaybe portStr) | ||
withLogFunc logOptions $ \lf -> do | ||
env <- appEnv lf | ||
runRIO env initEnv | ||
runRIO env mockTag | ||
run port (serve appAPI $ hoistServer appAPI (handleApiM env) appServer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import AppServer (runServer) | ||
import MyPrelude | ||
|
||
main :: IO () | ||
main = runSimpleApp $ logInfo "Hello World!" | ||
main = runSimpleApp $ liftIO runServer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
packages: | ||
./ | ||
|
||
package subtube | ||
tests: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[[env]] | ||
name = "HOOGLE_PORT" | ||
value = "9500" | ||
|
||
[[commands]] | ||
name = "doc" | ||
command = ''' | ||
echo http://127.0.0.1:$HOOGLE_PORT | ||
hoogle serve -p $HOOGLE_PORT --local | ||
''' | ||
help = "run hoogle server locally for documentation" | ||
category = "Haskell tools" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
imports = ["postgres.nix"] | ||
|
||
[services.postgres] | ||
package = "pkgs.postgresql_15" | ||
setupPostgresOnStartup = true | ||
listenAddresses = "*" | ||
|
||
[[env]] | ||
name = "SERVER_PORT" | ||
value = "9892" | ||
|
||
[[env]] | ||
name = "INVIDIOUS_ROOT" | ||
value = "https://invidious.jing.rocks/api/" | ||
|
||
[[env]] | ||
name = "INVIDIOUS_ROOT_FALLBACK" | ||
value = "https://yewtu.be/api/" | ||
|
||
[[env]] | ||
name = "DBNAME" | ||
value = "subtube" | ||
|
||
[[env]] | ||
name = "PGPORT" | ||
value = "9891" | ||
|
||
[[env]] | ||
name = "ST_PGHOST" | ||
value = "localhost" | ||
|
||
[[env]] | ||
name = "PGUSER" | ||
eval = "${USER:-$(id -nu)}" | ||
|
||
[[env]] | ||
name = "PSQL_URL" | ||
eval = "postgresql://${ST_PGHOST}:${PGPORT}/${DBNAME}" | ||
|
||
[[env]] | ||
name = "PSQL_MOCK_URL" | ||
eval = "postgresql://${ST_PGHOST}:${PGPORT}/${DBNAME}_mock" | ||
|
||
[[env]] | ||
name = "ST_DATABASE_MIGRATION_DIR" | ||
value = "psql" | ||
|
||
[[env]] | ||
name = "ST_DATABASE_MIGRATION_MOCK_DIR" | ||
eval = 'mockdata/db' | ||
|
||
[[commands]] | ||
name = "setup-db" | ||
command = ''' | ||
createdb -E UTF8 -T template0 -h $PGDATA -p $PGPORT $DBNAME | ||
createdb -E UTF8 -T template0 -h $PGDATA -p $PGPORT ${DBNAME}_mock | ||
pushd $PRJ_ROOT/migration/psql | ||
sqitch deploy dev | ||
sqitch deploy mock | ||
''' | ||
category = "DB" | ||
|
||
[[commands]] | ||
name = "reset-db" | ||
command = ''' | ||
rm -rf $PGDATA | ||
setup-postgres | ||
postgres | ||
''' | ||
category = "DB" | ||
|
||
[[commands]] | ||
name = "rebase-mock-db" | ||
command = ''' | ||
pushd $PRJ_ROOT/migration/psql | ||
yes | sqitch rebase mock | ||
''' | ||
category = "DB" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[[env]] | ||
name = "API_SPEC_PATH" | ||
eval = "$PRJ_ROOT/api.js" | ||
|
||
[[env]] | ||
name = "API_GENSTUB_PATH" | ||
eval = "$PRJ_ROOT/frontend/src/genstub" | ||
|
||
[[commands]] | ||
package = "openapi-generator-cli" | ||
category = "openapi" | ||
|
||
[[commands]] | ||
name = "gen-ts" | ||
help = "generate typescript client" | ||
command = ''' | ||
rm -rf "$API_GENSTUB_PATH" | ||
openapi-generator-cli generate -i "http://127.0.0.1:$SERVER_PORT/swagger.json" -g typescript-axios -o "$API_GENSTUB_PATH" | ||
''' | ||
category = "openapi" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# This module automatically configures postgres when the user enters the | ||
# devshell. | ||
# | ||
# To start the server, invoke `postgres` in one devshell. Then start a second | ||
# devshell to run the clients. | ||
{ lib, pkgs, config, ... }: | ||
with lib; | ||
let | ||
devshellSrc = fetchTarball | ||
"https://github.com/numtide/devshell/archive/cd4e2fda3150dd2f689caeac07b7f47df5197c31.tar.gz"; | ||
|
||
# Because we want to be able to push pure JSON-like data into the | ||
# environment. | ||
strOrPackage = | ||
import (devshellSrc + "/nix/strOrPackage.nix") { inherit lib pkgs; }; | ||
|
||
cfg = config.services.postgres; | ||
createDB = optionalString cfg.createUserDB '' | ||
echo "CREATE DATABASE ''${USER:-$(id -nu)};" | postgres --single -E postgres | ||
''; | ||
|
||
setup-postgres = pkgs.writeShellScriptBin "setup-postgres" '' | ||
set -euo pipefail | ||
export PATH=${cfg.package}/bin:${pkgs.coreutils}/bin | ||
# Abort if the data dir already exists | ||
[[ ! -d "$PGDATA" ]] || exit 0 | ||
initdb ${concatStringsSep " " cfg.initdbArgs} | ||
cat >> "$PGDATA/postgresql.conf" <<EOF | ||
listen_addresses = '${cfg.listenAddresses}' | ||
unix_socket_directories = '$PGHOST' | ||
EOF | ||
${createDB} | ||
''; | ||
|
||
start-postgres = pkgs.writeShellScriptBin "start-postgres" '' | ||
set -euo pipefail | ||
${setup-postgres}/bin/setup-postgres | ||
exec ${cfg.package}/bin/postgres | ||
''; | ||
in { | ||
options.services.postgres = { | ||
package = mkOption { | ||
type = strOrPackage; | ||
description = "Which version of postgres to use"; | ||
default = pkgs.postgresql; | ||
defaultText = "pkgs.postgresql"; | ||
}; | ||
|
||
setupPostgresOnStartup = mkEnableOption "call setup-postgres on startup"; | ||
|
||
createUserDB = mkOption { | ||
type = types.bool; | ||
default = true; | ||
description = '' | ||
Create a database named like current user on startup. | ||
This option only makes sense when `setupPostgresOnStartup` is true. | ||
''; | ||
}; | ||
|
||
listenAddresses = mkOption { | ||
type = types.str; | ||
default = ""; | ||
description = '' | ||
Specifies the TCP/IP address(es) on which the server is to listen for connections from client applications | ||
''; | ||
}; | ||
|
||
initdbArgs = mkOption { | ||
type = with types; listOf str; | ||
default = [ "--no-locale" ]; | ||
example = [ "--data-checksums" "--allow-group-access" ]; | ||
description = '' | ||
Additional arguments passed to <literal>initdb</literal> during data dir | ||
initialisation. | ||
''; | ||
}; | ||
|
||
}; | ||
config = { | ||
packages = [ cfg.package setup-postgres start-postgres ]; | ||
|
||
env = [ | ||
{ | ||
name = "PGDATA"; | ||
eval = "$PRJ_DATA_DIR/postgres"; | ||
} | ||
{ | ||
name = "PGHOST"; | ||
eval = "$PGDATA"; | ||
} | ||
]; | ||
|
||
devshell.startup.setup-postgres.text = | ||
lib.optionalString cfg.setupPostgresOnStartup '' | ||
${setup-postgres}/bin/setup-postgres | ||
''; | ||
}; | ||
} |
Oops, something went wrong.