Skip to content

Instantly share code, notes, and snippets.

@3noch
Created March 28, 2017 21:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3noch/79255f8c5ec3c287b91b7484265a89a8 to your computer and use it in GitHub Desktop.
Save 3noch/79255f8c5ec3c287b91b7484265a89a8 to your computer and use it in GitHub Desktop.
PHP with configuration in Nix
{ pkgs ? import <nixpkgs> {}
, phpPackage ? pkgs.php
, phpPackages ? pkgs.phpPackages
, opCache ? false
, showErrors ? false
, extensions ? []
, zendExtensions ? []
, extraConfig ? ""
}:
let
includePackage = directive: packageName: "${directive} = ${phpPackages.${packageName}}/lib/php/extensions/${packageName}.so";
phpIni = ''
${pkgs.lib.optionalString opCache ''
; WARNING: Be sure to load opcache *before* xdebug (http://us3.php.net/manual/en/opcache.installation.php).
zend_extension = "${phpPackage}/lib/php/extensions/opcache.so"
''}
${pkgs.lib.concatMapStringsSep "\n" (includePackage "extension") (extensions)}
${pkgs.lib.concatMapStringsSep "\n" (includePackage "zend_extension") (zendExtensions)}
${pkgs.lib.optionalString showErrors ''
error_reporting = E_ALL
display_errors = On
''}
${extraConfig}
'';
customPhpIniDir = pkgs.writeTextDir "php.ini" phpIni;
in pkgs.writeScriptBin "php" ''
#!${pkgs.bash}/bin/bash
export PHP_INI_SCAN_DIR=$PHP_INI_SCAN_DIR:'${phpPackage}/etc':'${customPhpIniDir}'
${phpPackage}/bin/php "$@"
''
@3noch
Copy link
Author

3noch commented Mar 28, 2017

Example usage:

import ./phpWith.nix {
  showErrors     = true;
  extensions     = ["imagick"];
  zendExtensions = ["xdebug"];
  extraConfig    = ''
    [XDebug]
    xdebug.remote_enable = 1
    xdebug.remote_autostart = 1
  '';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment