-
Notifications
You must be signed in to change notification settings - Fork 69
/
shell.nix
97 lines (78 loc) · 2.42 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{ sources ? import nix/sources.nix
, pkgs ? import sources.nixpkgs { overlays = [ ]; config = { }; }
}:
with pkgs;
let
lib = import <nixpkgs/lib>;
inherit (lib) optional optionals;
# custom defined packages in nixpkgs go = callPackage ./nix/go.nix { pkgs = pkgs; };
nodejs = nodejs-14_x;
postgresql = postgresql_14;
# postgres definition
pg_root = builtins.toString ./. + "/.yatai_db";
pg_user = "postgres";
pg_host = "localhost";
pg_db = "yatai";
# base requirements
basePackages = with pkgs; [
# custom defined go version
go
# TODO: lock version with niv
postgresql
# Without this, we see a whole bunch of warnings about LANG, LC_ALL and locales in general.
# The solution is from: https://github.com/NixOS/nix/issues/318#issuecomment-52986702
glibcLocales
nodejs
yarn
jq
gnumake
git
coreutils
];
requiredPackages = basePackages
++ lib.optional stdenv.isLinux inotify-tools
++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
CoreFoundation
CoreServices
]);
env = buildEnv {
name = "build-env";
paths = requiredPackages;
};
in
stdenv.mkDerivation rec {
name = "yatai-dev";
phases = [ "nobuild" ];
buildInputs = [ env ];
shellHook = ''
# "nix-shell --pure" resets LANG to POSIX, this breaks "make TAGS".
export LANG="en_US.UTF-8"
# /bin/ps cannot be found in the build environment.
export PATH="/bin:/usr/bin:/usr/local/bin:/usr/sbin:$PATH"
# setup for dashboard
alias scripts='jq ".scripts" dashboard/package.json'
make fe-deps be-deps
export PGDATA=${pg_root}
export SOCKET_DIRECTORIES="$PWD/sockets"
mkdir $SOCKET_DIRECTORIES
if [ ! -d "$PGDATA" ]; then
initdb --auth=trust --auth-host=trust >/dev/null
echo "unix_socket_directories = '$SOCKET_DIRECTORIES'" >> $PGDATA/postgresql.conf
fi
pg_ctl -l $PGDATA/logfile start
createuser ${pg_user} --createdb -h ${pg_host} || true
createdb ${pg_db} -h ${pg_host} -O ${pg_user} || true
function end {
echo "Shutting down the database..."
pg_ctl stop
echo "Removing directories..."
rm -rf $SOCKET_DIRECTORIES
}
trap end EXIT
'';
enableParallelBuilding = true;
LOCALE_ARCHIVE = if stdenv.isLinux then "${glibcLocales}/lib/locale/locale-archive" else "";
nobuild = ''
echo Do not run this derivation with nix-build, it can only be used with nix-shell
'';
}