-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathflake.nix
112 lines (103 loc) · 3.73 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
{
inputs = {
haskell-nix.url = "github:input-output-hk/haskell.nix";
stackageSrc = {
url = "github:input-output-hk/stackage.nix";
flake = false;
};
hackageSrc = {
url = "github:input-output-hk/hackage.nix";
flake = false;
};
utils.url = "github:numtide/flake-utils";
libtorch-nix = {
url = "github:hasktorch/libtorch-nix/d14b0fd10b96d192b92b8ccc7254ade4b3489331";
flake = false;
};
};
outputs = inputs@{ self, nixpkgs, haskell-nix, utils, ... }:
let
name = "hasktorchSkeleton";
compiler = "ghc8104"; # Not used for `stack.yaml` based projects.
cudaSupport = false;
cudaMajorVersion = null;
project-name = "${name}HaskellPackages";
# This overlay adds our project to pkgs
project-overlay = final: prev: {
${project-name} =
#assert compiler == supported-compilers;
final.haskell-nix.project' {
# 'cleanGit' cleans a source directory based on the files known by git
src = prev.haskell-nix.haskellLib.cleanGit {
inherit name;
src = ./.;
};
compiler-nix-name = compiler;
projectFileName = "cabal.project"; # Not used for `stack.yaml` based projects.
modules = [
# Fixes for libtorch-ffi
{
packages.libtorch-ffi = {
configureFlags = with final; [
"--extra-lib-dirs=${torch}/lib"
"--extra-include-dirs=${torch}/include"
"--extra-include-dirs=${torch}/include/torch/csrc/api/include"
];
flags = {
cuda = cudaSupport;
gcc = !cudaSupport && final.stdenv.hostPlatform.isDarwin;
};
};
}
];
};
};
in
{ overlay = final: prev: {
"${name}" = ("${project-name}-overlay" final prev)."${project-name}".flake {};
};
} // (utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
haskell-nix.overlay
(final: prev: {
haskell-nix = prev.haskell-nix // {
sources = prev.haskell-nix.sources // {
hackage = inputs.hackageSrc;
stackage = inputs.stackageSrc;
};
modules = [
# Fixes for libtorch-ffi
{
packages.libtorch-ffi = {
configureFlags = with final; [
"--extra-lib-dirs=${torch}/lib"
"--extra-include-dirs=${torch}/include"
"--extra-include-dirs=${torch}/include/torch/csrc/api/include"
];
flags = {
cuda = cudaSupport;
gcc = !cudaSupport && final.stdenv.hostPlatform.isDarwin;
};
};
}
];
};
})
(import ./nix/overlays/libtorch.nix { inherit inputs cudaSupport cudaMajorVersion; })
project-overlay
];
};
flake = pkgs."${project-name}".flake {};
in flake // rec {
packages.example = flake.packages."${name}:exe:example";
defaultPackage = packages.example;
devShell = (import ./shell.nix {
inherit cudaSupport cudaMajorVersion pkgs;
withHoogle = false;
});
}
));
}