Skip to content

Add dhall support #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions snack-lib/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ rec {
doesFileExist = base: filename:
lib.lists.elem filename (listFilesInDir base);

fileExtension = fp:
let
exts = lib.splitString "." (builtins.baseNameOf fp);
in if lib.length exts == 0 then null else lib.last exts;


listFilesInDir = dir:
let
go = dir: dirName:
Expand Down
29 changes: 27 additions & 2 deletions snack-lib/hpack.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ lib, glibcLocales, callPackage, writeText, runCommand, haskellPackages }:
{ lib, dhall-json, glibcLocales, callPackage, writeText, runCommand, haskellPackages }:

with (callPackage ./lib.nix {});
with (callPackage ./files.nix {});
with (callPackage ./modules.nix {});

let
Expand All @@ -19,14 +20,38 @@ let
"${y2j} ${writeText "y2j" text} > $out"
);
in builtins.fromJSON json;

fromDhall = text:
let json =

builtins.readFile (runCommand "d2j"
{ buildInputs = [ dhall-json ]; }
# hack: dhall-to-json gets a path and then imports the contents
"dhall-to-json <<< ${writeText "d2j" text} > $out"
);
in builtins.fromJSON json;
in
{
# Returns an attribute set with two fields:
# - library: a package spec
# - executable: an attr set of executable name to package spec
pkgDescrsFromHPack = packageYaml:
let
package = fromYAML (builtins.readFile packageYaml);
package =
let
ext = fileExtension packageYaml;
fromFile =
if ext == null
then abort "File ${packageYaml} has no extension!"
else if ext == "yaml"
then fromYAML
else if ext == "yml"
then fromYAML
else if ext == "dhall"
then fromDhall
else
abort "File ${packageYaml} has an unknown extension (${ext})!";
in fromFile (builtins.readFile packageYaml);

# Snack drops the version bounds because here it has no meaning
dropVersionBounds =
Expand Down
16 changes: 16 additions & 0 deletions tests/readme/package.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ name = "snack-readme"

, dependencies =
[ "lens", "wreq" ]

, library =
{ source-dirs = "./src" }

, executable =
{ main = "Main.hs"
, source-dirs = "./app"
, dependencies = [ "snack-readme" ]
}

, default-extensions = [ "OverloadedStrings" ]
}
1 change: 1 addition & 0 deletions tests/readme/test
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ test() {
SNACK="snack" test
SNACK="snack -s ./snack.nix" test
SNACK="snack --package-yaml ./package.yaml" test
SNACK="snack --package-yaml ./package.dhall" test