-
Notifications
You must be signed in to change notification settings - Fork 6
/
flake.nix
261 lines (259 loc) · 9.22 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
{
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/6fc7203e423bbf1c8f84cccf1c4818d097612566";
inputs.fhi.url = "github:soenkehahn/format-haskell-interpolate";
inputs.nix-tool-installer.url = "github:garnix-io/nix-tool-installer";
inputs.call-flake.url = "github:divnix/call-flake";
inputs.cradle = {
url = "github:garnix-io/cradle";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils, fhi, nix-tool-installer, call-flake, cradle }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import "${nixpkgs}" {
inherit system;
config.allowUnfree = true;
overlays = [
(final: prev: {
nix = prev.nix.overrideAttrs
(finalAttrs: prevAttrs: {
patches = (prevAttrs.patches or [ ]) ++ [
(final.fetchpatch {
name = "include-untracked-files.patch";
url = "https://github.com/NixOS/nix/compare/2.17.1...jfroche:nix:feat/include-untracked-files-2.17.1.patch";
excludes = [ "tests/functional/*" ];
hash = "sha256-HCGYzArlHO3Q0jIfc7rVD6AfV2wBzqY7VeU5DavexRE=";
})
];
requiredSystemFeatures = (prevAttrs.requiredSystemFeatures or [ ]) ++ [ "big-parallel" ];
});
})
];
};
strings = pkgs.lib.strings;
lists = pkgs.lib.lists;
ourHaskell = pkgs.haskell.packages.ghc947.override {
overrides = self: super: {
cradle = cradle.lib.${system}.mkCradle pkgs.haskell.packages.ghc947;
};
};
websiteFlake = call-flake ./website;
websitePackages =
if system == "x86_64-linux" then
pkgs.lib.attrsets.mapAttrs'
(name: value: { name = "website_${name}"; inherit value; })
websiteFlake.packages.${system} else { };
website2Flake = call-flake ./website2;
website2Packages =
if system == "x86_64-linux" then
pkgs.lib.attrsets.mapAttrs'
(name: value: { name = "website2_${name}"; inherit value; })
website2Flake.packages.${system} else { };
in
{
lib = pkgs.lib;
apps.default = {
type = "app";
program = "${self.packages.${system}.default}/bin/garn";
};
packages = rec {
default = self.packages.${system}.garn;
garnConfigEditor = import ./nix/editor.nix { inherit system; };
garn =
pkgs.runCommand "garn"
{
nativeBuildInputs = [ pkgs.makeWrapper ];
}
''
mkdir -p $out/bin
cp ${garnHaskellPackage}/bin/garn $out/bin
wrapProgram "$out/bin/garn" \
--prefix PATH : ${pkgs.lib.makeBinPath [
pkgs.coreutils
pkgs.deno
pkgs.git
pkgs.nix
self.packages.${system}.cabal2json
]}
'';
garnHaskellPackage =
let
# directories shouldn't have leading or trailing slashes
ignored = [
"examples"
"flake.nix"
".github"
"justfile"
"scripts"
"test/check-isolated-garn.sh"
"website"
];
src = builtins.path
{
path = ./.;
name = "garn-source";
filter = path: type:
let
repoPath =
builtins.concatStringsSep "/"
(lists.drop 4
(strings.splitString "/" path));
in
! (builtins.elem repoPath ignored);
};
in
(ourHaskell.callPackage ./garn.nix { }).overrideAttrs
(
original: {
inherit src;
nativeBuildInputs = original.nativeBuildInputs ++ [
pkgs.deno
pkgs.makeWrapper
pkgs.nix
pkgs.zsh
self.packages.${system}.cabal2json
];
postInstall = ''
wrapProgram "$out/bin/codegen" \
--set LC_ALL C.UTF-8 \
--prefix PATH : ${pkgs.lib.makeBinPath [
pkgs.git
pkgs.nix
]}
'';
doCheck = false;
}
);
cabal2json =
let
ghc = ourHaskell.ghc.withPackages (p:
[
p.Cabal-syntax
p.aeson
p.bytestring
]);
in
(pkgs.runCommand "cabal2json"
{
nativeBuildInputs =
if system == "aarch64-darwin" || system == "x86_64-darwin"
then [ pkgs.clang ]
else [ ];
}
''
cp ${./scripts/cabal2json.hs} ./cabal2json.hs
${ghc}/bin/ghc ./cabal2json.hs -o cabal2json
mkdir -p $out/bin
cp cabal2json $out/bin
'');
fileserver =
let
ghc = ourHaskell.ghc.withPackages (p:
[
p.cradle
p.fsnotify
p.getopt-generics
p.wai-app-static
p.warp
]);
in
(pkgs.writeScriptBin "fileserver" ''
export PATH=${pkgs.curl}/bin:$PATH
export PATH=${pkgs.deno}/bin:$PATH
exec ${ghc}/bin/runhaskell ${./scripts/fileserver.hs} "$@"
'');
}
// websitePackages
// website2Packages
// (
if system == "x86_64-linux"
then {
installScriptFiles = nix-tool-installer.lib.${system}.mkInstallScriptFiles {
toolName = "garn";
baseUrl = "https://garn.io";
flakeLocation = "github:garnix-io/garn/v0.0.20";
testCommand = "garn --help";
};
}
else { }
);
devShells = {
default = pkgs.mkShell {
shellHook =
# For prerendering the frontend,
(pkgs.lib.optionalString (! pkgs.stdenv.isDarwin)
''
export PUPPETEER_EXECUTABLE_PATH="${pkgs.chromium}/bin/chromium"
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
'');
inputsFrom =
builtins.attrValues self.checks.${system}
++ builtins.attrValues self.packages.${system};
nativeBuildInputs = with pkgs; [
bashInteractive
ghcid
cabal-install
(ourHaskell.ghc.withHoogle (p:
self.packages.${system}.garnHaskellPackage.buildInputs))
(haskell-language-server.override {
dynamic = true;
supportedGhcVersions = [ "947" ];
})
ourHaskell.cabal2nix
fhi.packages.${system}.default
self.packages.${system}.cabal2json
sd
];
};
};
checks =
let
justRecipe = recipe: inputs: pkgs.runCommand recipe
{ nativeBuildInputs = [ pkgs.just ] ++ inputs; }
''
touch $out
cp -r ${self}/* .
substituteInPlace justfile \
--replace !/usr/bin/env !${pkgs.coreutils}/bin/env
just ${recipe}
'';
websiteChecks =
if system == "x86_64-linux" then
pkgs.lib.attrsets.mapAttrs'
(name: check: { name = "website_${name}"; value = check; })
websiteFlake.checks.${system} else { };
website2Checks =
if system == "x86_64-linux" then
pkgs.lib.attrsets.mapAttrs'
(name: check: { name = "website2_${name}"; value = check; })
website2Flake.checks.${system} else { };
in
{
nix-fmt = justRecipe "fmt-nix-check" [ self.formatter.${system} ];
typescript-fmt =
justRecipe "fmt-typescript-check" [
pkgs.fd
pkgs.nodePackages.prettier
];
haskell-fmt = justRecipe "fmt-haskell-check" [
pkgs.hpack
pkgs.ormolu
];
fileserver = pkgs.runCommand "fileserver-check"
{
buildInputs = [ self.packages.${system}.fileserver ];
} ''
fileserver --help
touch $out
'';
}
// websiteChecks
// website2Checks;
formatter = pkgs.nixpkgs-fmt;
apps = {
fileserver = flake-utils.lib.mkApp
{ drv = self.packages.${system}.fileserver; };
};
});
}