-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
87 lines (85 loc) · 2.7 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
86
87
{
description = "Advent of Code 2024";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, devshell, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ devshell.overlays.default ]; };
in
{
devShells = rec {
default = accentor-api;
accentor-api = pkgs.devshell.mkShell {
name = "Advent of Code 2024";
packages = [
pkgs.nixpkgs-fmt
pkgs.postgresql_14
];
env = [
{
name = "PGDATA";
eval = "$PRJ_DATA_DIR/postgres";
}
{
name = "DATABASE_HOST";
eval = "$PGDATA";
}
];
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 aoc2024 WITH PASSWORD 'aoc2024' CREATEDB;" | postgres --single -E postgres
'';
}
{
name = "pg:start";
category = "database";
help = "Start postgres instance";
command = ''
[ ! -d $PGDATA ] && pg:setup
pg_ctl -D $PGDATA -U postgres start -l log/postgres.log
'';
}
{
name = "pg:stop";
category = "database";
help = "Stop postgres instance";
command = ''
pg_ctl -D $PGDATA -U postgres stop
'';
}
{
name = "pg:console";
category = "database";
help = "Open database console";
command = ''
psql --host $PGDATA -U postgres
'';
}
{
name = "run_file";
category = "database";
help = "Run a file in the database";
command = ''
psql --host $PGDATA -U postgres -f $1
'';
}
];
};
};
}
);
}