Running PHP Composer in a derivation failed

Hello, I’m trying to make a derivation that builds my PHP (Laravel) application.
Here’s the code of one of my attampts:

{ stdenvNoCC, php83 }: stdenvNoCC.mkDerivation (finalAttrs:
let
    php' = php83.withExtensions ({ enabled, all }: enabled );
in {
    pname =  "yota-laravel";
    version = "2.0.0";

    src = ./.;

    nativeBuildInputs = [
        php'
        php'.packages.composer
    ];

    buildInputs = [
        php'
    ];

    COMPOSER_CACHE_DIR = "/dev/null";
    COMPOSER_MIRROR_PATH_REPOS = "1";
    COMPOSER_HTACCESS_PROTECT = "0";
    COMPOSER_DISABLE_NETWORK = "0";

    buildPhase = ''
        composer --no-ansi --no-interaction --no-dev --no-plugins --no-scripts install
        php artisan config:cache
        php artisan route:cache
        php artisan view:cache
    '';

    installPhase = ''
        mkdir $out
        cp -r . $out
    '';
})

It took 4m55s and it failed with the following log output:

...
  - Installing nikic/php-parser (v5.0.2): Cloning 139676794d
    Install of nikic/php-parser failed
  - Installing psy/psysh (v0.12.3): Cloning b6b6cce7d3
    Install of psy/psysh failed
  - Installing laravel/tinker (v2.9.0): Cloning 502e0fe3f0
    Install of laravel/tinker failed

In Git.php line 472:
                                                                               
  Failed to clone https://github.com/doctrine/deprecations.git via https, ssh  
   protocols, aborting.                                                        
                                                                               
  - https://github.com/doctrine/deprecations.git                               
    Cloning into '/build/4g3hx676n3s5r809i1lql6d22x04h42g-source/vendor/doctr  
  ine/deprecations'...                                                         
    fatal: unable to access 'https://github.com/doctrine/deprecations.git/':   
  Could not resolve host: github.com                                           
                                                                               
  - git@github.com:doctrine/deprecations.git                                   
    Cloning into '/build/4g3hx676n3s5r809i1lql6d22x04h42g-source/vendor/doctr  
  ine/deprecations'...                                                         
    error: cannot run ssh: No such file or directory                           
    fatal: unable to fork                                                      

You don’t have internet access in the build sandbox and cannot run commands that need to download things unless they are a fixed output derivation (FOD).

1 Like

Maybe this will help?

https://nixos.org/manual/nixpkgs/stable/#ssec-building-php-projects

1 Like

Actually, I first tried using buildComposerProject and mkComposerRepository, but didn’t succeed.
I also posted questions regarding the respective issues I had here: :sweat_smile: