-
Notifications
You must be signed in to change notification settings - Fork 7
/
flake.nix
105 lines (104 loc) · 3.19 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
description = "Gandalf";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
devshell = {
url = "github:chvp/devshell";
inputs = {
flake-utils.follows = "flake-utils";
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 = gandalf;
gandalf = pkgs.devshell.mkShell {
name = "Gandalf";
imports = [
"${devshell}/extra/language/ruby.nix"
"${devshell}/extra/git/hooks.nix"
];
git.hooks = {
enable = true;
pre-commit = {
text = "bundle exec rubocop";
};
};
packages = with pkgs; [
docker
nodejs
libyaml
imagemagick
];
language.ruby = {
package = pkgs.ruby_3_2;
nativeDeps = [ pkgs.libmysqlclient pkgs.zlib ];
};
env = [
{
name = "DATABASE_ROOT_PASSWORD";
eval = "gandalf";
}
{
name = "TEST_DATABASE_URL";
eval = "mysql2://root:[email protected]:3306/gandalf_test";
}
{
name = "DATABASE_URL";
eval = "mysql2://root:[email protected]:3306/gandalf";
}
];
serviceGroups.server.services = {
rails = {
name = "server";
command = "rails db:prepare && rails s -p 3000";
};
mysql.command = "mysql";
redis.command = "redis-server --port 6379";
sidekiq.command = "bundle exec sidekiq";
};
commands = [
{
name = "gems:refresh";
category = "general commands";
help = "Install dependencies";
command = ''
bundle install
bundle pristine
'';
}
{
name = "mysql";
category = "database";
help = "Start database docker";
command = ''
trap "systemd-run --user docker stop gandalf-db" 0
docker run --name gandalf-db -p 3306:3306 --rm -v gandalf-db-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=$DATABASE_ROOT_PASSWORD mariadb:latest &
wait
'';
}
{
name = "mysql-console";
category = "database";
help = "Open database console";
command = ''
docker exec -i gandalf-db mysql -uroot -p"$DATABASE_ROOT_PASSWORD"
'';
}
{
name = "redis";
package = pkgs.redis;
}
];
};
};
}
);
}