0

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

Fabian Schneider
  • 799
  • 1
  • 13
  • 40
  • I am more concerned about the wrapper script that copies everything into the home directory. That's not how a package should behave. – Robert Hensing May 31 '21 at 11:37
  • Does `nix-build -A typedb.src` produce the expected store path contents? – Robert Hensing May 31 '21 at 11:37
  • @RobertHensing I am aware that this is not how it should be; however the program needs a writable environment while running; so I tried to follow the normal installation path as close as possible... is there another way to do this? – Fabian Schneider May 31 '21 at 12:12
  • `nix-build -A typedb.src` evaluates to the error `error: expression does not evaluate to a derivation (or a set or list of those)` – Fabian Schneider May 31 '21 at 12:12
  • Often programs will allow overriding the writable locations with an environment variable, config file, or such. I don't know if `typedb` does. It should. – Robert Hensing May 31 '21 at 14:07
  • The evaluation error is because `builtins.fetchTarball` runs at evaluation time, evaluating to a path, rather than a fixed-output derivation like `fetchurl x` does. The latter is more efficient because it doesn't stall the evaluator. – Robert Hensing May 31 '21 at 14:09
  • well typedb is contained fully inside the folder; so it could potentially be installed anywhere; it only needs a java to run; i made the java path itself overridable some time ago. the package should provide the "standard" way to install it that is done by the other installers as well – Fabian Schneider May 31 '21 at 14:10
  • @RobertHensing when using fetchurl `nix-build -A typedb.src` does print `/nix/store/pn0vsk8apng2vrh4m8kwzf9f4lmasjxm-typedb-all-linux-2.1.1.tar.gz` which seems fine; on building the package though, the same error occurrs: the tar file is not available in the `installPhase`.. – Fabian Schneider May 31 '21 at 14:25
  • Could you make a draft pr on the NixOS/nixpkgs repo? That way it's easier to checkout and give feedback. – Robert Hensing Jun 01 '21 at 16:25
  • @RobertHensing sure; github was down; but I managed to do the draft pull request now: https://github.com/NixOS/nixpkgs/pull/125350 – Fabian Schneider Jun 02 '21 at 09:36

0 Answers0