diff --git a/src/Composer2Nix/Generator.php b/src/Composer2Nix/Generator.php index c15a3b9..6523a9c 100644 --- a/src/Composer2Nix/Generator.php +++ b/src/Composer2Nix/Generator.php @@ -46,7 +46,7 @@ class Generator return "./".$target; } - private static function generatePackagesExpression($outputFile, $name, $preferredInstall, array $packages, $executable, $symlinkDependencies) + private static function generatePackagesExpression(array $config, $outputFile, $name, $preferredInstall, array $packages, $executable, $symlinkDependencies) { $handle = fopen($outputFile, "w"); @@ -136,6 +136,27 @@ class Generator $dependencies[$package["name"]] = $dependency; } + /* Compose meta properties */ + $meta = array(); + + if(array_key_exists("homepage", $config)) + $meta["homepage"] = $config["homepage"]; + + if(array_key_exists("license", $config)) + { + if(is_string($config["license"])) + $meta["license"] = $config["license"]; + else if(is_array($config["license"])) + { + if(count($config["license"]) > 0) + $meta["license"] = $config["license"][0]; + + for($i = 1; $i < count($config["license"]); $i++) + $meta["license"] .= ", ".$config["license"][$i]; + } + } + + /* Compose package function invocation */ $expr = new NixFunction(array( "composerEnv" => new NixNoDefault(), "fetchurl" => new NixNoDefault(), @@ -149,7 +170,8 @@ class Generator "src" => new NixFile("./."), "executable" => $executable, "dependencies" => new NixInherit(), - "symlinkDependencies" => $symlinkDependencies + "symlinkDependencies" => $symlinkDependencies, + "meta" => new NixAttrSet($meta) )))); $exprStr = NixGenerator::phpToNix($expr, true); @@ -240,7 +262,7 @@ class Generator $packages = array(); /* Generate packages expression */ - Generator::generatePackagesExpression($outputFile, $name, $preferredInstall, $packages, $executable, $symlinkDependencies); + Generator::generatePackagesExpression($config, $outputFile, $name, $preferredInstall, $packages, $executable, $symlinkDependencies); /* Generate composition expression */ Generator::generateCompositionExpression($compositionFile, $outputFile, $composerEnvFile); diff --git a/src/Composer2Nix/composer-env.nix b/src/Composer2Nix/composer-env.nix index a588968..52101a1 100644 --- a/src/Composer2Nix/composer-env.nix +++ b/src/Composer2Nix/composer-env.nix @@ -49,7 +49,7 @@ rec { ''; }; - buildPackage = { name, src, dependencies ? [], symlinkDependencies ? false, executable ? false, removeComposerArtifacts ? false, postInstall ? ""}@args: + buildPackage = { name, src, dependencies ? [], symlinkDependencies ? false, executable ? false, removeComposerArtifacts ? false, postInstall ? "", ...}@args: let reconstructInstalled = writeTextFile { name = "reconstructinstalled.php"; @@ -113,7 +113,7 @@ rec { if(array_key_exists("bin", $config)) { mkdir("vendor/".$binDir); - + foreach($config["bin"] as $bin) symlink("../../".$bin, "vendor/".$binDir."/".basename($bin)); } @@ -186,7 +186,30 @@ rec { ${stdenv.lib.optionalString executable '' ${constructBin} composer.json ln -s $(pwd)/vendor/bin $out/bin - patchShebangs $out/bin + ''} + + ${stdenv.lib.optionalString (!symlinkDependencies) '' + # Patch the shebangs if possible + if [ -d $out/bin ] + then + # Look for all executables in bin/ + for i in $out/bin/* + do + # Look for their location + realFile=$(readlink -f "$i") + + # Restore write permissions + chmod u+wx "$(dirname "$realFile")" + chmod u+w "$realFile" + + # Patch shebang + sed -e "s|#!/usr/bin/php|#!${php}/bin/php|" \ + -e "s|#!/usr/bin/env php|#!${php}/bin/php|" \ + "$realFile" > tmp + mv tmp "$realFile" + chmod u+x "$realFile" + done + fi ''} ${stdenv.lib.optionalString (removeComposerArtifacts) ''