dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
908 stars 211 forks source link

dhall not being picked up at runtime in a nix execution #2489

Closed locallycompact closed 1 year ago

locallycompact commented 1 year ago

Hi, I can not seem to get dhall-nixpkgs to work. Here is my reproduction:

https://gitlab.homotopic.tech/horizon/horizon-spec/-/tree/9c2d4b55991c2424df81b1b585d3c6678237cdb7

The problem is the test does not find a cache hit no matter what I try.

I've generated a nix expression like so

dhall-to-nixpkgs directory dhall --fixed-output-derivations --name "horizon-spec" > horizon-spec.dhall.nix

I tried to add the dhall package as a runtime input. I've also tried endless combinations of buildInputs in various places - at the check site, at the script site - nothing seems to pick up the cache. I've tried without the FOD flag and passing in the Prelude manually. I'm just stumped.

What has to happen for scripts to pick up the cached dhall packages?

locallycompact commented 1 year ago

I was able to hack this by doing this:

        wrapDhallEnvironment = name: { dependencies }: script:
          let
            cache = ".cache";
            cacheDhall = "${cache}/dhall";
          in
          writeBashBin name
            ''
              mkdir -p ${cacheDhall}
              for dependency in ${builtins.toString dependencies}; do
                ${pkgs.xorg.lndir}/bin/lndir -silent $dependency/${cacheDhall} ${cacheDhall}
              done
              export XDG_CACHE_HOME=$PWD/${cache}
              ${script}
            '';

        horizon-spec-tests-wrapper = wrapDhallEnvironment "horizon-spec-tests-wrapper" { dependencies = dhall-prelude; } ''${legacyPackages.horizon-spec}/bin/horizon-spec-tests'';

It's good enough for now.

Gabriella439 commented 1 year ago

If you use the Nixpkgs support for Dhall, it will handle this automatically for you:

https://nixos.org/manual/nixpkgs/stable/#sec-language-dhall

locallycompact commented 1 year ago

This only works for dhall dependencies of a dhall project. Not calling dhall decode from a haskell executable at runtime.