-
Notifications
You must be signed in to change notification settings - Fork 1
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
12 changed files
with
327 additions
and
84 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ lib | ||
, writeShellScriptBin | ||
, git | ||
}: | ||
|
||
let | ||
keepFiles = [ | ||
# Local-specific files | ||
".envrc.local" | ||
".vscode" | ||
"TODO" | ||
|
||
# Cache files | ||
"node_modules" # Has no functional effect on `dev` service since new/updated modules will be fetched when needed | ||
]; | ||
in | ||
writeShellScriptBin "clean" '' | ||
${git}/bin/git clean -xdf ${lib.concatStringsSep " " (builtins.map (file: "-e ${file}") keepFiles)} | ||
'' // { | ||
meta = { | ||
description = "Reset DateiLager back to a clean state as if it was cloned for the first time"; | ||
}; | ||
} |
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,60 @@ | ||
{ lib | ||
, ansifilter | ||
, coreutils | ||
, moreutils | ||
, services | ||
, writeShellScriptBin | ||
}: | ||
|
||
let | ||
packages = lib.unique ([ | ||
ansifilter | ||
coreutils | ||
moreutils | ||
] ++ builtins.concatMap (service: service.packages or []) services); | ||
|
||
compileService = isLast: service: | ||
let | ||
colorize = text: | ||
"$'\\e[1;${service.ansiColor or ""}m${text}\\e[0m'"; | ||
|
||
consoleFilter = lib.optionalString (service ? consoleFilter) | ||
"| grep -v ${service.consoleFilter}"; | ||
in | ||
builtins.concatStringsSep "\n" ([] | ||
++ lib.optional (service ? env) service.env | ||
++ lib.optional (service ? setup) '' | ||
(${service.setup}) 2>&1 | \ | ||
ts ${colorize "${service.name} (setup)>"} | ||
'' | ||
++ lib.optional (service ? run) '' | ||
(${service.run}) 2>&1 | pee \ | ||
"ts ${colorize "${service.name}>"}${consoleFilter}" \ | ||
'ansifilter > tmp/log/${service.name}.log'${lib.optionalString (!isLast) " &"} | ||
'' | ||
++ lib.optional (!(service ? run) && isLast) '' | ||
sleep infinity | ||
''); | ||
|
||
compileServices = services: | ||
builtins.concatStringsSep "\n" | ||
(lib.imap0 | ||
(i: service: | ||
compileService (i == builtins.length services - 1) service) | ||
services); | ||
in | ||
writeShellScriptBin "dev" '' | ||
set -e | ||
export PATH=${lib.makeBinPath packages}:$PATH | ||
# Stop all services when Ctrl-C is pressed or error occurs | ||
trap 'kill $(jobs -p) 2>/dev/null; wait $(jobs -p)' INT TERM ERR EXIT | ||
mkdir -p tmp/log | ||
${compileServices services} | ||
'' // { | ||
meta = with lib; { | ||
description = "Runs all the services necessary for DateiLager development"; | ||
}; | ||
} |
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,8 @@ | ||
{ lib | ||
, callPackage | ||
}: | ||
|
||
[ | ||
(callPackage ./postgres.nix { }) | ||
(callPackage ./setup-db.nix { }) | ||
] |
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,51 @@ | ||
{ coreutils | ||
, postgresql | ||
}: | ||
|
||
{ | ||
name = "postgres"; | ||
ansiColor = "34"; | ||
|
||
packages = [ | ||
coreutils # sleep | ||
postgresql | ||
]; | ||
|
||
env = '' | ||
export PGDATA="$PWD/tmp/postgres" | ||
export PGUSER=postgres | ||
export PGPASSWORD=password | ||
export PGURI="postgres://$PGUSER:[email protected]" | ||
wait_for_postgres() { | ||
until psql "$PGURI/postgres" -c '\q' 2> /dev/null; do | ||
sleep 0.2 | ||
done | ||
} | ||
database_exists() { | ||
if [ "$(psql "$PGURI/postgres" -qtAc "SELECT 1 FROM pg_database WHERE datname = '$1'")" == "1" ]; then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi | ||
} | ||
create_database() { | ||
psql "$PGURI/postgres" -c "CREATE DATABASE $dbname;" | ||
} | ||
''; | ||
|
||
setup = '' | ||
if [ ! -d "$PGDATA" ]; then | ||
echo "== Creating postgres database cluster ==" | ||
initdb --username="$PGUSER" --pwfile=<(echo "$PGPASSWORD") | ||
fi | ||
''; | ||
|
||
# Don't try to create a unix socket | ||
# We only use TCP sockets and some systems require root permissions for unix sockets | ||
run = '' | ||
postgres -c unix_socket_directories= -c timezone=UTC -c fsync=off -c synchronous_commit=off -c full_page_writes=off | ||
''; | ||
} |
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,17 @@ | ||
{}: | ||
|
||
{ | ||
name = "setup-db"; | ||
ansiColor = "36"; | ||
|
||
setup = '' | ||
wait_for_postgres | ||
for dbname in dl dl_tests; do | ||
if ! $(database_exists $dbname); then | ||
echo "== Creating '$dbname' database ==" | ||
create_database $dbname | ||
fi | ||
done | ||
''; | ||
} |
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,3 @@ | ||
use flake | ||
|
||
source_env_if_exists .envrc.local |
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,51 @@ | ||
name: 'Set up environment' | ||
description: '' | ||
inputs: {} | ||
outputs: {} | ||
runs: | ||
using: composite | ||
steps: | ||
- uses: cachix/install-nix-action@v14 | ||
with: | ||
install_url: https://nixos-nix-install-tests.cachix.org/serve/vij683ly7sl95nnhb67bdjjfabclr85m/install | ||
install_options: '--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve' | ||
extra_nix_config: | | ||
experimental-features = nix-command flakes | ||
- run: nix flake check | ||
shell: bash | ||
|
||
- name: Set cache paths | ||
id: cache-paths | ||
run: | | ||
echo "::set-output name=go_mod::$(go env GOMODCACHE)" | ||
echo "::set-output name=go_build::$(go env GOCACHE)" | ||
echo "::set-output name=npm::$(npm config get cache)" | ||
shell: nix develop -c bash -eo pipefail -l {0} | ||
|
||
- name: Cache go mods | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
${{ steps.cache-paths.outputs.go_mod }} | ||
${{ steps.cache-paths.outputs.go_build }} | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Cache npm packages | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.cache-paths.outputs.npm }} | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- run: go mod download | ||
shell: nix develop -c bash -eo pipefail -l {0} | ||
|
||
- run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH | ||
shell: nix develop -c bash -eo pipefail -l {0} | ||
|
||
- run: make install | ||
shell: nix develop -c bash -eo pipefail -l {0} |
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
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 |
---|---|---|
|
@@ -11,3 +11,9 @@ release/ | |
*.pb.go | ||
fs*.ts | ||
**/node_modules/ | ||
tmp/* | ||
!tmp/.gitkeep | ||
.direnv | ||
.idea/ | ||
.DS_STORE | ||
.envrc.local |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.