-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
133 lines (126 loc) · 4.12 KB
/
flake.nix
File metadata and controls
133 lines (126 loc) · 4.12 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{
description = "Accentor API";
inputs = {
bundix = {
url = "github:inscapist/bundix";
inputs.nixpkgs.follows = "nixpkgs";
};
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, bundix, devshell, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
devshell.overlays.default
(self: super: { inherit bundix; })
];
};
ruby = pkgs.ruby_4_0;
gems = pkgs.bundlerEnv {
name = "accentor-api-env";
ruby = ruby.override { jemallocSupport = true; };
gemfile = ./Gemfile;
lockfile = ./Gemfile.lock;
gemset = ./gemset.nix;
groups = [ "default" "development" "test" "production" ];
};
in
{
packages = rec {
default = accentor-api;
accentor-api = pkgs.stdenv.mkDerivation rec {
pname = "accentor-api";
version = "0.23.0";
src = pkgs.lib.cleanSourceWith { filter = name: type: !(builtins.elem name [ ".github" "flake.lock" "flake.nix" ]); src = ./.; name = "source"; };
buildPhase = ''
# Compile bootsnap cache
${gems}/bin/bundle exec bootsnap precompile --gemfile app/ lib/
'';
installPhase = ''
mkdir $out
cp -r * $out
'';
passthru.env = gems;
};
};
devShells = rec {
default = accentor-api;
accentor-api = pkgs.devshell.mkShell {
name = "Accentor API";
packages = [
gems
(pkgs.lib.lowPrio gems.wrappedRuby)
pkgs.ffmpeg
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 accentor WITH PASSWORD 'accentor' 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 = "gems:update";
category = "dependencies";
help = "Update the `Gemfile.lock` and `gemset.nix` files";
command = ''
${ruby}/bin/bundle lock --add-checksums
${pkgs.bundix}/bin/bundix
'';
}
];
};
deps = pkgs.devshell.mkShell { packages = [ ruby pkgs.bundix ]; };
};
}
);
}