-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
55 lines (52 loc) · 1.76 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
{
description = "Gonny the station chef";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { flake-utils, nixpkgs, devshell, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlays.default ];
};
in
with pkgs; {
devShells.default = pkgs.devshell.mkShell {
packages = [ go postgresql ];
commands = [
{
name = "pg:setup";
category = "database";
help = "Setup postgres in project folder";
command = ''
initdb --encoding=UTF8 --no-locale --no-instructions -U postgres
echo "listen_addresses = ${"'"}${"'"}" >> $PGDATA/postgresql.conf
echo "unix_socket_directories = '$PGDATA'" >> $PGDATA/postgresql.conf
echo "CREATE USER ronny WITH PASSWORD 'ronnydbpassword' CREATEDB SUPERUSER;" | postgres --single -E postgres
echo "CREATE DATABASE ronny WITH owner 'ronny';" | postgres --single -E postgres
'';
}
{
name = "pg:start";
category = "database";
help = "Start postgres instance";
command = ''
[ ! -d $PGDATA ] && pg:setup
postgres
'';
}
];
env = [
{ name = "DATABASE_HOST"; eval = "$PRJ_DATA_DIR/postgres"; }
{ name = "PGDATA"; eval = "$PRJ_DATA_DIR/postgres"; }
];
};
}
);
}