Derivation stdenv cant execute bash scripts

I’m trying to package Urbackup but i cant run bash scripts in the derivation. Not even simple ones like the teste.sh that i created to test and that just run echo ‘test!’.

The error message i get is ./teste.sh: cannot execute: required file not found.

The following is my nix expression:

with import <nixpkgs> {};
 
stdenv.mkDerivation rec {
  pname = "urbackup-server";
  version = "2.5.20";

  src = fetchgit {
    url = "https://github.com/uroni/urbackup_backend.git";
    rev = "refs/tags/${version}";
    sha256 = "sha256-brP7nYikbIvQP/K+qSKyd8eHWUIK9Ai/4qP09ptr+lE=";
  };

  buildInputs = [
    cryptopp
    curlWithGnuTls
  ];

  configurePhase = ''
    runHook preInstall

    touch teste.sh
    echo '#!/usr/bin/env bash' >> teste.sh
    echo 'echo 'echo test! >> teste.sh
    chmod +x teste.sh
    ./teste.sh

    ./switch_build.sh server
    autoreconf --install
    ./configure

    runHook postInstall
  '';

  buildFlags = [
    "-j8"
  ];

  enableParallelBuilding = true;

  meta = with lib; {
    description = "Easy to setup Open Source client/server backup system";
    longDescription = "An easy to setup Open Source client/server backup system, that through a combination of image and file backups accomplishes both data safety and a fast restoration time";
    homepage = "https://www.urbackup.org/index.html";
    license = licenses.agpl3Plus;
    platforms = platforms.linux;
  };
}

I’m running nix inside Debian Trixie:

$ nix --version
nix (Nix) 2.25.2

I can access the files normally with ls cat.

Does /usr/bin/env even exist in the sandbox? Better off just running bash test.sh or whatever.

You’re right! it now executes.

Do you know if running bash is the default way to running scripts inside derivations?

If you’re making your own script as part of the build, you could probably just write #!bash as the shebang, or better, use writeShellApplication which gets shellcheck-ed and put the call in nativeBuildInputs. If you’re trying to use someone else’s existing script, I don’t see any other way to handle it (besides running sh or bash or whatever directly) if it’s using a shebang that points at a nonexistent file. Well, you could patch the file, I suppose, with patchShebangs --build, but seems kinda overkill for something only used during the build :person_shrugging:

1 Like