From b12373a1277e22670cd47b475b861a9b589e094b Mon Sep 17 00:00:00 2001 From: Sander van der Burg Date: Thu, 17 Aug 2017 22:03:30 +0200 Subject: [PATCH] - Add note on deploying a CLI project - Fix error when a project without dependencies (and lock file) is deployed --- README.md | 35 +++++++++++++++++++++++-------- src/Composer2Nix/composer-env.nix | 27 ++++++++++++++---------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 2a9cdec..b93809c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ composer2nix ============ -`composer2nix` is a tool that can be used to generate [Nix](http://nixos.org) +`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 @@ -29,10 +29,10 @@ including its dependencies: $ nix-build -An example use case scenario -============================ -We can use `composer2nix` to automate the deployment of a web application as -part of a NixOS configuration. +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 @@ -82,9 +82,11 @@ application and its dependencies. We can use Nix to build a bundle of our web application including its dependencies: +```bash $ nix-build $ ls result/ index.php vendor/ +``` (As may be observed, the `vendor/` folder contains all dependency artifacts). @@ -115,17 +117,32 @@ in We can deploy the above NixOS configuration as follows: - $ nixos-rebuild switch +```bash +$ nixos-rebuild switch +``` If the above command succeeds, we have a running system with the Apache webserver serving our web application. +Deploying a command-line utility project +---------------------------------------- +In addition to web applications, we can also deploy command-line utility +projects implemented in PHP. + +For example, for the `composer2nix` project, we can generate a CLI-specific +expression by adding the `--executable` parameter: + + $ composer2nix --executable + +We can install the `composer2nix` executable in our Nix profile by running: + + $ nix-env -f default.nix -i + Limitations =========== Currently, the state of this tool is that it is just a proof on concept -implementation. As a result, it is lacking many features and probably buggy. -Most importantly, only the `path`, `zip`, `git`, and `hg` dependencies are -supported. +implementation. For example, it does not support downloading from `fossil` +repositories. License ======= diff --git a/src/Composer2Nix/composer-env.nix b/src/Composer2Nix/composer-env.nix index 8c6c961..7e6024c 100644 --- a/src/Composer2Nix/composer-env.nix +++ b/src/Composer2Nix/composer-env.nix @@ -57,19 +57,24 @@ rec { text = '' #! ${php}/bin/php packages, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); + print($packagesStr); + } } else - { - $config = json_decode($composerLockStr); - $packagesStr = json_encode($config->packages, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - print($packagesStr); - } + print("[]"); ?> ''; }; @@ -170,7 +175,7 @@ rec { ${stdenv.lib.optionalString (removeComposerArtifacts) '' # Remove composer stuff - rm composer.json composer.lock + rm -f composer.json composer.lock ''} ''; };