dub2nix icon indicating copy to clipboard operation
dub2nix copied to clipboard

attempt to write in the store when building

Open symphorien opened this issue 4 years ago • 9 comments

I'm trying to use dub2nix on https://github.com/CyberShadow/btdu/commit/9bbab62ba129d07c00b5e9e6cb00b6181b259831

I'm invoking it with

let pkgs = import <nixpkgs> { }; in
let mkDub = (import ./mkDub.nix {
  inherit pkgs;
});
in
mkDub.mkDubDerivation {
  version = "0.1.0"; # optional
  src = ./.;
  package = {
    name = "btdu";
    description = "sampling disk usage profiler for btrfs";
    outPath = "foo";
  };
}

when building dub attempts to write to the store:

$  nix-build --show-trace
these derivations will be built:
  /nix/store/jxq676a3bgp8zb8iq2cslzw3qzrq312x-btdu-0.1.0.drv
building '/nix/store/jxq676a3bgp8zb8iq2cslzw3qzrq312x-btdu-0.1.0.drv'...
unpacking sources
unpacking source archive /nix/store/0lvppfcimz2p21f6146ncxfwj48waip2-source
source root is source
patching sources
configuring
no configure script, doing nothing
building
Registered package: ncurses (version: 0.0.149)
Registered package: ae (version: 0.0.2833)
Registered package: btrfs (version: 0.0.11)
Performing "release" build using dmd for x86_64.
/nix/store/a8rk8i1b2597ihlqxr6m7vy3plfc3d0d-ncurses/.dub: Permission denied
builder for '/nix/store/jxq676a3bgp8zb8iq2cslzw3qzrq312x-btdu-0.1.0.drv' failed with exit code 2
error: build of '/nix/store/jxq676a3bgp8zb8iq2cslzw3qzrq312x-btdu-0.1.0.drv' failed

symphorien avatar Jan 31 '21 14:01 symphorien

Thanks. I'll look into this.

lionello avatar Jan 31 '21 18:01 lionello

still the case with current master of btdu and dub2nix (I had to run dub convert to obtain a dub.json)

symphorien avatar Dec 11 '21 15:12 symphorien

@symphorien I started looking into this, but btdu doesn't build for me, making it hard to debug. Have you tried building with ldc?

ldc2 failed with exit code 1.
error: builder for '/nix/store/qnyhx2vid7dkfnq8syvp75y92h8qfli0-btdu.drv' failed with exit code 2;
       last 10 log lines:
       > building
       > Registered package: ncurses (version: 0.0.149)
       > Registered package: ae (version: 0.0.2833)
       > Registered package: btrfs (version: 0.0.11)
       > Performing "release" build using ldc2 for aarch64, arm_hardfloat.
       > btdu ~master: building configuration "application"...
       > source/btdu/browser.d(44,8): Error: module `time` is in file 'ae/utils/time.d' which cannot be read
       > import path[0] = source/
       > import path[1] = /nix/store/p30ic724rgi9gg0w61bab2hmivqdrh5g-ldc-1.27.1/include/d
       > ldc2 failed with exit code 1.
       For full logs, run 'nix log /nix/store/qnyhx2vid7dkfnq8syvp75y92h8qfli0-btdu.drv'.

lionello avatar Dec 12 '21 23:12 lionello

It builds succesfully with dmd inside nix-shell -I nixpkgs=../nixpkgs -p dub dmd zlib ncurses where nixpkgs points to current nixos-unstable: b0bf5f888d377dd2f36d90340df6dc9f035aaada

I don't know how to test with ldc:

$ dub
Failed to invoke the compiler dmd to determine the build platform: /bin/sh: ligne 1: dmd : commande introuvable

if I replace dmd with ldc in the nix-shell command above.

symphorien avatar Dec 13 '21 19:12 symphorien

@symphorien ~~Can you try nix-shell -I nixpkgs=../nixpkgs -p dub ldc zlib ncurses with dub --compiler=ldc? Looks like it doesn't build with ldc.~~ I'm on an ARM machine, so got no dmd here. Think I found it.

lionello avatar Dec 14 '21 16:12 lionello

I made a mistake and actually dub works with ldc without a flag. and I confirm that btdu compiles with ldc.

symphorien avatar Dec 14 '21 20:12 symphorien

@symphorien Found it: current dub2nix does not attempt to build library projects and only supports projects that have targetType set to sourceLibrary. Two of the dependencies from btdu are staticLibrary projects. While attempting to add support for these, I'm running into several dub issues.

The more serious issue is that dub tries to iterate over all files in the Nix store, because ae has .. as one of its import paths: https://github.com/CyberShadow/ae/blob/master/dub.sdl#L13

lionello avatar Dec 16 '21 00:12 lionello

It might be worth pointing out that Dub itself has implemented a workaround for this exact issue when it stores copies of its packages (in ~/.dub/packages):

  • https://github.com/dlang/dub/issues/502
  • https://github.com/dlang/dub/pull/712

This fix was also (graciously) done to fix ae. :)

Hope this helps.

CyberShadow avatar Jan 27 '22 23:01 CyberShadow

I get this error when trying to build packages that have emsi_containers-0.9.0 as a dependency (e.g. dcd).

I think the root cause is the "targetPath": "build", in the dub.json there, and I'm unsure how I can patch a dependency: https://github.com/lionello/dub2nix/blob/d72adcf01c4d4351ed459e169494232a228eedb3/mkDub.nix#L45

An idea here would be to change the way the dub.selections.nix is structured, e.g. in a way where we have

{
  emsi_containers.fetch = {
      # ...
    }
}

so that we can pass in per-dependency overrides (mostly patches) in mkDubDerivation. 🤔

nekowinston avatar Sep 23 '23 02:09 nekowinston