NixOS / cabal2nix

Generate Nix build instructions from a Cabal file
https://haskell4nix.readthedocs.io
Other
352 stars 154 forks source link

Where hpack goes so does hpack-dhall. #374

Open philderbeast opened 5 years ago

philderbeast commented 5 years ago

In the same way that we have an --hpack option for taking the package definition from package.yaml with hpack can we also have an --hpack-dhall option for taking the package definition from package.dhall with hpack-dhall?


> cabal2nix --help
cabal2nix converts Cabal files into build instructions for Nix.

Available options:
--hpack                  run hpack before configuring this package (only
                           non-hackage packages)
philderbeast commented 5 years ago

I kept --hpack as an option and added --dhall;

Available options:
  --hpack                  package.yaml --> .cabal (only non-hackage packages)
  --dhall                  package.dhall -> .cabal (only non-hackage packages)
philderbeast commented 5 years ago
> cabal2nix --dhall siggy-chardust
*** found package.dhall. Using hpack-dhall...
...
mkDerivation {
  pname = "siggy-chardust";
  version = "1.0.0";
  src = ./siggy-chardust;
...
  libraryToolDepends = [ hpack-dhall ];
...
  preConfigure = "hpack-dhall";
...
}
cabal2nix --dhall https://github.com/BlockScope/flare-timing --subpath=siggy-chardust
...
*** found package.dhall. Using hpack-dhall...
...
mkDerivation {
  pname = "siggy-chardust";
  version = "1.0.0";
  src = fetchgit {
    url = "https://github.com/BlockScope/flare-timing";
    sha256 = "1f8z45p894m77m80nk0di6x6s7mvdx35d1y70971m661iqybk5z1";
    rev = "5b34dd6c5a8babef45a3beca2af9f04ccf8ed645";
    fetchSubmodules = true;
  };
  postUnpack = "sourceRoot+=/siggy-chardust; echo source root reset to $sourceRoot";
...
  libraryToolDepends = [ hpack-dhall ];
...
  preConfigure = "hpack-dhall";
...
}
philderbeast commented 5 years ago

When package.dhall has an error, in this case I've added a trailing semicolon;

> cabal2nix siggy-chardust
*** found package.dhall. Using hpack-dhall...
*** hpack-dhall error: "\n\ESC[1;31mError\ESC[0m: Invalid input\n\n./siggy-chardust/package.dhall:48:8:\n   |\n48 |       };\n   |        ^\nunexpected ';'\nexpecting \"!=\", \"&&\", \"++\", \"//\", \"//\\\\\", \"/\\\", \"==\", \"||\", \"\8743\", \"\10835\", \"\11005\", '#', '(', '*', '+', '.', ':', '?', built-in expression, double literal, end of input, import, integer literal, label, list literal, natural literal, record type or literal, text literal, the rest of expression, or union type or literal\n". Exiting.
philderbeast commented 5 years ago

@peti you've probably seen https://github.com/sol/hpack-dhall/issues/3 where @sol gives some pros and cons of hpack-dhall. I liked using hpack (yaml) for filling in cabal fields for me like other-modules. I like that I can keep those benefits of hpack and yet do more with hpack-dhall.