-
Notifications
You must be signed in to change notification settings - Fork 48
/
flake.nix
109 lines (105 loc) · 3.51 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
106
107
108
109
{
description = "Traewelling";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
devenv.url = "github:cachix/devenv";
};
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.devenv.flakeModule
];
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
perSystem = {
pkgs,
lib,
...
}: {
devenv.shells.default = {config, ...}: {
# See https://github.com/cachix/devenv/issues/528#issuecomment-1556108767
containers = lib.mkForce {};
languages = {
php.enable = true;
php.package = pkgs.php83;
javascript.enable = true;
};
dotenv.enable = true;
services.mysql = {
enable = true;
ensureUsers = [
{
name = config.env.DB_USERNAME;
password = config.env.DB_PASSWORD;
ensurePermissions = {
"*.*" = "ALL PRIVILEGES";
};
}
];
initialDatabases = [
{
name = config.env.DB_DATABASE;
}
];
};
scripts = let
composer = "${config.languages.php.packages.composer}/bin/composer";
php = "${config.languages.php.package}/bin/php";
npm = "${config.languages.javascript.package}/bin/npm";
mysql = config.services.mysql.package;
envKeys = builtins.attrNames config.env;
unsetEnv = builtins.concatStringsSep "\n" (
map (key: "unset ${key}") envKeys
);
in {
setup-devenv.exec = ''
set -eo pipefail
if [ ! -f .env ]
then
echo "Copying .env.example to .env"
cp .env.example .env
fi
set -a; source .env; set +a
echo "Installing composer packages"
${composer} install > /dev/null
echo "Installing npm packages"
${npm} ci > /dev/null
if [[ "$DB_CONNECTION" == "mysql" ]];
then
echo "Waiting for MySQL Database to be ready."
echo " Make sure to run 'devenv up' in another terminal to start the MySQL server."
while ! ${mysql}/bin/mysqladmin ping -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USERNAME" -p="$DB_PASSWORD" --silent; do
sleep 1
done
echo "Migrating database"
${php} artisan migrate:fresh --seed
else
echo "You seem to be not using mysql. Skipping migrations."
fi
echo "Generating Keys"
${php} artisan key:generate > /dev/null
echo "Initializing Passport"
${php} artisan passport:install > /dev/null
'';
serve.exec = ''
# Unset .env variables, so laravel reads the .env files by itself
${unsetEnv}
${npm} run dev &
${php} artisan serve
'';
artisan.exec = ''
# Unset .env variables, so laravel reads the .env files by itself
${unsetEnv}
exec ${php} artisan $@
'';
};
};
formatter = pkgs.alejandra;
};
};
}