diff --git a/.envrc b/.envrc index 1b5ce28..dc25ec7 100644 --- a/.envrc +++ b/.envrc @@ -1,2 +1,10 @@ -use nix -watch_file flake.nix flake.lock +if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" +fi + +watch_file flake.nix +watch_file flake.lock +if ! use flake . --no-pure-eval +then + echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 +fi diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c5cd6a0..2eb2795 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -16,33 +16,37 @@ jobs: - name: Install Nix uses: cachix/install-nix-action@v25 + - uses: cachix/cachix-action@v14 + with: + name: devenv + - name: Set outputs id: vars run: | echo "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" - name: Install dependencies - run: nix-shell --run 'composer install --no-interaction' + run: nix develop --no-pure-eval -c composer install --no-interaction - name: Check code using Nette code checker - run: nix-shell --run 'code-checker -d app' + run: nix develop --no-pure-eval -c code-checker -d app - name: Lint coding style - run: nix-shell --run 'composer run-script cs' + run: nix develop --no-pure-eval -c composer run-script cs - name: Run static analysis - run: nix-shell --run 'composer run-script phpstan' + run: nix develop --no-pure-eval -c composer run-script phpstan - name: Lint source code - run: nix-shell --run 'composer run-script lint' + run: nix develop --no-pure-eval -c composer run-script lint - name: Run tests run: | cp .github/workflows/private.neon app/Config/private.neon - nix-shell --run 'composer test' + nix develop --no-pure-eval -c composer test - name: Build a zipball - run: nix-shell --run 'npm run dist "entries-${{ steps.vars.outputs.sha_short }}.zip"' + run: nix develop --no-pure-eval -c npm run dist "entries-${{ steps.vars.outputs.sha_short }}.zip" - name: Upload the zipball to GitHub uses: actions/upload-artifact@v4 diff --git a/.github/workflows/private.neon b/.github/workflows/private.neon index 82e2514..65a5c71 100644 --- a/.github/workflows/private.neon +++ b/.github/workflows/private.neon @@ -1,2 +1,6 @@ +dbal: + driver: mysqli + unix_socket: %env.DEVENV_RUNTIME%/mysql.sock + parameters: adminPassword: heslo diff --git a/.gitignore b/.gitignore index e2e0d9d..037345f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ phpstan.neon /.parcel-cache/ /.direnv/ +/.devenv/ diff --git a/app/Bootstrap.php b/app/Bootstrap.php index c3a2915..b9e51ff 100644 --- a/app/Bootstrap.php +++ b/app/Bootstrap.php @@ -13,6 +13,9 @@ public static function boot(): Configurator { $configurator->enableTracy(__DIR__ . '/../log'); $configurator->setTimeZone('UTC'); $configurator->setTempDirectory(__DIR__ . '/../temp'); + $configurator->addDynamicParameters([ + 'env' => getenv(), + ]); $configurator ->addConfig(__DIR__ . '/Config/common.neon'); $configurator diff --git a/default.nix b/default.nix deleted file mode 100644 index 2f2e032..0000000 --- a/default.nix +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-FileCopyrightText: 2022 Jan Tojnar -# SPDX-License-Identifier: MIT - -let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - flake-compat = builtins.fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - }; - flake = import flake-compat { - src = ./.; - }; -in -flake.defaultNix diff --git a/flake.lock b/flake.lock index cc739b9..da01f25 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,33 @@ { "nodes": { + "cachix": { + "inputs": { + "devenv": [ + "devenv" + ], + "flake-compat": [ + "devenv" + ], + "git-hooks": [ + "devenv" + ], + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1728672398, + "narHash": "sha256-KxuGSoVUFnQLB2ZcYODW7AVPAh9JqRlD5BrfsC/Q4qs=", + "owner": "cachix", + "repo": "cachix", + "rev": "aac51f698309fd0f381149214b7eee213c66ef0a", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "latest", + "repo": "cachix", + "type": "github" + } + }, "composer2nixRepo": { "flake": false, "locked": { @@ -16,14 +44,38 @@ "type": "github" } }, + "devenv": { + "inputs": { + "cachix": "cachix", + "flake-compat": "flake-compat", + "git-hooks": "git-hooks", + "nix": "nix", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1736184348, + "narHash": "sha256-LvuuwJBlZjLgjl6uzhfXP0rBveoNx7q0nz21xYb1AII=", + "owner": "cachix", + "repo": "devenv", + "rev": "07219f00c633f756d1f0cc5bb6c4c311b5c4cb0d", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { - "lastModified": 1733328505, - "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", "owner": "edolstra", "repo": "flake-compat", - "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "type": "github" }, "original": { @@ -32,28 +84,181 @@ "type": "github" } }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "devenv", + "nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": [ + "devenv" + ], + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-stable": [ + "devenv" + ] + }, + "locked": { + "lastModified": 1730302582, + "narHash": "sha256-W1MIJpADXQCgosJZT8qBYLRuZls2KSiKdpnTVdKBuvU=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "af8a16fe5c264f5e9e18bcee2859b40a656876cf", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "libgit2": { + "flake": false, + "locked": { + "lastModified": 1697646580, + "narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=", + "owner": "libgit2", + "repo": "libgit2", + "rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5", + "type": "github" + }, + "original": { + "owner": "libgit2", + "repo": "libgit2", + "type": "github" + } + }, + "nix": { + "inputs": { + "flake-compat": [ + "devenv" + ], + "flake-parts": "flake-parts", + "libgit2": "libgit2", + "nixpkgs": "nixpkgs_2", + "nixpkgs-23-11": [ + "devenv" + ], + "nixpkgs-regression": [ + "devenv" + ], + "pre-commit-hooks": [ + "devenv" + ] + }, + "locked": { + "lastModified": 1727438425, + "narHash": "sha256-X8ES7I1cfNhR9oKp06F6ir4Np70WGZU5sfCOuNBEwMg=", + "owner": "domenkozar", + "repo": "nix", + "rev": "f6c5ae4c1b2e411e6b1e6a8181cc84363d6a7546", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.24", + "repo": "nix", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1733376361, - "narHash": "sha256-aLJxoTDDSqB+/3orsulE6/qdlX6MzDLIITLZqdgMpqo=", + "lastModified": 1730531603, + "narHash": "sha256-Dqg6si5CqIzm87sp57j5nTaeBbWhHFaVyG7V6L8k3lY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7ffd9ae656aec493492b44d0ddfb28e79a1ea25d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1717432640, + "narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "929116e316068c7318c54eb4d827f7d9756d5e9c", + "rev": "88269ab3044128b7c2f4c7d68448b2fb50456870", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixpkgs-unstable", + "ref": "release-24.05", "repo": "nixpkgs", "type": "github" } }, + "nixpkgs_3": { + "locked": { + "lastModified": 1733477122, + "narHash": "sha256-qamMCz5mNpQmgBwc8SB5tVMlD5sbwVIToVZtSxMph9s=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "7bd9e84d0452f6d2e63b6e6da29fe73fac951857", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "composer2nixRepo": "composer2nixRepo", - "flake-compat": "flake-compat", - "nixpkgs": "nixpkgs", - "utils": "utils" + "devenv": "devenv", + "nixpkgs": "nixpkgs_3", + "systems": "systems" } }, "systems": { @@ -70,24 +275,6 @@ "repo": "default", "type": "github" } - }, - "utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index eeab6e5..0581d4c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,64 +1,108 @@ { description = "Entry registration system for Rogaining"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs = { + nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling"; + systems.url = "github:nix-systems/default"; + devenv.url = "github:cachix/devenv"; + devenv.inputs.nixpkgs.follows = "nixpkgs"; - inputs.utils.url = "github:numtide/flake-utils"; - - inputs.composer2nixRepo = { - url = "github:svanderburg/composer2nix"; - flake = false; + composer2nixRepo = { + url = "github:svanderburg/composer2nix"; + flake = false; + }; }; - inputs.flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; + outputs = + { + self, + nixpkgs, + devenv, + systems, + composer2nixRepo, + ... + }@inputs: + + let + forEachSystem = nixpkgs.lib.genAttrs (import systems); + in + { + packages = forEachSystem (system: { + devenv-up = self.devShells.${system}.default.config.procfileScript; + }); - outputs = { self, nixpkgs, utils, flake-compat, composer2nixRepo }: - utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; + devShells = forEachSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + importComposerPackage = + path: + (import path { + inherit system pkgs; + noDev = true; + }).override + { + executable = true; + }; - importComposerPackage = path: (import path { - inherit system pkgs; - noDev = true; - }).override { - executable = true; - }; + composer2nix = importComposerPackage composer2nixRepo.outPath; - composer2nix = importComposerPackage composer2nixRepo.outPath; + nette-code-checker = importComposerPackage ./.github/workflows/nix/code-checker; - nette-code-checker = importComposerPackage ./.github/workflows/nix/code-checker; + update-php-extradeps = pkgs.writeShellScriptBin "update-php-extradeps" '' + pushd .github/workflows/nix/code-checker + composer update + env NIX_PATH=nixpkgs=${nixpkgs.outPath} ${composer2nix}/bin/composer2nix -p nette/code-checker + popd + ''; - update-php-extradeps = pkgs.writeShellScriptBin "update-php-extradeps" '' - pushd .github/workflows/nix/code-checker - composer update - env NIX_PATH=nixpkgs=${nixpkgs.outPath} ${composer2nix}/bin/composer2nix -p nette/code-checker - popd - ''; - in { - devShells = { - default = - let - php = pkgs.php81.withExtensions ({ enabled, all }: with all; enabled ++ [ - intl - ]); - in - pkgs.mkShell { - nativeBuildInputs = [ - php + php = pkgs.php81.withExtensions ( + { enabled, all }: + with all; + enabled + ++ [ + intl + ] + ); + in + { + default = devenv.lib.mkShell { + inherit inputs pkgs; + modules = [ + { + # https://devenv.sh/reference/options/ + packages = [ pkgs.python3 # for create-zipball.py nette-code-checker update-php-extradeps pkgs.nodejs pkgs.phpactor - ] ++ (with php.packages; [ - composer - psalm - ]); - }; - }; - } - ); + php.packages.psalm + ]; + + languages.php = { + enable = true; + package = php; + }; + + processes.http = { + exec = "cd www; php -S localhost:8084 index.php"; + }; + + services.mysql = { + enable = true; + initialDatabases = [ + { + name = "entries"; + schema = ./install.sql; + } + ]; + }; + } + ]; + }; + } + ); + }; } diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 7f6e40e..0000000 --- a/shell.nix +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-FileCopyrightText: 2022 Jan Tojnar -# SPDX-License-Identifier: MIT - -let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - flake-compat = builtins.fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - }; - flake = import flake-compat { - src = ./.; - }; -in -flake.shellNix diff --git a/www/index.php b/www/index.php index 466a988..b112732 100644 --- a/www/index.php +++ b/www/index.php @@ -2,6 +2,13 @@ declare(strict_types=1); +if (PHP_SAPI === 'cli-server') { + $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ?: ''; + if (is_file(__DIR__ . $path)) { + return false; + } +} + require __DIR__ . '/../vendor/autoload.php'; $configurator = App\Bootstrap::boot();