Giter VIP home page Giter VIP logo

nix-shell's Introduction

GitHub stars Donate!

Nix shell

Tutorial

Description

This package provides a Nix flake ready to use for PHP development, using the Nix package manager which can be installed on (almost) any operating system.

Each available environment provides the following tools:

  • Composer,
  • Symfony CLI,
  • SQLite

Available stable PHP versions from 5.6 to 8.3. But also weekly builds from the following branches:

  • PHP-8.1
  • PHP-8.2
  • PHP-8.3
  • master (future 8.4)

To list the available PHP versions, run:

nix flake show github:loophp/nix-shell

The PHP extensions to use are automatically inferred from the composer.json file.

...8<...

"require": {
  "ext-intl": "*",
},
"require-dev": {
  "ext-xdebug": "*",
  "ext-pcov": "*",
}

...>8...

To load extensions from the require and required-dev sections, using the flag --impure is required. Example:

nix shell github:loophp/nix-shell#php82 --impure

We use Cachix to store binaries of the built packages. Install it as described in its docs and then add the cache using cachix use nix-shell if you want to avoid building those PHP packages yourself.

cachix use nix-shell
cachix use php-src-nix

This project also provides a basic template for PHP projects, to use it, run:

nix flake init --template github:loophp/nix-shell#basic

Usage

While being extremely stable for years, "flake" is an upcoming feature of the Nix package manager. In order to use it, you must explicitly enable it, please check the documentation to enable it, this is currently an opt-in option.

In a shell

To work with PHP 8.1 only:

nix shell github:loophp/nix-shell#php81

or with PHP 8.1 and a couple of useful tools:

nix shell github:loophp/nix-shell#env-php81

Since the 14th of November 2022, PHP is in NTS mode by default (see #154774).

To list the available PHP versions and environments, run:

nix flake show github:loophp/nix-shell

In another flake

Step 1

Import the input:

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    phps.url = "github:loophp/nix-shell";
  };
Step 2

Import the overlay:

pkgs = import inputs.nixpkgs {
    inherit system;
    overlays = [
        inputs.phps.overlays.default
    ];
};
Step 3

Use the packages:

    # PHP 8.1 environment
    pkgs.env-php81

To create your own version of PHP, use the available API function buildPhpFromComposer.

With direnv

direnv is an extension for your shell. It augments existing shells with a new feature that can load and unload environment variables depending on the current directory. You can use it within Nix (nix-direnv) and load a development environment just by changing directory.

Edit the file .envrc and add the following line:

use flake github:loophp/nix-shell#env-php-master-snapshot --impure

And it's done.

Customize PHP

To customize the PHP configuration, you can do it like this:

nix shell github:loophp/nix-shell#php81
php -c /path/to/the/config.ini <<command>>

Another option would be to create a .user.ini file within your current working directory before running the PHP environment, as such:

max_execution_time = 0
memory_limit = 2048M

Then run:

nix shell github:loophp/nix-shell#php82 --impure

The --impure flag is important to make sure that your custom .user.ini file is correctly taken in account.

Contributing

Feel free to contribute by sending pull requests. We are a usually very responsive team and we will help you going through your pull request from the beginning to the end.

For some reasons, if you can't contribute to the code and are willing to help, sponsoring is a good, sound, and safe way to show us some gratitude for the hours we invested in this package.

Sponsor me on Github and/or any of the contributors.

Thanks

Changelog

See CHANGELOG.md for a changelog based on git commits.

For more detailed changelogs, please check the release changelogs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.