thoughtpolice / buck2-nix

Do not taunt happy fun ball
59 stars 4 forks source link

nix.rules.build seems to struggle with multiple-output expressions #18

Open Fuuzetsu opened 1 year ago

Fuuzetsu commented 1 year ago

If I try to do the below

nix.rules.build(
    name = "jq",
    expr = "pkgs.jq",
    visibility = [ "root//..." ],
)

and use it somewhere, it will fail:

Required outputs are missing: Action failed to produce outputs: `buck-out/v2/gen/root/632fe5438d4aecc1/tools/__jq__/out.link`

because

[shana@aya:~/programming/tenchu-buck]$ ls -lha buck-out/v2/gen/root/632fe5438d4aecc1/tools/__jq__/
total 16K
drwxr-xr-x 2 shana users 4.0K May  1 22:46 .
drwxr-xr-x 7 shana users 4.0K May  1 22:39 ..
-rw-r--r-- 1 shana users  146 May  1 22:46 build.nix
-rwxr-xr-x 1 shana users  487 May  1 22:46 build.sh
lrwxrwxrwx 1 shana users   54 May  1 22:46 out.link-bin -> /nix/store/3x7qsswi5q7ibd5gifjnhggbry0y9920-jq-1.6-bin
lrwxrwxrwx 1 shana users   54 May  1 22:46 out.link-man -> /nix/store/j81k5f746lxlj8jp4gm19ni15qhy83wg-jq-1.6-man

A workaround is to use pkgs.jq.out as the expr. pkgs.jq.bin does not work.

Maybe at least add a field which allows to specify the link name so it's a middle-ground?

Fuuzetsu commented 1 year ago

Ah, actually it's even worse: pkgs.jq.out does not work as it seems to produce empty link. So probably we're forced to do a nix wrapper that symlinks ${pkgs.jq.bin}/bin/jq and build that or something.

Fuuzetsu commented 1 year ago

Ah, actually it's even worse: pkgs.jq.out does not work as it seems to produce empty link. So probably we're forced to do a nix wrapper that symlinks ${pkgs.jq.bin}/bin/jq and build that or something.


nix.rules.build(
    name = "jq",
    expr = """
        pkgs.runCommand "jq" { } ''
            mkdir -p "$out"/bin
            ln -s ${pkgs.jq.bin}/bin/jq "$out"/bin
        ''
    """,
    visibility = [ "root//..." ],
)

Seems to do it.

thoughtpolice commented 1 year ago

Honestly the .build rule should be changed to take a list of output attrs that the expression is intended to produce (out/lib/bin/whatever) and then there should be a provider object returned for each of those symlinks. This assumes mkDerivation of course but hey that's life.

Unfortunately this is a case where we have to duplicate the information between the expression and Buck files, I think. But maybe it's possible to use dynamic_outputs to fix this, but at a glance I'm not sure.