-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathflake.nix
85 lines (81 loc) · 2.4 KB
/
flake.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
{
description = "bottlenose";
inputs.nixpkgs.url = "github:nixos/nixpkgs/5e15d5da4abb74f0dd76967044735c70e94c5af1";
# https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable&package=ruby
inputs.nixpkgs-ruby.url = "github:nixos/nixpkgs/5e15d5da4abb74f0dd76967044735c70e94c5af1";
outputs = { self, nixpkgs, nixpkgs-ruby }: let
pkgs = import nixpkgs {
system = "x86_64-linux";
config.allowUnfree = true; # for chrome
};
rubyPkgs = import nixpkgs-ruby {
system = "x86_64-linux";
};
in {
devShell.x86_64-linux = let
psql_setup_file = pkgs.writeText "setup.sql" ''
DO
$do$
BEGIN
IF NOT EXISTS ( SELECT FROM pg_catalog.pg_roles WHERE rolname = 'bottlenose') THEN
CREATE ROLE bottlenose CREATEDB LOGIN;
END IF;
END
$do$
'';
postgres_setup = ''
export PGDATA=$PWD/postgres_data
export PGHOST=$PWD/postgres
export LOG_PATH=$PWD/postgres/LOG
export PGDATABASE=postgres
export DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true
if [ ! -d $PGHOST ]; then
mkdir -p $PGHOST
fi
if [ ! -d $PGDATA ]; then
echo 'Initializing postgresql database...'
initdb $PGDATA --auth=trust >/dev/null
fi
'';
gem_setup = ''
mkdir -p .nix-gems
export GEM_HOME=$PWD/.nix-gems
export GEM_PATH=$GEM_HOME
export PATH=$GEM_HOME/bin:$PATH
gem install --conservative bundler
'';
start_postgres = pkgs.writeShellScriptBin "start_postgres" ''
pg_ctl start -l $LOG_PATH -o "-c listen_addresses= -c unix_socket_directories=$PGHOST"
psql -f ${psql_setup_file} > /dev/null
'';
stop_postgres = pkgs.writeShellScriptBin "stop_postgres" ''
pg_ctl -D $PGDATA stop
'';
chromeWrapper = pkgs.writeShellScriptBin "chrome" ''
${pkgs.google-chrome}/bin/google-chrome-stable $@
'';
in pkgs.mkShell {
name = "bottlenose";
buildInputs = (with pkgs; [
git
postgresql
qt512.full
bundix
curl.dev
pcre
nodejs-16_x
nodePackages.yarn
start_postgres
stop_postgres
chromedriver
chromeWrapper
]) ++ (with rubyPkgs; [
ruby_3_0
]);
shellHook = ''
${gem_setup}
${postgres_setup}
'';
};
};
}