Illegal path references in fixed-output derivation

Hello, I’m making a derivation for my Laravel project.
Here’s the code:

{ stdenvNoCC, php83, lib }: 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
    '';

    outputHashAlgo = "sha256";
    outputHashMode = "recursive";
    outputHash = lib.fakeSha256;

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

And when I try to build it, I get the following error:

error: illegal path references in fixed-output derivation '/nix/store/s2acrr4zqkhh2ryw9knkkbh9l868q6zv-yota-laravel-2.0.0.drv'

And when I run nix log /nix/store/s2acrr4zqkhh2ryw9knkkbh9l868q6zv-yota-laravel-2.0.0.drv I get the following:

...
@nix { "action": "setPhase", "phase": "installPhase" }
Running phase: installPhase
@nix { "action": "setPhase", "phase": "fixupPhase" }
Running phase: fixupPhase
shrinking RPATHs of ELF executables and libraries in /nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0
checking for references to /build/ in /nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0...
patching script interpreter paths in /nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/artisan: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/bin/doctrine-dbal: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/bin/psysh: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/bin/php-parse: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/bin/carbon: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/bin/var-dump-server: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/bin/patch-type-declarations: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/nikic/php-parser/bin/php-parse: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/symfony/error-handler/Resources/bin/extract-tentative-return-types.php: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/symfony/error-handler/Resources/bin/patch-type-declarations: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/symfony/var-dumper/Resources/bin/var-dump-server: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/nesbot/carbon/bin/carbon: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/doctrine/dbal/bin/doctrine-dbal: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"
/nix/store/15kgzd44lxp9r2qz9kkq26hip9b2m6s3-yota-laravel-2.0.0/vendor/psy/psysh/bin/psysh: interpreter directive changed from "#!/usr/bin/env php" to "/nix/store/lhwpl116xag61ax4r9sdafz79chn1n80-php-with-extensions-8.3.4/bin/php"

On this blog post I found the information that this error happens when fixed-output derivation places something in $out which contains a Nix store path.
If I do nix build --keep-failed and inspect the build directory, #!/usr/bin/env php directives are not actually changed to nix store paths which is weird given the logs above.
Running grep -r 'nix/store' inside the build directory also didn’t return anything.

Any ideas how can I fix this?

The patching of the shebangs happens in fixupPhase, and apparently, some of the vendored stuff had some shebangs to be patched. (see end of nix log)
You can disable fixupPhase by setting dontFixup = true

2 Likes

Thanks a lot! :smiley:

In case somebody is interested, after trying dontFixup, I also found the dontPatchShebangs option, which also works in my case.

1 Like