-
Notifications
You must be signed in to change notification settings - Fork 64
/
flake.nix
149 lines (142 loc) · 4.67 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
{
description = "A library for probabilistic programming in Haskell.";
nixConfig = {
extra-substituters = [
"https://tweag-monad-bayes.cachix.org"
"https://tweag-jupyter.cachix.org"
];
extra-trusted-public-keys = [
"tweag-monad-bayes.cachix.org-1:tmmTZ+WvtUMpYWD4LAkfSuNKqSuJyL3N8ZVm/qYtqdc="
"tweag-jupyter.cachix.org-1:UtNH4Zs6hVUFpFBTLaA4ejYavPo5EFFqgd7G7FxGW9g="
];
};
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
jupyenv = {
url = "github:tweag/jupyenv";
inputs = {
flake-compat.follows = "flake-compat";
flake-utils.follows = "flake-utils";
};
};
};
outputs = {
self,
nixpkgs,
jupyenv,
flake-compat,
flake-utils,
pre-commit-hooks,
} @ inputs:
flake-utils.lib.eachSystem
[
# Tier 1 - Tested in CI
flake-utils.lib.system.x86_64-linux
flake-utils.lib.system.x86_64-darwin
# Tier 2 - Not tested in CI (at least for now)
flake-utils.lib.system.aarch64-linux
flake-utils.lib.system.aarch64-darwin
]
(
system: let
inherit (nixpkgs) lib;
inherit (jupyenv.lib.${system}) mkJupyterlabNew;
pkgs = import nixpkgs {
inherit system;
config.allowBroken = true;
};
warnToUpdateNix = pkgs.lib.warn "Consider updating to Nix > 2.7 to remove this warning!";
src = lib.sourceByRegex self [
"^benchmark.*$"
"^models.*$"
"^monad-bayes\.cabal$"
"^src.*$"
"^test.*$"
"^.*\.md"
];
monad-bayes-per-ghc = let
opts = {
name = "monad-bayes";
root = src;
cabal2nixOptions = "--benchmark -fdev";
# https://github.com/tweag/monad-bayes/pull/256: Don't run tests on Mac because of machine precision issues
modifier = drv:
if system == "x86_64-linux"
then drv
else pkgs.haskell.lib.dontCheck drv;
overrides = self: super:
with pkgs.haskell.lib;
{
# Please check after flake.lock updates whether some of these overrides can be removed
brick = super.brick_2_4;
}
// lib.optionalAttrs (lib.versionAtLeast super.ghc.version "9.10") {
# Please check after flake.lock updates whether some of these overrides can be removed
microstache = doJailbreak super.microstache;
};
};
ghcs = [
# Always keep this up to date with the tested-with section in monad-bayes.cabal,
# and the build-all-ghcs job in .github/workflows/nix.yml!
"ghc902"
"ghc927"
"ghc945"
"ghc964"
"ghc982"
"ghc9101"
];
buildForVersion = ghcVersion: (builtins.getAttr ghcVersion pkgs.haskell.packages).developPackage opts;
in
lib.attrsets.genAttrs ghcs buildForVersion;
monad-bayes = monad-bayes-per-ghc.ghc902;
monad-bayes-all-ghcs = pkgs.linkFarm "monad-bayes-all-ghcs" monad-bayes-per-ghc;
jupyterEnvironment = mkJupyterlabNew {
imports = [
(import ./kernels/haskell.nix {inherit monad-bayes;})
];
};
monad-bayes-dev = pkgs.mkShell {
inputsFrom = [monad-bayes.env];
packages = with pre-commit-hooks.packages.${system}; [
alejandra
cabal-fmt
hlint
ormolu
jupyterEnvironment
];
shellHook = pre-commit.shellHook;
};
pre-commit = pre-commit-hooks.lib.${system}.run {
inherit src;
hooks = {
alejandra.enable = true;
cabal-fmt.enable = true;
hlint.enable = false;
ormolu.enable = true;
};
};
in rec {
packages = {
inherit monad-bayes monad-bayes-per-ghc monad-bayes-all-ghcs pre-commit jupyterEnvironment;
};
packages.default = packages.monad-bayes;
checks = {inherit monad-bayes pre-commit;};
devShells.default = monad-bayes-dev;
# Needed for backwards compatibility with Nix versions <2.8
defaultPackage = warnToUpdateNix packages.default;
devShell = warnToUpdateNix devShells.default;
}
);
}