-
Notifications
You must be signed in to change notification settings - Fork 24
/
flake.nix
153 lines (149 loc) · 5.28 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
{
description = "inCode";
inputs = {
haskellNix.url = "github:input-output-hk/haskell.nix";
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
purifix.url = "github:purifix/purifix";
easy-purescript.url = "github:justinwoo/easy-purescript-nix";
};
outputs = { self, nixpkgs, flake-utils, haskellNix, purifix, easy-purescript }:
flake-utils.lib.eachDefaultSystem (system:
let
lib = nixpkgs.lib;
overlays = [
purifix.overlay
haskellNix.overlay
(final: prev: {
inCode = final.haskell-nix.project' {
name = "inCode";
src = ./.;
compiler-nix-name = "ghc982";
shell = {
withHoogle = false;
tools = {
cabal = { };
hlint = { };
haskell-language-server = { };
};
};
};
})
];
pkgs = import nixpkgs {
inherit system overlays;
inherit (haskellNix) config;
};
haskellFlake = pkgs.inCode.flake { };
inCode = rec {
purescript = pkgs.purifix { src = ./purescript; };
haskell = haskellFlake.packages."inCode:exe:inCode-build";
web = pkgs.stdenv.mkDerivation {
name = "inCode";
buildInputs = [ haskell ] ++ lib.attrValues purescript;
srcs = [
./code-samples
./config
./copy
./css
./js
./latex
./scss
./static
];
LANG = "en_US.UTF-8";
LOCALE_ARCHIVE = pkgs.lib.optionalString
(pkgs.buildPlatform.libc == "glibc")
"${pkgs.glibcLocales}/lib/locale/locale-archive";
unpackPhase = ''
for srcFile in $srcs; do
cp -a $srcFile/. $(stripHash $srcFile)
done
mkdir _purescript
${
lib.concatStringsSep "\n" (lib.mapAttrsToList
(name: value: ''cp ${value.bundle-app} _purescript/${name}.js'')
purescript
)
}
'';
buildPhase = ''
export XDG_CACHE_HOME=$(mktemp -d)
${haskell}/bin/inCode-build build
'';
installPhase = ''
mkdir -p "$out/dist"
cp -a _site/. "$out/dist"
'';
};
};
rebuild-js =
let
buildSingleDep = name: value:
let
srcGlob = "purescript/${name}/src/**/*.purs";
buildDir = "$HAKYLL_DIR/_purescript-build/${name}";
mainModule = "${buildDir}/Main/index.js";
outFile = "$HAKYLL_DIR/_purescript/${name}.js";
in
''
mkdir -p ${buildDir}
purs compile ${toString value.globs} ${srcGlob} -o ${buildDir}
chmod -R +w ${buildDir}
echo "import {main} from '${mainModule}'; main()" | esbuild --bundle --outfile=${outFile} --format=iife
'';
in
pkgs.writeShellScriptBin
"rebuild-js"
''
mkdir -p "$HAKYLL_DIR/_purescript";
${lib.concatStringsSep "\n" (lib.mapAttrsToList buildSingleDep inCode.purescript)}
'';
all-js-globs = lib.flatten (lib.mapAttrsToList (name: value: value.globs) inCode.purescript);
in
{
packages = {
inherit inCode;
default = inCode.web;
};
devShells = {
haskell-dev = haskellFlake.devShell;
purescript-dev = lib.mapAttrs (name: value: value.develop) inCode.purescript;
default = pkgs.mkShell {
shellHook = ''
export HAKYLL_DIR=$(mktemp -d)
echo "Available commands: rebuild-js inCode-build"
echo "Hakyll working directory: \$HAKYLL_DIR"
export PURS_IDE_SOURCES='${toString all-js-globs}'
mkdir -p purescript/output
mkdir -p $HAKYLL_DIR/_purescript
${lib.concatStringsSep "\n"
(lib.mapAttrsToList
(name: value:
''
cp -a ${value.deps}/output/. purescript/output
chmod -R +w purescript/output
cp ${value.bundle-app} $HAKYLL_DIR/_purescript/${name}.js
''
)
inCode.purescript
)}
chmod -R +w $HAKYLL_DIR/_purescript
for srcDir in code-samples config copy css js latex scss static; do
ln -s "$PWD/$srcDir" $HAKYLL_DIR
done
'';
nativeBuildInputs = [ pkgs.esbuild pkgs.purescript ]
++ haskellFlake.devShell.nativeBuildInputs
++ lib.attrValues inCode.purescript
++ map (value: value.develop.buildInputs) (lib.attrValues inCode.purescript)
++ [ easy-purescript.packages.${system}.purty easy-purescript.packages.${system}.spago ];
packages = [
rebuild-js
inCode.haskell
];
};
};
}
);
}