|
| 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 | +} |
0 commit comments