Why are the `fetchTarball`-downloaded files not in scope?

293 Views Asked by At

I am on NixOS, trying to add the following derivation to nixpkgs:

{ stdenv, lib, openjdk,typedbHome ? "~/.typedb_home", fetchzip}:

let 
  typedbVersion = "2.1.1";
  typedbDirLinux = "typedb-all-linux-${typedbVersion}";
  typedbDirMac = "typedb-all-mac-${typedbVersion}";
  typedbDirWindows = "typedb-all-windows-${typedbVersion}";
  typedbDir = if stdenv.hostPlatform.isWindows then typedbDirWindows
              else if stdenv.isDarwin          then typedbDirMac
                                               else typedbDirLinux;
  linuxSrc = builtins.fetchTarball {
    url = "https://github.com/vaticle/typedb/releases/download/2.1.1/typedb-all-linux-2.1.1.tar.gz";
    sha256 = "15nwm2dr68p67c2xcqigs66gd679j1zr72gqv7qxgvflwyvyz8fb";
  };
  windowsSrc = fetchzip {
    url = "https://github.com/vaticle/typedb/releases/download/2.1.1/typedb-all-windows-2.1.1.zip";
    sha256 = "0vd66gfshkg697z07nhy957mwqzlli4r4pmn67hx58n9mkg024kq";
  };
  macSrc = fetchzip {
    url = "https://github.com/vaticle/typedb/releases/download/2.1.1/typedb-all-mac-2.1.1.zip";
    sha256 = "16hlfy6kh2rnvcralz206q13mghb0rv8wazpg6q3h324p5rdys54";
  };
  srcFolder = if stdenv.hostPlatform.isWindows then windowsSrc
              else if stdenv.isDarwin          then macSrc
                                               else linuxSrc ;
  javaPatch = ''
        20c20
        < JAVA_BIN=java
        ---
        > JAVA_BIN=${openjdk}/bin/java
        '';

in
stdenv.mkDerivation rec {
  pname = "typedb";
  version = typedbVersion;

  src = srcFolder;
    
  phases = [ "installPhase" ];

  buildDepends = [ openjdk ];

  installPhase = ''
    echo "here"     # added for debugging
    ls -lah         # "
    echo "--"       # "
    #patch before install
    echo "${javaPatch}" > typedb_java.patch
    patch ./${typedbDir}/typedb typedb_java.patch

    mkdir $out
    cp -r ./${typedbDir} $out
    # add a wrapper script to $out that will move typedb to $typedb
    # this is necessary because typedb needs a writable environment
    echo "
      # on the first start copy everything to typedbHome
      if [ ! -f ${typedbHome}/typedb ]; then 
        mkdir -p ${typedbHome}; 
        cp -r $out/${typedbDir}/* ${typedbHome}; 
    
        # correct permissions so that typedb and the user can write there 
        chmod -R u+rw ${typedbHome}
        chmod u+x ${typedbHome}/typedb
      fi; 
      ${typedbHome}/typedb \$@; 
    " > $out/typedb

    chmod +x $out/typedb
  '';

  doCheck = true;

  meta = with lib; {
    description = "TypeDB is a distributed knowledge graph: a logical database to organise large and complex networks of data as one body of knowledge.";
    longDescription = ''
        TypeDB is a distributed knowledge graph: a logical database to organise large and complex networks of data as one body of knowledge. 
        TypeDB provides the knowledge engineering tools for developers to easily leverage the power of Knowledge Representation and Automated 
        Reasoning when building complex systems. Ultimately, TypeDB serves as the knowledge-base foundation for intelligent systems.
    '';
    homepage = "https://www.grakn.ai/";
    license = licenses.gpl3Plus;
    platforms = platforms.all;
    maintainers = [ maintainers.haskie ];
  };
}

I successfully built and installed it in sandbox mode while testing it a few times. Then as stated in the contributing guidelines, I checked that all the packages depending on the change are still bulidable with nix-shell -p nixpkgs-review --run "nixpkgs-review wip" (even though it is a new package; I just went through the contribution guideline list). This checked out fine as well.

Now, however, when I try to rebuild it in sandbox mode the build fails with this message:

build --option build-use-sandbox true -A typedb
these derivations will be built:
  /nix/store/0dr5r50fg66dhaa2mh2gh1dbzg7lbx8j-typedb-2.1.1.drv
building '/nix/store/0dr5r50fg66dhaa2mh2gh1dbzg7lbx8j-typedb-2.1.1.drv'...
installing
here
total 16K
drwx------ 2 nixbld nixbld 4.0K May 30 11:13 .
drwxr-x--- 9 nobody nixbld 4.0K May 30 11:13 ..
-rw-r--r-- 1 nixbld nixbld 5.9K May 30 11:13 env-vars
--
patching file ./typedb-all-linux-2.1.1/typedb
Hunk #1 FAILED at 20.
patch: **** Can't reopen file ./typedb-all-linux-2.1.1/typedb : No such file or directory
builder for '/nix/store/0dr5r50fg66dhaa2mh2gh1dbzg7lbx8j-typedb-2.1.1.drv' failed with exit code 2
error: build of '/nix/store/0dr5r50fg66dhaa2mh2gh1dbzg7lbx8j-typedb-2.1.1.drv' failed

it seems that the zip files that I require as src are not downloaded at all; what is the reason for this behavior and how can I fix this?

the build worked before so i think it might have something to do with weird caching behavior or something alike (however using sandboxed mode should circumvent that normally)?

the full repo can be found here. The package I am adding is in pkgs/server/typedb

I tried

  • building with and without sandboxed mode,
  • nix-prefetch-url-ing the appropriate tarball before building,
  • re-cloning the repo to a different location and building it from scratch with sandboxed mode
  • determining whether there are non-garbage collected broken prefeched tarballs (I did not find any however (maybe the way I was looking for them wasn't quite right))

this question was also posted on reddit but I thought that it might be easier to find here.

Draft pull request can be found here

0

There are 0 best solutions below