Home

Awesome

composer-plugin-nixify

Generates a Nix expression to build a Composer project.

Related projects:

Usage

The Nixify plugin should work fine with Composer versions all the way back to 1.3.0, and also supports Composer 2.0.

To use the plugin:

# Install the plugin
composer require stephank/composer-plugin-nixify

# Build your project with Nix
nix-build

Running Composer with this plugin enabled will generate two files:

This may already build successfully! But if your project needs extra build steps, you may have to customize default.nix a bit. Some examples of what's possible:

{ pkgs ? import <nixpkgs> { } }:

let

  # Example of providing a different source tree.
  src = pkgs.lib.cleanSource ./.;

  project = pkgs.callPackage ./composer-project.nix {

    # Example of selecting a specific version of PHP.
    php = pkgs.php74;

  } src;

in project.overrideAttrs (oldAttrs: {

  # Example of overriding the default package name taken from composer.json.
  name = "myproject";

  # Example of adding packages to the build environment.
  buildInputs = oldAttrs.buildInputs ++ [ pkgs.imagemagick ];

  # Example of invoking a build step in your project.
  buildPhase = ''
    composer run lint
  '';

})

Settings

Some additional settings are available which can be set in the "extra" object in your composer.json: