buildComposerProject - failed to open autoload.php

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

{ php83 }: php83.buildComposerProject (finalAttrs: {
    pname =  "yota-laravel";
    version = "2.0.0";
    src = ./.;
    php = php83.buildEnv {
        extensions = ( { enabled, all }: enabled );
    composerLock = ./composer.lock;
    vendorHash = "sha256-vYuWiX3YxS6ZZ3ngsYDuR6ydggBBwBG8K+KRBP8UqrA=";
    buildPhase = ''
        php artisan config:cache
        php artisan route:cache
        php artisan view:cache

And here’s the log:

@nix { "action": "setPhase", "phase": "unpackPhase" }
Running phase: unpackPhase
unpacking source archive /nix/store/526b8lc3pb2zqnnaifzicpvn9a1d5kan-bd7bkkzyplxc172ris1gad3idnc75a5i-source
source root is bd7bkkzyplxc172ris1gad3idnc75a5i-source
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "configurePhase" }
Running phase: configurePhase
Executing composerInstallConfigureHook
Validating consistency between composer.lock and /nix/store/gawqdzilggwhlrscxi4df66v8b9n4qrk-yota-laravel-2.0.0-composer-repository/composer.lock
Finished composerInstallConfigureHook
@nix { "action": "setPhase", "phase": "buildPhase" }
Running phase: buildPhase

Warning: require(/build/bd7bkkzyplxc172ris1gad3idnc75a5i-source/vendor/autoload.php): Failed to open stream: No such file or directory in /build/bd7bkkzyplxc172ris1gad3idnc75a5i-source/artisan on line 18

Fatal error: Uncaught Error: Failed opening required '/build/bd7bkkzyplxc172ris1gad3idnc75a5i-source/vendor/autoload.php' (include_path='.:/nix/store/lcry86ga2mj77gfddcl10w7mccpq62q4-php-8.3.4/lib/php') in /build/bd7bkkzyplxc172ris1gad3idnc75a5i-source/artisan:18
Stack trace:
#0 {main}
  thrown in /build/bd7bkkzyplxc172ris1gad3idnc75a5i-source/artisan on line 18

If I remove the buildPhase, the project builds, but I need php artisan commands for the application to actually work when I serve it using Nginx…

the autoload file is likely missing or is in another location maybe because the application is not installed correctly, yet. I would try to use nix-build -K/nix build --keep-failed to dump the /build/ directory to /tmp/ and inspect there further or use debugging commands to inspect the file layout.

1 Like

You are right, the autoload file is missing, actually the entire vendor directory is missing.
Here’s the structure of the build directory:

├── bd7bkkzyplxc172ris1gad3idnc75a5i-source
│   ├── app
│   ├── artisan
│   ├── bootstrap
│   ├── composer.json
│   ├── composer.lock
│   ├── config
│   ├── database
│   ├── derivative.nix
│   ├── flake.lock
│   ├── flake.nix
│   ├── LICENSE
│   ├── package.json
│   ├── package-lock.json
│   ├── phpunit.xml
│   ├── public
│   ├──
│   ├── resources
│   ├── routes
│   ├── server.php
│   ├── storage
│   ├── tests
│   └── webpack.mix.js
└── env-vars

The buildComposerProject is a wrapper that builds the vendor (set of external libraries required to build/run), which turns out to be actually the vendor directory in the PHP language.

I don’t know what is artisan doing… (I never wanted to work in a Laravel project so, I really don’t know anything there), but I doubt it’s building something since building a PHP app boils down to build the vendor.

Therefore, I would remove the custom buildPhase and try again.

Give us some feedback and feel free to join the Matrix Nixos/PHP room at

If I build the derivation without my custom buildPhase, I can use result and successfully run php artisan commands. The thing is I want the derivation to do it for me since I plan to use it in my server configuration.

Thanks, I’ll join :smiley:

OK, then try to run these commands in a postInstall hook perhaps?

1 Like

That worked, thanks! :smiley: