Skip to content

Commit

Permalink
Add dhall support
Browse files Browse the repository at this point in the history
  • Loading branch information
nmattia committed Aug 26, 2018
1 parent 4bbf242 commit fa50d9b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
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

0 comments on commit fa50d9b

Please sign in to comment.