Skip to content

Commit 33d7d14

Browse files
authored
chore: add devenv.sh development environment (#412)
Signed-off-by: Pierre-Yves Landuré <pierre-yves@landure.fr> Co-authored-by: Pierre-Yves Landuré <py.landure@cobredia.fr>
1 parent 7167978 commit 33d7d14

File tree

6 files changed

+589
-20
lines changed

6 files changed

+589
-20
lines changed

.envrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export DIRENV_WARN_TIMEOUT=20s
2+
3+
eval "$(devenv direnvrc)"
4+
5+
# The use_devenv function supports passing flags to the devenv command
6+
# For example: use devenv --impure --option services.postgres.enable:bool true
7+
use devenv

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,13 @@
22
/var/
33
/vendor/
44
composer.lock
5+
6+
# Devenv
7+
.devenv*
8+
devenv.local.nix
9+
10+
# direnv
11+
.direnv
12+
13+
# pre-commit
14+
.pre-commit-config.yaml

devenv.lock

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"nodes": {
3+
"devenv": {
4+
"locked": {
5+
"dir": "src/modules",
6+
"lastModified": 1754939863,
7+
"owner": "cachix",
8+
"repo": "devenv",
9+
"rev": "b67a897dba65c60568beddcec2b1d7163c255992",
10+
"type": "github"
11+
},
12+
"original": {
13+
"dir": "src/modules",
14+
"owner": "cachix",
15+
"repo": "devenv",
16+
"type": "github"
17+
}
18+
},
19+
"flake-compat": {
20+
"flake": false,
21+
"locked": {
22+
"lastModified": 1747046372,
23+
"owner": "edolstra",
24+
"repo": "flake-compat",
25+
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
26+
"type": "github"
27+
},
28+
"original": {
29+
"owner": "edolstra",
30+
"repo": "flake-compat",
31+
"type": "github"
32+
}
33+
},
34+
"git-hooks": {
35+
"inputs": {
36+
"flake-compat": "flake-compat",
37+
"gitignore": "gitignore",
38+
"nixpkgs": [
39+
"nixpkgs"
40+
]
41+
},
42+
"locked": {
43+
"lastModified": 1754416808,
44+
"owner": "cachix",
45+
"repo": "git-hooks.nix",
46+
"rev": "9c52372878df6911f9afc1e2a1391f55e4dfc864",
47+
"type": "github"
48+
},
49+
"original": {
50+
"owner": "cachix",
51+
"repo": "git-hooks.nix",
52+
"type": "github"
53+
}
54+
},
55+
"gitignore": {
56+
"inputs": {
57+
"nixpkgs": [
58+
"git-hooks",
59+
"nixpkgs"
60+
]
61+
},
62+
"locked": {
63+
"lastModified": 1709087332,
64+
"owner": "hercules-ci",
65+
"repo": "gitignore.nix",
66+
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
67+
"type": "github"
68+
},
69+
"original": {
70+
"owner": "hercules-ci",
71+
"repo": "gitignore.nix",
72+
"type": "github"
73+
}
74+
},
75+
"nixpkgs": {
76+
"locked": {
77+
"lastModified": 1754299112,
78+
"owner": "cachix",
79+
"repo": "devenv-nixpkgs",
80+
"rev": "16c21c9f5c6fb978466e91182a248dd8ca1112ac",
81+
"type": "github"
82+
},
83+
"original": {
84+
"owner": "cachix",
85+
"ref": "rolling",
86+
"repo": "devenv-nixpkgs",
87+
"type": "github"
88+
}
89+
},
90+
"root": {
91+
"inputs": {
92+
"devenv": "devenv",
93+
"git-hooks": "git-hooks",
94+
"nixpkgs": "nixpkgs",
95+
"pre-commit-hooks": [
96+
"git-hooks"
97+
]
98+
}
99+
}
100+
},
101+
"root": "root",
102+
"version": 7
103+
}

