From 5f9a7bfbd59a6aa2444445e69b9ff711de9b29a6 Mon Sep 17 00:00:00 2001 From: John Boehr Date: Sun, 7 Apr 2024 11:00:59 -0700 Subject: [PATCH] Update to nixos 23.11 --- .envrc | 1 + .github/workflows/ci.yml | 77 +++++++++---- .gitignore | 1 + default.nix | 65 ----------- flake.lock | 226 ++++++++++++++++++++++++++++++--------- flake.nix | 214 +++++++++++++++++++++++++++++------- nix/ci.nix | 75 ------------- nix/derivation.nix | 79 +++++++------- 8 files changed, 448 insertions(+), 290 deletions(-) create mode 100644 .envrc delete mode 100644 default.nix delete mode 100644 nix/ci.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3032018..d7b0dbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,8 +5,7 @@ on: branches: - master - dev-1.x - - github-actions - - ci + - develop pull_request: branches: - master @@ -108,26 +107,62 @@ jobs: TEST_PHP_EXECUTABLE: /usr/bin/php run: bash ./.github/scripts/docker.sh - nix: + nix-matrix: runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - uses: cachix/install-nix-action@v18 - with: - nix_path: nixpkgs=channel:nixos-22.05 - - run: nix-build - - run: nix-build nix/ci.nix + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v26 + - id: set-matrix + name: Generate Nix Matrix + run: | + set -Eeu + matrix="$(nix eval --json '.#githubActions.matrix')" + echo "matrix=$matrix" >> "$GITHUB_OUTPUT" - nix-flake: - runs-on: ubuntu-latest + nix: + name: "nix (${{ matrix.name }})" + runs-on: ${{ matrix.os }} + needs: nix-matrix + strategy: + matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}} steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - uses: cachix/install-nix-action@v18 - with: - nix_path: nixpkgs=channel:nixos-22.05 - - run: nix build - - run: nix flake check + - uses: actions/checkout@v4 + + - name: Set Up Build Cache + uses: actions/cache@v4 + id: nix-cache + with: + path: /tmp/nix-store.nar + key: nix-store.nar-${{ runner.os }}-${{ hashFiles('flake.lock') }}-${{ matrix.attr }} + restore-keys: | + nix-store.nar-${{ runner.os }}-${{ hashFiles('flake.lock') }}-${{ matrix.attr }} + nix-store.nar-${{ runner.os }}-${{ hashFiles('flake.lock') }}- + nix-store.nar-${{ runner.os }}- + + - uses: cachix/install-nix-action@v26 + with: + nix_path: nixpkgs=channel:nixos-23.11 + extra_nix_config: "system-features = nixos-test benchmark big-parallel kvm" + + - name: Import Nix Store Cache + if: "steps.nix-cache.outputs.cache-hit == 'true'" + run: | + nix-store --import < /tmp/nix-store.nar + + - run: sudo sysctl -w kernel.perf_event_paranoid=1 + + - run: nix build -L ".#${{ matrix.attr }}" + + - name: Export Nix Store Cache + shell: bash + # partially based on https://github.com/NixOS/nix/issues/1245#issuecomment-282586759 + run: | + drv="$(nix-store -qd "$(readlink result)")" + drvRefs="$( echo "$drv" | xargs nix-store -q --references )" + ( echo "$drvRefs" | grep '[.]drv$' | xargs nix-store -q --outputs ; + echo "$drvRefs" | grep -v '[.]drv$' ) | \ + xargs nix-store -r | \ + xargs nix-store -qR | + xargs nix-store --export > /tmp/nix-store.nar diff --git a/.gitignore b/.gitignore index 5e03d73..7d8e21c 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ configure.in coverage.info *.dep .deps +.direnv .dirstamp gmon* .idea diff --git a/default.nix b/default.nix deleted file mode 100644 index d392747..0000000 --- a/default.nix +++ /dev/null @@ -1,65 +0,0 @@ -# when using nix-shell, run "configurePhase" otherwise you'll have missing headers -# to use a specific version of php, run `nix-shell --arg php '(import {}).php73'` -# or clang: nix-shell --arg stdenv '(import {}).clangStdenv' -{ pkgs ? import { } -, stdenv ? pkgs.stdenv -, php ? pkgs.php -, buildPecl ? php.buildPecl -, gitignoreSource ? (import - (pkgs.fetchFromGitHub { - owner = "hercules-ci"; - repo = "gitignore"; - rev = "00b237fb1813c48e20ee2021deb6f3f03843e9e4"; - sha256 = "sha256:186pvp1y5fid8mm8c7ycjzwzhv7i6s3hh33rbi05ggrs7r3as3yy"; - }) - { inherit (pkgs) lib; }).gitignoreSource -, mustache_spec ? pkgs.callPackage - (import ( - (fetchTarball { - url = "https://github.com/jbboehr/mustache-spec/archive/18cca097c306e8cbfd9f6a30f86a52f4c1d219e4.tar.gz"; - sha256 = "0xg9x2adbvp565imza0hg622qm2hdy0w3z944krv1f3bjs7332wi"; - }) - )) - { } -, handlebars_spec ? pkgs.callPackage - (import ( - (fetchTarball { - url = "https://github.com/jbboehr/handlebars-spec/archive/289859aba16bc9e63d5b05ce176b777cb67700dc.tar.gz"; - sha256 = "1rsapj9d37srynvjlg89ww9lyci1bv9ysi0baqqgj45sp87fw6yc"; - }) - )) - { } -, handlebarsc ? pkgs.callPackage - (import (fetchTarball { - url = "https://github.com/jbboehr/handlebars.c/archive/v1.0.0.tar.gz"; - sha256 = "027f1h65nam3wpvd1qfah4j9m21q299wwya2m13f0fwm5qxbd0s3"; - })) - { - inherit stdenv; - inherit mustache_spec handlebars_spec; - inherit debugSupport devSupport hardeningSupport ltoSupport valgrindSupport WerrorSupport; - sharedSupport = (!staticSupport && !ltoSupport); - staticSupport = (ltoSupport || staticSupport); - } -, php_psr ? pkgs.callPackage - (import (fetchTarball { - url = "https://github.com/jbboehr/php-psr/archive/a46f438d0e2669ad56ffe859650ef0be10fc5e91.tar.gz"; - sha256 = "0q18038qyqn6rzdyljhxla3qmixaspbwi6981q929qnp2bx69ggx"; - })) - { inherit buildPecl stdenv php; } -, astSupport ? false -, checkSupport ? true -, debugSupport ? false -, devSupport ? false -, ltoSupport ? false -, hardeningSupport ? true -, psrSupport ? true -, WerrorSupport ? (debugSupport || devSupport) -, valgrindSupport ? (debugSupport || devSupport) -, staticSupport ? false -}: - -pkgs.callPackage ./nix/derivation.nix { - inherit stdenv php buildPecl gitignoreSource handlebars_spec mustache_spec handlebarsc php_psr; - inherit astSupport checkSupport debugSupport devSupport hardeningSupport psrSupport valgrindSupport WerrorSupport; -} diff --git a/flake.lock b/flake.lock index 9640212..8d80af6 100644 --- a/flake.lock +++ b/flake.lock @@ -19,11 +19,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1668681692, - "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", "owner": "edolstra", "repo": "flake-compat", - "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "type": "github" }, "original": { @@ -35,11 +35,11 @@ "flake-compat_2": { "flake": false, "locked": { - "lastModified": 1668681692, - "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", "owner": "edolstra", "repo": "flake-compat", - "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "type": "github" }, "original": { @@ -49,12 +49,17 @@ } }, "flake-utils": { + "inputs": { + "systems": [ + "systems" + ] + }, "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -64,12 +69,18 @@ } }, "flake-utils_2": { + "inputs": { + "systems": [ + "handlebars-c", + "systems" + ] + }, "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -79,12 +90,15 @@ } }, "flake-utils_3": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -139,12 +153,15 @@ } }, "flake-utils_7": { + "inputs": { + "systems": "systems_3" + }, "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -160,11 +177,11 @@ ] }, "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", "owner": "hercules-ci", "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { @@ -181,11 +198,11 @@ ] }, "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", "owner": "hercules-ci", "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { @@ -203,11 +220,11 @@ ] }, "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", "owner": "hercules-ci", "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { @@ -245,11 +262,11 @@ ] }, "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", "owner": "hercules-ci", "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { @@ -268,17 +285,19 @@ "mustache_spec": [ "mustache_spec" ], + "nix-github-actions": "nix-github-actions", "nixpkgs": [ "nixpkgs" ], - "pre-commit-hooks": "pre-commit-hooks" + "pre-commit-hooks": "pre-commit-hooks", + "systems": "systems_2" }, "locked": { - "lastModified": 1671993884, - "narHash": "sha256-TkwvdypKhGoY5U2sgbOBIHo/rvbN/Ngs6pFon8fI1iA=", + "lastModified": 1712510613, + "narHash": "sha256-M1lCAooWD3LVrxkeoLt3ckmW6lSGUGbQIcH8t7AuA6w=", "owner": "jbboehr", "repo": "handlebars.c", - "rev": "6ec01529dba20568d95450776bee967e58ce4bec", + "rev": "3467eec4d7db03f7c0191e378b330e1c18a1dd44", "type": "github" }, "original": { @@ -329,13 +348,54 @@ "type": "github" } }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "handlebars-c", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703863825, + "narHash": "sha256-rXwqjtwiGKJheXB43ybM8NwWB8rO2dSRrEqes0S7F5Y=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "5163432afc817cf8bd1f031418d1869e4c9d5547", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, + "nix-github-actions_2": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703863825, + "narHash": "sha256-rXwqjtwiGKJheXB43ybM8NwWB8rO2dSRrEqes0S7F5Y=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "5163432afc817cf8bd1f031418d1869e4c9d5547", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1671994277, - "narHash": "sha256-HwVpFVppZWKKuCs6Sfah38aGRMuBokYANd7MMAU/saE=", + "lastModified": 1712510854, + "narHash": "sha256-5grEixAy6uUMFKE8w1c54iBg8BeLzz4HdPNRD4tN3HQ=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2cfb9ab1268806616dbf07ae2fc8d72e66837237", + "rev": "0f58ce3b44a0b4c8a95034af8a45c0061c01d766", "type": "github" }, "original": { @@ -346,32 +406,32 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1671271954, - "narHash": "sha256-cSvu+bnvN08sOlTBWbBrKaBHQZq8mvk8bgpt0ZJ2Snc=", + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d513b448cc2a6da2c8803e3c197c9fc7e67b19e3", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-22.05", + "ref": "nixos-23.11", "repo": "nixpkgs", "type": "github" } }, "nixpkgs-stable_2": { "locked": { - "lastModified": 1671271954, - "narHash": "sha256-cSvu+bnvN08sOlTBWbBrKaBHQZq8mvk8bgpt0ZJ2Snc=", + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d513b448cc2a6da2c8803e3c197c9fc7e67b19e3", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-22.05", + "ref": "nixos-23.11", "repo": "nixpkgs", "type": "github" } @@ -411,11 +471,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1671452357, - "narHash": "sha256-HqzXiQEegpRQ4VEl9pEPgHSIxhJrNJ27HfN1wOc7w2E=", + "lastModified": 1712055707, + "narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "200790e9c77064c53eaf95805b013d96615ecc27", + "rev": "e35aed5fda3cc79f88ed7f1795021e559582093a", "type": "github" }, "original": { @@ -435,11 +495,11 @@ "nixpkgs-stable": "nixpkgs-stable_2" }, "locked": { - "lastModified": 1671452357, - "narHash": "sha256-HqzXiQEegpRQ4VEl9pEPgHSIxhJrNJ27HfN1wOc7w2E=", + "lastModified": 1712055707, + "narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "200790e9c77064c53eaf95805b013d96615ecc27", + "rev": "e35aed5fda3cc79f88ed7f1795021e559582093a", "type": "github" }, "original": { @@ -455,9 +515,71 @@ "handlebars-c": "handlebars-c", "handlebars_spec": "handlebars_spec", "mustache_spec": "mustache_spec", + "nix-github-actions": "nix-github-actions_2", "nixpkgs": "nixpkgs", "php-psr": "php-psr", - "pre-commit-hooks": "pre-commit-hooks_2" + "pre-commit-hooks": "pre-commit-hooks_2", + "systems": "systems_4" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 48bba43..3b1af18 100644 --- a/flake.nix +++ b/flake.nix @@ -3,8 +3,10 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs"; + systems.url = "github:nix-systems/default"; flake-utils = { url = "github:numtide/flake-utils"; + inputs.systems.follows = "systems"; }; mustache_spec = { url = "github:jbboehr/mustache-spec"; @@ -32,67 +34,201 @@ url = "github:cachix/pre-commit-hooks.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + nix-github-actions = { + url = "github:nix-community/nix-github-actions"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = { self, nixpkgs, flake-utils, mustache_spec, handlebars_spec, handlebars-c, php-psr, gitignore, pre-commit-hooks }@args: - flake-utils.lib.eachDefaultSystem (system: - let + outputs = { + self, + nixpkgs, + flake-utils, + mustache_spec, + handlebars_spec, + handlebars-c, + php-psr, + gitignore, + pre-commit-hooks, + nix-github-actions, + ... + } @ args: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = nixpkgs.legacyPackages.${system}; + lib = pkgs.lib; php = pkgs.php; + src' = gitignore.lib.gitignoreSource ./.; src = pkgs.lib.cleanSourceWith { - filter = (path: type: (builtins.all (x: x != baseNameOf path) - [ ".idea" ".git" "nix" "ci.nix" ".travis.sh" ".travis.yml" ".github" "flake.nix" "flake.lock" ])); - src = gitignore.lib.gitignoreSource ./.; + name = "php-handlebars-source"; + src = src'; + filter = gitignore.lib.gitignoreFilterWith { + basePath = ./.; + extraRules = '' + .clang-format + composer.json + composer.lock + .editorconfig + .envrc + .gitattributes + .github + .gitignore + *.md + *.nix + flake.* + ''; + }; }; pre-commit-check = pre-commit-hooks.lib.${system}.run { - inherit src; + src = src'; hooks = { - #editorconfig-checker.enable = true; + alejandra.enable = true; #markdownlint.enable = true; - nixpkgs-fmt.enable = true; + #shellcheck.enable = true; }; }; - in - rec { - packages = flake-utils.lib.flattenTree rec { - php-handlebars = pkgs.callPackage ./nix/derivation.nix { + + makePackage = { + stdenv ? pkgs.stdenv, + php ? pkgs.php, + astSupport ? false, + }: + pkgs.callPackage ./nix/derivation.nix { + inherit src; + inherit stdenv php; + buildPecl = pkgs.callPackage (nixpkgs + "/pkgs/build-support/php/build-pecl.nix") { + inherit php stdenv; + }; + inherit (gitignore.lib) gitignoreSource; mustache_spec = mustache_spec.packages.${system}.mustache-spec; handlebars_spec = handlebars_spec.packages.${system}.handlebars-spec; handlebarsc = handlebars-c.packages.${system}.handlebars-c; php_psr = args.php-psr.packages.${system}.php-psr; - inherit (gitignore.lib) gitignoreSource; - inherit php; - inherit (php) buildPecl; }; - php-handlebars-dist = pkgs.runCommand "handlebars-pecl.tgz" - { - buildInputs = [ php ]; - src = php-handlebars.src; - } '' - cp -r $src/* . - PHP_PEAR_PHP_BIN=${php}/bin/php pecl package - mv handlebars-*.tgz $out - ''; - default = php-handlebars; - }; - devShells.default = pkgs.mkShell { - inputsFrom = builtins.attrValues self.packages.${system}; - buildInputs = with pkgs; [ nixpkgs-fmt pre-commit editorconfig-checker ]; - shellHook = '' - ${pre-commit-check.shellHook} - ''; + makeCheck = package: + package.override { + checkSupport = true; + WerrorSupport = true; + }; + + makeDevShell = package: + (pkgs.mkShell.override { + stdenv = package.stdenv; + }) { + inputsFrom = [package]; + buildInputs = with pkgs; [ + actionlint + autoconf-archive + clang-tools + lcov + gdb + package.php.packages.composer + pre-commit + valgrind + ]; + shellHook = '' + ${pre-commit-check.shellHook} + mkdir -p .direnv/include + unlink .direnv/include/php + ln -sf ${package.php.unwrapped.dev}/include/php/ .direnv/include/php + export REPORT_EXIT_STATUS=1 + export NO_INTERACTION=1 + export PATH="$PWD/vendor/bin:$PATH" + ''; + }; + + matrix = with pkgs; { + php = { + inherit php81 php82 php83; + }; + stdenv = { + gcc = stdenv; + clang = clangStdenv; + # totally broken + #musl = pkgsMusl.stdenv; + }; }; - checks = { - # @todo we could move/copy everything in nix/ci.nix here - inherit pre-commit-check; - inherit (packages) default; + # @see https://github.com/NixOS/nixpkgs/pull/110787 + buildConfs = lib.cartesianProductOfSets { + php = ["php81" "php82" "php83"]; + stdenv = [ + "gcc" + "clang" + # totally broken + # "musl" + ]; + astSupport = [true false]; }; - formatter = pkgs.nixpkgs-fmt; + buildFn = { + php, + stdenv, + astSupport ? false, + }: + lib.nameValuePair + (lib.concatStringsSep "-" (lib.filter (v: v != "") [ + "${php}" + "${stdenv}" + ( + if astSupport + then "ast" + else "" + ) + ])) + ( + makePackage { + php = matrix.php.${php}; + stdenv = matrix.stdenv.${stdenv}; + inherit astSupport; + } + ); + + packages = builtins.listToAttrs (builtins.map buildFn buildConfs); + in { + packages = + packages + // { + default = packages.php81-gcc; + php-handlebars = packages.php81-gcc; # old package name + php-handlebars-dist = + pkgs.runCommand "handlebars-pecl.tgz" + { + buildInputs = [php]; + inherit src; + } '' + cp -r $src/* . + PHP_PEAR_PHP_BIN=${php}/bin/php pecl package + mv handlebars-*.tgz $out + ''; + }; + + devShells = builtins.mapAttrs (name: package: makeDevShell package) (packages + // { + default = packages.php81-gcc; + }); + + checks = + {inherit pre-commit-check;} + // (builtins.mapAttrs (name: package: makeCheck package) packages); + + formatter = pkgs.alejandra; } - ); + ) + // { + # prolly gonna break at some point + githubActions.matrix.include = let + cleanFn = v: v // {name = builtins.replaceStrings ["githubActions." "checks." "x86_64-linux."] ["" "" ""] v.attr;}; + in + builtins.map cleanFn + (nix-github-actions.lib.mkGithubMatrix { + attrPrefix = "checks"; + checks = nixpkgs.lib.getAttrs ["x86_64-linux"] self.checks; + }) + .matrix + .include; + }; } diff --git a/nix/ci.nix b/nix/ci.nix deleted file mode 100644 index 1a6f401..0000000 --- a/nix/ci.nix +++ /dev/null @@ -1,75 +0,0 @@ -let - generateHandlebarsTestsForPlatform = { pkgs, phpAttr }: - pkgs.recurseIntoAttrs { - # std - std = - let - php = pkgs.${phpAttr}; - in - pkgs.callPackage ../default.nix { - inherit php; - inherit (php) buildPecl; - astSupport = false; - }; - # i686 - # i686 = let - # php = pkgs.pkgsi686Linux.${phpAttr}; - # in pkgs.pkgsi686Linux.callPackage ../default.nix { - # inherit php; - # inherit (php) buildPecl; - # astSupport = true; - # }; - # ast - ast = - let - php = pkgs.${phpAttr}; - in - pkgs.callPackage ../default.nix { - inherit php; - inherit (php) buildPecl; - astSupport = true; - }; - # clang - clang = - let - php = pkgs.${phpAttr}; - stdenv = pkgs.clangStdenv; - in - pkgs.callPackage ../default.nix { - inherit stdenv php; - inherit (php) buildPecl; - astSupport = true; - }; - }; -in -builtins.mapAttrs - (k: _v: - let - path = builtins.fetchTarball { - url = https://github.com/NixOS/nixpkgs/archive/nixos-22.05.tar.gz; - name = "nixos-22.05"; - }; - pkgs = import (path) { system = k; }; - in - pkgs.recurseIntoAttrs { - php74 = generateHandlebarsTestsForPlatform { - inherit pkgs; - phpAttr = "php74"; - }; - - php80 = generateHandlebarsTestsForPlatform { - inherit pkgs; - phpAttr = "php80"; - }; - - php81 = generateHandlebarsTestsForPlatform { - inherit pkgs; - phpAttr = "php81"; - }; - } - ) -{ - x86_64-linux = { }; - # Uncomment to test build on macOS too - # x86_64-darwin = {}; -} diff --git a/nix/derivation.nix b/nix/derivation.nix index 80dd916..b973d61 100644 --- a/nix/derivation.nix +++ b/nix/derivation.nix @@ -1,47 +1,51 @@ -{ lib -, php -, stdenv -, autoreconfHook -, fetchurl -, talloc -, pcre -, pcre2 -, buildPecl -, handlebarsc -, gitignoreSource -, valgrind ? null -, php_psr ? null -, handlebars_spec ? null -, mustache_spec ? null -, astSupport ? false -, checkSupport ? true -, debugSupport ? false -, devSupport ? false -, hardeningSupport ? true -, psrSupport ? true -, WerrorSupport ? (debugSupport || devSupport) -, valgrindSupport ? (debugSupport || devSupport) +{ + lib, + php, + stdenv, + autoreconfHook, + fetchurl, + talloc, + pcre, + pcre2, + buildPecl, + handlebarsc, + gitignoreSource, + valgrind ? null, + php_psr ? null, + handlebars_spec ? null, + mustache_spec ? null, + astSupport ? false, + checkSupport ? true, + debugSupport ? false, + devSupport ? false, + hardeningSupport ? true, + psrSupport ? true, + WerrorSupport ? (debugSupport || devSupport), + valgrindSupport ? (debugSupport || devSupport), + src, }: - buildPecl rec { pname = "handlebars"; name = "handlebars-${version}"; version = "v1.0.0"; - src = lib.cleanSourceWith { - filter = (path: type: (builtins.all (x: x != baseNameOf path) - [ ".idea" ".git" ".github" "ci.nix" ".ci" "nix" "default.nix" "flake.nix" "flake.lock" ])); - src = gitignoreSource ../.; + inherit src; + + passthru = { + inherit stdenv php; }; - buildInputs = [ handlebarsc talloc pcre pcre2 ] + buildInputs = + [handlebarsc talloc pcre pcre2] ++ lib.optional valgrindSupport valgrind - ++ lib.optional psrSupport php_psr - ; + ++ lib.optional psrSupport php_psr; - nativeBuildInputs = lib.optionals checkSupport [ handlebars_spec mustache_spec ]; + nativeBuildInputs = + [php.unwrapped.dev] + ++ lib.optionals checkSupport [handlebars_spec mustache_spec]; - configureFlags = [ ] + configureFlags = + [] ++ lib.optional astSupport "--enable-handlebars-ast" ++ lib.optional (!astSupport) "--disable-handlebars-ast" ++ lib.optional hardeningSupport "--enable-handlebars-hardening" @@ -49,10 +53,9 @@ buildPecl rec { ++ lib.optional psrSupport "--enable-handlebars-psr" ++ lib.optional (!psrSupport) "--disable-handlebars-psr" ++ lib.optional WerrorSupport "--enable-compile-warnings=error" - ++ lib.optionals (!WerrorSupport) [ "--enable-compile-warnings=yes" "--disable-Werror" ] - ; + ++ lib.optionals (!WerrorSupport) ["--enable-compile-warnings=yes" "--disable-Werror"]; - makeFlags = [ "phpincludedir=$(out)/include/php/ext/handlebars" ]; + makeFlags = ["phpincludedir=$(out)/include/php/ext/handlebars"]; preBuild = lib.optionalString checkSupport '' HANDLEBARS_SPEC_DIR="${handlebars_spec}/share/handlebars-spec" \ @@ -61,6 +64,6 @@ buildPecl rec { ''; doCheck = checkSupport; - checkTarget = "test"; - checkFlags = [ "REPORT_EXIT_STATUS=1" "NO_INTERACTION=1" ]; + #checkTarget = "test"; + #checkFlags = ["REPORT_EXIT_STATUS=1" "NO_INTERACTION=1"]; }