-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathflake.nix
231 lines (222 loc) · 8.46 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
{
description = "twesterhout/halide-haskell: Running Halide pipelines from Haskell";
nixConfig = {
extra-substituters = "https://halide-haskell.cachix.org";
extra-trusted-public-keys = "halide-haskell.cachix.org-1:cFPqtShCsH4aNjn2q4PHb39Omtd/FWRhrkTBcSrtNKQ=";
};
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
nix-filter.url = "github:numtide/nix-filter";
flake-compat = {
url = "github:edolstra/flake-compat";
# don't look for a flake.nix file in this repository
# this tells Nix to retrieve this input as just source code
flake = false;
};
# halide = {
# url = "github:halide/Halide";
# flake = false;
# };
arrayfire-nix = {
url = "github:twesterhout/arrayfire-nix";
inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
# inline-c = {
# url = "github:twesterhout/inline-c";
# flake = false;
# };
arrayfire-haskell = {
url = "github:twesterhout/arrayfire-haskell/main";
flake = false;
};
nixGL = {
url = "github:guibou/nixGL";
inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, flake-utils, nix-filter, nixGL, ... }:
let
inherit (nixpkgs) lib;
src = nix-filter.lib {
root = ./.;
include = [
"src"
"example"
"test"
"construction.png"
"halide-haskell.cabal"
"README.md"
"test-readme/README.lhs"
"LICENSE"
];
};
halide-haskell-for = pkgs: haskellPackages:
let
builder =
{ withIntelOpenCL
, withCuda
}:
(haskellPackages.callCabal2nix "halide-haskell" src {
Halide = pkgs.halide;
}).overrideAttrs (attrs: rec {
pname = attrs.pname
+ lib.optionalString withIntelOpenCL "-intel-ocl"
+ lib.optionalString withCuda "-cuda";
name = "${pname}-${attrs.version}";
nativeBuildInputs = attrs.nativeBuildInputs
++ lib.optional withIntelOpenCL pkgs.makeWrapper;
propagatedBuildInputs = with pkgs;
attrs.propagatedBuildInputs
++ lib.optionals withIntelOpenCL [ clinfo intel-ocl ocl-icd ]
++ lib.optional withCuda nixGL.packages.${system}.nixGLDefault;
postInstall = (attrs.postInstall or "")
+ lib.optionalString withIntelOpenCL ''
wrapProgram $out/bin/halide-haskell \
--prefix LD_LIBRARY_PATH : ${pkgs.ocl-icd}/lib \
--prefix OCL_ICD_VENDORS : ${pkgs.intel-ocl}/etc/OpenCL/vendors
''
+ lib.optionalString withCuda ''
prog="$out/bin/halide-haskell"
hidden="$(dirname "$prog")/.$(basename "$prog")"-wrapped
mv "$prog" "$hidden"
echo "#!${pkgs.stdenv.shell}" > "$prog"
echo "exec ${pkgs.nixgl.auto.nixGLDefault}/bin/nixGL $hidden \"\$@\"" >> "$prog"
chmod +x "$prog"
'';
# We set withIntelOpenCL and withCuda such that dev shells can determine whether
# they need extra dependencies
inherit withIntelOpenCL;
inherit withCuda;
});
in
lib.makeOverridable builder
{ withIntelOpenCL = false; withCuda = false; };
with-markdown-unlit = hp: p: p.overrideAttrs (attrs: {
nativeBuildInputs = (attrs.nativeBuildInputs or [ ]) ++ [ hp.markdown-unlit ];
});
overlayFor = args: self: super: {
haskell = super.haskell // {
packageOverrides = nixpkgs.lib.composeExtensions super.haskell.packageOverrides
(hself: hsuper: rec {
# arrayfire =
# (hself.callCabal2nix "arrayfire" inputs.arrayfire-haskell.outPath {
# af = pkgs.arrayfire;
# }).overrideAttrs (attrs: {
# configureFlags = (attrs.configureFlags or [ ]) ++ [ "-fdisable-default-paths" ];
# });
halide-haskell = (halide-haskell-for self hself).override args;
halide-JuicyPixels =
(hself.callCabal2nix "halide-JuicyPixels" ./halide-JuicyPixels { });
halide-arrayfire =
(hself.callCabal2nix "halide-arrayfire" ./halide-arrayfire { });
halide-readme = with-markdown-unlit hself
(hself.callCabal2nix "halide-readme" ./test-readme { });
halide-tutorial01 = with-markdown-unlit hself
(hself.callCabal2nix "halide-tutorial01" ./tutorials/01-Basics { });
halide-tutorial03 = with-markdown-unlit hself
(hself.callCabal2nix "halide-tutorial03" ./tutorials/03-Inspecting { });
halide-tutorial04 = with-markdown-unlit hself
(hself.callCabal2nix "halide-tutorial04" ./tutorials/04-Debugging { });
halide-tutorial05 = with-markdown-unlit hself
(hself.callCabal2nix "halide-tutorial05" ./tutorials/05-Scheduling { });
halide-all = self.buildEnv {
name = "halide-all";
paths = [
halide-haskell
halide-JuicyPixels
halide-readme
halide-tutorial01
halide-tutorial03
halide-tutorial04
halide-tutorial05
]; # ++ lib.optional self.stdenv.isLinux halide-arrayfire;
};
});
};
};
devShellFor = pkgs:
let
ps = pkgs.haskellPackages;
withIntelOpenCL = ps.halide-haskell.withIntelOpenCL;
withCuda = ps.halide-haskell.withCuda;
in
ps.shellFor {
packages = ps: with ps; [
halide-haskell
halide-JuicyPixels
halide-readme
halide-tutorial01
halide-tutorial03
halide-tutorial04
halide-tutorial05
]; # ++ lib.optional pkgs.stdenv.isLinux halide-arrayfire;
withHoogle = true;
nativeBuildInputs = with pkgs; with ps; [
# Building and testing
cabal-install
doctest
markdown-unlit
# Language servers
haskell-language-server
nil
# Formatters
fourmolu
cabal-fmt
nixpkgs-fmt
# Previewing markdown files
python3Packages.grip
# For debugging Halide
clang_14
# gcc
# zlib
# gdb
]
++ lib.optional withIntelOpenCL clinfo
++ lib.optional withCuda pkgs.nixgl.auto.nixGLDefault;
shellHook = ''
export PROMPT_COMMAND=""
export PS1='(nix) GHC ${ps.ghc.version} \w $ '
export LD_LIBRARY_PATH=${pkgs.zlib}/lib:${pkgs.halide}/lib:$LD_LIBRARY_PATH
'' + (if withIntelOpenCL then ''
export LD_LIBRARY_PATH=${pkgs.ocl-icd}/lib:$LD_LIBRARY_PATH
export OCL_ICD_VENDORS="${pkgs.intel-ocl}/etc/OpenCL/vendors"
'' else "");
};
pkgsFor = system: args: import nixpkgs {
inherit system;
overlays = [
nixGL.overlay
(overlayFor args)
];
config.allowUnfree =
(args ? withIntelOpenCL) && args.withIntelOpenCL
|| (args ? withCuda) && args.withCuda;
};
in
{
packages = flake-utils.lib.eachDefaultSystemMap (system:
with (pkgsFor system { }); {
default = haskellPackages.halide-haskell;
halide-haskell = haskellPackages.halide-haskell;
halide-all = haskellPackages.halide-all;
haskell = haskell.packages;
});
devShells = flake-utils.lib.eachDefaultSystemMap (system: {
default = devShellFor (pkgsFor system { });
cuda = devShellFor (pkgsFor system { withCuda = true; });
intel-ocl = devShellFor (pkgsFor system { withIntelOpenCL = true; });
});
overlays = {
default = overlayFor { };
cuda = overlayFor { withCuda = true; };
intel-ocl = overlayFor { withIntelOpenCL = true; };
};
templates.default = {
path = ./template;
description = "A minimal Haskell project using halide-haskell";
};
};
}