I have following derivation to install jdtls files using nix flake.
{
stdenv,
fetchurl,
gnutar,
...
}: stdenv.mkDerivation {
pname = "jdtls";
version = "1.28.0";
src = fetchurl {
url = "https://www.eclipse.org/downloads/download.php?file=/jdtls/snapshots/jdt-language-server-1.28.0-202309211406.tar.gz";
sha256 = "q9O44I8iLuNT/eD1IDVnoa1TQgzEIhl2YF40wD0y/sA=";
};
nativeBuildInputs = [ gnutar ];
buildPhase = ''
ls -l
# mkdir -p $out/share
# tar -xf $src -d $out/share
# mv $out/share/bin $out
'';
}
I the tar.gz file, there are multiple directories in the root of the compressed file and that's causing nix build to be failed with this error.
Files:
❯ tar -tf /nix/store/1m9df2gmnak6rkmf71vfnk36g724p6zb-jdt-language-server-1.28.0-202309211406.tar.gz
plugins/
features/
config_mac/
config_mac_arm/
config_win/
config_linux/
config_linux_arm/
config_ss_mac/
config_ss_mac_arm/
config_ss_win/
config_ss_linux/
config_ss_linux_arm/
bin/
plugins/ch.qos.logback.classic_1.4.11.jar
plugins/org.eclipse.jdt.junit.runtime_3.7.200.v20230627-0107.jar
plugins/org.eclipse.lsp4j.jsonrpc_0.21.0.v20230517-2120.jar
plugins/org.eclipse.osgi.services_3.11.100.v20221006-1531.jar
plugins/com.google.guava_32.1.2.jre.jar
Error:
❯ nix log /nix/store/8r6v9l4825pxl76w7vy5nlv5drn6livs-jdtls-1.28.0.drv
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/1m9df2gmnak6rkmf71vfnk36g724p6zb-jdt-language-server-1.28.0-202309211406.tar.gz
unpacker produced multiple directories
Resolve this error?
Nix does some automatic detection on the tar you downloaded, assuming that it contains a single directory. To skip it, you can add
sourceRoot = ".";to your derivation like so:You can see in the default unpackPhase how it goes wrong.