Skip to content

Commit 89804f9

Browse files
authored
MariaDB Plugin (#1048)
1 parent 823ba3e commit 89804f9

File tree

13 files changed

+118
-66
lines changed

13 files changed

+118
-66
lines changed

examples/databases/mariadb/conf/mysql/mysql.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/databases/mariadb/conf/set-env.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/databases/mariadb/conf/set-exit.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
{
2-
"packages": [
3-
"mariadb"
4-
],
5-
"env": {
6-
"MYSQL_HOME": "$PWD/conf/mysql",
7-
"MYSQL_DATADIR": "$PWD/conf/mysql/data",
8-
"MYSQL_UNIX_PORT": "$PWD/conf/mysql/mysql.sock",
9-
"MYSQL_PID_FILE": "$PWD/conf/mysql/mysql.pid"
10-
},
11-
"shell": {
12-
"init_hook": [
13-
"source conf/set-env.sh",
14-
"conf/mysql/mysql.sh",
15-
"source conf/set-exit.sh"
16-
]
2+
"packages": [
3+
"mariadb@latest"
4+
],
5+
"shell": {
6+
"init_hook": [],
7+
"scripts": {
8+
"connect_db": [
9+
"mysql -u devbox_user -p -D devbox_lamp"
10+
],
11+
"test_db_setup": [
12+
"devbox services up -b",
13+
"sleep 5",
14+
"mysql -u root < setup_db.sql",
15+
"devbox services stop"
16+
]
1717
}
18+
},
19+
"nixpkgs": {
20+
"commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62"
21+
}
1822
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"lockfile_version": "1",
3+
"packages": {
4+
"mariadb": {
5+
"resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#mariadb"
6+
},
7+
"mariadb@latest": {
8+
"last_modified": "2023-05-01T16:53:22Z",
9+
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#mariadb",
10+
"version": "10.6.12"
11+
}
12+
}
13+
}

plugins/mariadb.json

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "mariadb",
33
"version": "0.0.1",
4-
"match": "disabled",
5-
"readme": "* This package creates shims and stores them in .devbox/virtenv/mariadb/bin\n* Use mysql_install_db to initialize data directory\n* Use mysqld to start the server",
4+
"match": "^mariadb_?[0-9]*$",
5+
"readme": "* This plugin wraps mysqld and mysql_install_db to work in your local project\n* This plugin will create a new database for your project in MYSQL_DATADIR if one doesn't exist on shell init\n* Use mysqld to manually start the server, and `mysqladmin -u root shutdown` to manually stop it",
66
"env": {
77
"MYSQL_BASEDIR": "{{ .DevboxProfileDefault }}",
88
"MYSQL_HOME": "{{ .Virtenv }}/run",
@@ -11,11 +11,23 @@
1111
"MYSQL_PID_FILE": "{{ .Virtenv }}/run/mysql.pid"
1212
},
1313
"create_files": {
14-
"{{ .Virtenv }}/data": "",
1514
"{{ .Virtenv }}/run": "",
16-
"{{ .Virtenv }}/bin/mysql": "mariadb/mysql",
17-
"{{ .Virtenv }}/bin/mysql_install_db": "mariadb/mysql_install_db",
18-
"{{ .Virtenv }}/bin/mysqladmin": "mariadb/mysqladmin",
19-
"{{ .Virtenv }}/bin/mysqld": "mariadb/mysqld"
15+
"{{ .Virtenv }}/flake.nix": "mariadb/flake.nix",
16+
"{{ .Virtenv }}/setup_db.sh": "mariadb/setup_db.sh",
17+
"{{ .Virtenv }}/process-compose.yaml": "mariadb/process-compose.yaml"
18+
},
19+
"packages": [
20+
"path:{{ .Virtenv }}"
21+
],
22+
"shell": {
23+
"init_hook": [
24+
"bash {{ .Virtenv }}/setup_db.sh"
25+
]
26+
},
27+
"services": {
28+
"mariadb": {
29+
"start": "mysqld 2> $MYSQL_HOME/mysql.log & MYSQL_PID=$! && echo 'Starting mysqld... check mariadb_logs for details'",
30+
"stop": "mysqladmin -u root shutdown"
31+
}
2032
}
2133
}

plugins/mariadb/flake.nix

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
description = "A flake that outputs MariaDB with custom configuration and aliases to work in Devbox";
3+
4+
inputs = {
5+
nixpkgs.url = "{{.URLForInput}}";
6+
};
7+
8+
outputs = {self, nixpkgs}:
9+
let
10+
mariadb-bin = nixpkgs.legacyPackages.{{.System}}.symlinkJoin {
11+
12+
name = "mariadb-wrapped";
13+
paths = [nixpkgs.legacyPackages.{{ .System }}.{{.PackageName}}];
14+
nativeBuildInputs = [ nixpkgs.legacyPackages.{{.System}}.makeWrapper];
15+
postBuild = ''
16+
17+
wrapProgram $out/bin/mysqld \
18+
--add-flags '--datadir=''$MYSQL_DATADIR --pid-file=''$MYSQL_PID_FILE --socket=''$MYSQL_UNIX_PORT';
19+
20+
wrapProgram $out/bin/mariadbd \
21+
--add-flags '--datadir=''$MYSQL_DATADIR --pid-file=''$MYSQL_PID_FILE --socket=''$MYSQL_UNIX_PORT';
22+
23+
wrapProgram $out/bin/mysqld_safe \
24+
--add-flags '--datadir=''$MYSQL_DATADIR --pid-file=''$MYSQL_PID_FILE --socket=''$MYSQL_UNIX_PORT';
25+
26+
if [-f $out/bin/mariadbd-safe]; then
27+
wrapProgram $out/bin/mariadbd_safe \
28+
--add-flags '--datadir=''$MYSQL_DATADIR --pid-file=''$MYSQL_PID_FILE --socket=''$MYSQL_UNIX_PORT';
29+
fi
30+
31+
wrapProgram "$out/bin/mysql_install_db" \
32+
--add-flags '--datadir=''$MYSQL_DATADIR --pid-file=''$MYSQL_PID_FILE --basedir=''$MYSQL_BASEDIR';
33+
34+
if [-f $out/bin/mariadb-install-db]; then
35+
wrapProgram "$out/bin/mariadb_install_db" \
36+
--add-flags '--datadir=''$MYSQL_DATADIR --pid-file=''$MYSQL_PID_FILE --basedir=''$MYSQL_BASEDIR';
37+
fi
38+
'';
39+
};
40+
in{
41+
packages.{{.System}} = {
42+
default = mariadb-bin;
43+
};
44+
};
45+
}

plugins/mariadb/mysql

Lines changed: 0 additions & 1 deletion
This file was deleted.

plugins/mariadb/mysql_install_db

Lines changed: 0 additions & 1 deletion
This file was deleted.

plugins/mariadb/mysqladmin

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)