devenv.nix

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
{
2+
pkgs,
3+
lib,
4+
config,
5+
inputs,
6+
...
7+
}:
8+
let
9+
inherit (config.languages.php.packages) composer;
10+
composerCommand = lib.meta.getExe composer;
11+
phpCommand = lib.meta.getExe config.languages.php.package;
12+
pythonPackages = pkgs.python3Packages;
13+
in
14+
{
15+
name = "PostgreSQL for Doctrine";
16+
17+
# https://devenv.sh/basics/
18+
# Set these locally in devenv.local.nix
19+
env = {
20+
POSTGRES_USER = lib.mkDefault "postgres";
21+
POSTGRES_PASSWORD = lib.mkDefault "postgres";
22+
POSTGRES_DB = lib.mkDefault "postgres_doctrine_test";
23+
POSTGRES_PORT = lib.mkDefault 5432;
24+
};
25+
26+
# https://devenv.sh/packages/
27+
packages = with pkgs; [ git ];
28+
29+
# https://devenv.sh/languages/
30+
languages.php = {
31+
enable = true;
32+
# PHP 8.1 is this project least supported PHP version.
33+
version = "8.1";
34+
extensions = [
35+
"ctype"
36+
"dom"
37+
"filter"
38+
"iconv"
39+
"mbstring"
40+
"openssl"
41+
"pdo"
42+
"pdo_pgsql"
43+
"pdo_sqlite"
44+
"tokenizer"
45+
"xdebug"
46+
"xmlwriter"
47+
];
48+
49+
ini = lib.concatStringsSep "\n" [
50+
"xdebug.mode=develop"
51+
"memory_limit=256m"
52+
"error_reporting=E_ALL"
53+
];
54+
};
55+
56+
# https://devenv.sh/processes/
57+
# processes.cargo-watch.exec = "cargo-watch";
58+
59+
# https://devenv.sh/services/
60+
services.postgres = {
61+
enable = true;
62+
63+
listen_addresses = "127.0.0.1";
64+
port = config.env.POSTGRES_PORT;
65+
66+
initialDatabases = [ { name = config.env.POSTGRES_DB; } ];
67+
68+
initialScript = ''
69+
CREATE ROLE "${config.env.POSTGRES_USER}"
70+
WITH SUPERUSER LOGIN PASSWORD '${config.env.POSTGRES_PASSWORD}';
71+
'';
72+
};
73+
74+
# https://devenv.sh/scripts/
75+
scripts.php-modules.exec = ''
76+
set -o 'errexit' -o 'pipefail'
77+
78+
echo 'Installed PHP modules'
79+
echo '---------------------'
80+
81+
${phpCommand} -m |
82+
command grep --invert-match --extended-regexp '^(|\[.*\])$' |
83+
command tr '\n' ' ' |
84+
command fold --spaces
85+
86+
printf '\n---------------------\n'
87+
'';
88+
89+
enterShell = ''
90+
echo "🚀 ${config.name} Development Environment"
91+
git --version
92+
composer --version
93+
php-modules
94+
postgres --version
95+
echo "Storage: ''${PGDATA}"
96+
export PATH="${config.env.DEVENV_ROOT}/bin:$PATH"
97+
'';
98+
99+
# https://devenv.sh/tasks/
100+
tasks = {
101+
"devenv:enterShell:install:composer" = {
102+
description = "Install composer packages";
103+
before = [ "devenv:enterShell" ];
104+
exec = ''
105+
set -o 'errexit'
106+
[[ -e "''${DEVENV_ROOT}/composer.json" ]] &&
107+
${composerCommand} 'install'
108+
'';
109+
};
110+
"devenv:services:reset:postgresql" = {
111+
description = "Reset PostgreSQL data";
112+
exec = ''
113+
set -o 'errexit'
114+
echo "Deleting PostgreSQL data in ''${PGDATA}"
115+
[[ -e "''${PGDATA}" ]] &&
116+
rm -r "''${PGDATA}"
117+
'';
118+
};
119+
};
120+
121+
# https://devenv.sh/tests/
122+
enterTest = ''
123+
echo "Running tests"
124+
git --version | grep --color=auto "${pkgs.git.version}"
125+
php --version | grep --color=auto "${config.languages.php.package.version}"
126+
composer check-code-style
127+
composer run-static-analysis
128+
composer run-all-tests
129+
'';
130+
131+
# https://devenv.sh/git-hooks/
132+
git-hooks.hooks = {
133+
# Conventional Commits
134+
commitizen.enable = true;
135+
136+
# Markdown files
137+
# markdownlint.enable = true;
138+
# mdformat = rec {
139+
# enable = true;
140+
# package = pythonPackages.mdformat;
141+
# extraPackages = with pythonPackages; [
142+
# mdformat-beautysh
143+
# mdformat-gfm
144+
# mdformat-tables
145+
# ];
146+
# };
147+
148+
composer-validate = rec {
149+
enable = true;
150+
name = "composer validate";
151+
package = composer;
152+
files = "composer.json$";
153+
pass_filenames = false;
154+
entry = ''"${lib.meta.getExe package}" validate'';
155+
stages = [
156+
"pre-commit"
157+
"pre-push"
158+
];
159+
};
160+
161+
composer-audit = rec {
162+
enable = true;
163+
name = "composer audit";
164+
after = [ "composer-validate" ];
165+
package = composer;
166+
files = "composer.json$";
167+
verbose = true;
168+
pass_filenames = false;
169+
entry = ''"${lib.meta.getExe package}" audit'';
170+
stages = [
171+
"pre-commit"
172+
"pre-push"
173+
];
174+
};
175+
176+
rector = rec {
177+
enable = true;
178+
name = "Rector";
179+
after = [ "composer-validate" ];
180+
inherit (config.languages.php) package;
181+
files = "\\.php$";
182+
pass_filenames = true;
183+
entry = "${lib.meta.getExe package} '${config.env.DEVENV_ROOT}/bin/rector' 'process'";
184+
args = [
185+
"--dry-run"
186+
"--config=${config.env.DEVENV_ROOT}/ci/rector/config.php"
187+
];
188+
};
189+
190+
php-cs-fixer = rec {
191+
enable = true;
192+
name = "PHP Coding Standards Fixer";
193+
after = [
194+
"composer-validate"
195+
"rector"
196+
];
197+
inherit (config.languages.php) package;
198+
files = "\\.php$";
199+
pass_filenames = true;
200+
entry = "${lib.meta.getExe package} '${config.env.DEVENV_ROOT}/bin/php-cs-fixer' 'fix'";
201+
args = [
202+
"--dry-run"
203+
"--config=${config.env.DEVENV_ROOT}/ci/php-cs-fixer/config.php"
204+
"--show-progress=none"
205+
"--no-interaction"
206+
"--diff"
207+
];
208+
};
209+
210+
phpstan = rec {
211+
enable = true;
212+
name = "PHPStan";
213+
after = [ "composer-validate" ];
214+
inherit (config.languages.php) package;
215+
pass_filenames = false;
216+
entry = "${lib.meta.getExe package} '${config.env.DEVENV_ROOT}/bin/phpstan' 'analyse'";
217+
args = [ "--configuration=${config.env.DEVENV_ROOT}/ci/phpstan/config.neon" ];
218+
};
219+
220+
deptrac = rec {
221+
enable = true;
222+
name = "Deptrac";
223+
after = [ "composer-validate" ];
224+
inherit (config.languages.php) package;
225+
pass_filenames = false;
226+
entry = "${lib.meta.getExe package} '${config.env.DEVENV_ROOT}/bin/deptrac' 'analyze'";
227+
args = [
228+
"--config-file=./ci/deptrac/config.yml"
229+
"--cache-file=./ci/deptrac/.cache"
230+
"--no-interaction"
231+
"--no-progress"
232+
];
233+
};
234+
235+
};
236+
237+
# See full reference at https://devenv.sh/reference/options/
238+
}

devenv.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
2+
inputs:
3+
nixpkgs:
4+
url: github:cachix/devenv-nixpkgs/rolling
5+
6+
# If you're using non-OSS software, you can set allowUnfree to true.
7+
# allowUnfree: true
8+
9+
# If you're willing to use a package that's vulnerable
10+
# permittedInsecurePackages:
11+
# - "openssl-1.1.1w"
12+
13+
# If you have more than one devenv you can merge them
14+
#imports:
15+
# - ./backend

0 commit comments

Comments
 (0)