Skip to content

Commit 806cba3

Browse files
committed
Adds haskellData
1 parent 60ff7f2 commit 806cba3

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

flake-lang/build.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@
5050
'';
5151
};
5252

53+
haskellData = lib.mkOption {
54+
type = lib.types.functionTo lib.types.attrs;
55+
default = import ./haskell-data.nix pkgs;
56+
readOnly = true;
57+
description = lib.mdDoc ''Makes a derivation containing a Haskell Cabal package with data modules (using Cabal data stanzas)'';
58+
example = lib.mdDoc ''
59+
haskellData {
60+
srcs = [ ./. ];
61+
cabalDataPatterns = [ "**/*.json" ];
62+
cabalPackageName = "golden-json-data";
63+
};
64+
'';
65+
};
66+
5367
haskellFlake = lib.mkOption {
5468
type = lib.types.functionTo lib.types.attrs;
5569
default = import ./flake-haskell.nix pkgsForHaskellNix;

flake-lang/haskell-data.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Makes a Cabal package with just a 'data' directory with proper 'data-filers' stanza
2+
pkgs: { srcs, cabalDataPatterns, cabalPackageName, cabalPackageVersion ? "0.1.0.0" }:
3+
let
4+
cabalTemplate = pkgs.writeTextFile {
5+
name = "haskell-data.nix-cabal-template";
6+
text = ''
7+
cabal-version: 3.0
8+
name: ${cabalPackageName}
9+
version: ${cabalPackageVersion}
10+
synopsis: A Cabal project that contains data files
11+
build-type: Simple
12+
data-files: ${builtins.concatStringsSep ", " (builtins.map (d: "data/${d}") cabalDataPatterns)}
13+
14+
library
15+
default-language: Haskell2010
16+
build-depends: base >=4.16
17+
exposed-modules: Paths_${builtins.replaceStrings ["-"] ["_"] cabalPackageName}
18+
'';
19+
};
20+
in
21+
pkgs.stdenv.mkDerivation {
22+
inherit srcs;
23+
name = cabalPackageName;
24+
buildInputs = [
25+
pkgs.cabal-install
26+
];
27+
sourceRoot = ".";
28+
buildPhase = ''
29+
mkdir data;
30+
cp -r -t data ${builtins.concatStringsSep " " (builtins.map (src: "${src}/*") srcs)};
31+
cat ${cabalTemplate} > ${cabalPackageName}.cabal;
32+
'';
33+
34+
installPhase = ''
35+
mkdir $out;
36+
cp -r data $out/;
37+
mv ${cabalPackageName}.cabal $out/;
38+
'';
39+
}

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
## Foundational Plutus library
4242
plutus.url = "github:input-output-hk/plutus";
4343

44-
## Plutarch eDSL that LB generates to
44+
## Plutarch eDSL
4545
plutarch = {
4646
url = "github:plutonomicon/plutarch-plutus";
4747
flake = false;

0 commit comments

Comments
 (0)