PHPackages                             svanderburg/composer2nix - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. svanderburg/composer2nix

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

svanderburg/composer2nix
========================

Generate Nix expressions to build PHP composer packages

v0.0.6(4y ago)925.5k↓30%27[10 issues](https://github.com/svanderburg/composer2nix/issues)[4 PRs](https://github.com/svanderburg/composer2nix/pulls)MITNixCI passing

Since Oct 2Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/svanderburg/composer2nix)[ Packagist](https://packagist.org/packages/svanderburg/composer2nix)[ RSS](/packages/svanderburg-composer2nix/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (8)Used By (0)

composer2nix
============

[](#composer2nix)

`composer2nix` is a tool that can be used to generate [Nix](http://nixos.org/nix)expressions for PHP [composer](https://getcomposer.org) packages.

Nix integration makes it possible to use the Nix package manager (as opposed to composer) to deploy PHP packages including all their required dependencies.

In addition, generated Nix composer packages support convenient integration of PHP applications with NixOS services, such as NixOS' Apache HTTP service.

Prerequisites
=============

[](#prerequisites)

This package requires the following packages to be installed:

- [Nix package manager](http://nixos.org/nix)
- The Nix prefetch scripts. They can be installed from Nix packages by running:

```
$ nix-env -f '' -iA nix-prefetch-scripts
```

Consult the Nix documentation for detailed installation instructions.

Installation
============

[](#installation)

This package can be installed with both `composer` and the Nix package manager. To install it with composer, run:

```
$ composer global require svanderburg/composer2nix
```

To install this package with Nix, clone the Git repository and run:

```
$ nix-env -f release.nix -iA package.x86_64-linux
```

Building a development version
==============================

[](#building-a-development-version)

A development version can be deployed by checking out the Git repository and running:

```
$ nix-env -f release.nix -iA package.x86_64-linux
```

The above command installs the development `composer2nix` executable into the Nix profile of the user.

Alternatively, you can use `composer` directly to install the project dependencies:

```
$ composer install
```

Usage
=====

[](#usage)

You need a project providing a `composer.json` and (if applicable) a `composer.lock` configuration file.

Running the following command generates Nix expressions from the composer configuration files:

```
$ composer2nix
```

The above command produces three expressions: `php-packages.nix` containing the dependencies, `composer-env.nix` the build infrastructure and `default.nix` that can be used to compose the package from its dependencies.

Running the following command-line instruction deploys the package with Nix including its dependencies:

```
$ nix-build
```

Deploying a web application project
-----------------------------------

[](#deploying-a-web-application-project)

We can use `composer2nix` to automate the deployment of a web application project as part of a NixOS configuration.

For example, we can create the following trivial PHP web application (`index.php`) that uses the [dompdf](http://dompdf.github.io/) library to generate a PDF file from an HTML page:

```
