-
Notifications
You must be signed in to change notification settings - Fork 21
/
flake.nix
191 lines (167 loc) · 6.96 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
{
description = "rhine";
nixConfig.bash-prompt = "\[rhine\]$ ";
nixConfig = {
extra-substituters = [
"https://rhine.cachix.org"
];
extra-trusted-public-keys = [
"rhine.cachix.org-1:oFsONI6lXn3XG4aVmIURDa2Rn0dW5XTPy6eJWROIs8k="
];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
monad-schedule = {
url = "github:turion/monad-schedule";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs:
with builtins;
let
lib = inputs.nixpkgs.lib;
# The names of all Haskell packages in this repository, defined as all the directories with *.cabal files in them.
# Contains e.g.: rhine, rhine-examples, rhine-bayes, ...
pnames = map (path: baseNameOf (dirOf path)) (lib.fileset.toList (lib.fileset.fileFilter (file: file.hasExt "cabal") ./.));
# All GHC versions that this project is tested with.
# To be kept in sync with the `tested-with:` section in rhine.cabal.
# To do: Automated check whether this is the same as what get-tested returns.
# Currently blocked on https://github.com/Kleidukos/get-tested/issues/39
supportedGhcs = [ "ghc92" "ghc94" "ghc96" "ghc98" "ghc910" ];
# All Haskell packages defined here that contain a library section
libPnames = filter (pname: pname != "rhine-examples") pnames;
# The Haskell packages set, for every supported GHC version
hpsFor = pkgs:
lib.genAttrs supportedGhcs (ghc: pkgs.haskell.packages.${ghc})
// { default = pkgs.haskellPackages; };
# A haskellPackages overlay containing everything defined in this repo
rhinePackagesOverlay = hfinal: hprev:
lib.genAttrs pnames (pname: hfinal.callCabal2nix pname ./${pname} { });
# A nixpkgs overlay containing everything defined in this repo, for reuse in downstream projects
localOverlay = final: prev:
let
hps = hpsFor final;
# Overrides that are necessary because of dependencies not being up to date or fixed yet in nixpkgs.
# Check on nixpkgs bumps whether some of these can be removed.
temporaryHaskellOverrides = with prev.haskell.lib.compose; [
(hfinal: hprev: {
monad-bayes = markUnbroken hprev.monad-bayes;
time-domain = hprev.callHackageDirect
{
pkg = "time-domain";
ver = "0.1.0.5";
sha256 = "sha256-llDBQuU5ez/0MiOIMH97P4BQhFDyPfTMWinq1wJrDGI=";
}
{ };
})
(hfinal: hprev: lib.optionalAttrs prev.stdenv.isDarwin {
monad-schedule = dontCheck hprev.monad-schedule;
})
(hfinal: hprev: lib.optionalAttrs (lib.versionOlder hprev.ghc.version "9.4") {
time-domain = doJailbreak hprev.time-domain;
})
(hfinal: hprev: lib.optionalAttrs (lib.versionAtLeast hprev.ghc.version "9.10") {
# Remove these as nixpkgs progresses!
finite-typelits = doJailbreak hprev.finite-typelits;
vector-sized = hprev.callHackageDirect
{
pkg = "vector-sized";
ver = "1.6.1";
sha256 = "sha256-//EOAwpEEQkdYF88U/bp0uybKleYHRmTWaKsxIZvCeQ=";
}
{ };
microstache = doJailbreak hprev.microstache;
gloss-rendering = doJailbreak hprev.gloss-rendering;
gloss = doJailbreak hprev.gloss;
})
];
in
{
# The Haskell package set containing the packages defined in this repo
haskell = prev.haskell // {
packageOverrides = lib.composeManyExtensions ([
prev.haskell.packageOverrides
rhinePackagesOverlay
] ++ temporaryHaskellOverrides);
};
# Helper packages containing aspects of the whole rhine build:
# All executables, built with the nixpkgs-default GHC
# We build these only with one GHC because otherwise the bin names would clash
rhine-bin = prev.buildEnv
{
name = "rhine-bin";
paths = map (pname: hps.default.${pname}) pnames;
pathsToLink = [ "/bin" ];
};
# All libraries for all GHC versions
rhine-lib = prev.buildEnv
{
name = "rhine-lib";
paths = lib.mapCartesianProduct
({ hp, pname }: hp.${pname})
{ hp = attrValues hps; pname = pnames; };
pathsToLink = [ "/lib" ];
};
# Haddocks for all packages that can be uploaded to Hackage
rhine-docs = prev.buildEnv
{
name = "rhine-docs";
paths = map (pname: prev.haskell.lib.documentationTarball hps.default.${pname}) libPnames;
};
# Sdist tarballs for all packages that can be uploaded to Hackage
rhine-sdist = prev.buildEnv
{
name = "rhine-sdist";
paths = map (pname: prev.haskell.lib.sdistTarball hps.default.${pname}) libPnames;
};
# All rhine build products
rhine-all = prev.symlinkJoin
{
name = "rhine-all";
paths = with final; [
rhine-bin
rhine-lib
(prev.linkFarm "docsAndSdist" { docs = final.rhine-docs; sdist = rhine-sdist; })
];
};
};
overlay = lib.composeManyExtensions
[
inputs.monad-schedule.overlays.default
localOverlay
];
# Helper to build a flake output for all systems that are defined in nixpkgs
forAllPlatforms = f:
mapAttrs (system: pkgs: f system (pkgs.extend overlay)) inputs.nixpkgs.legacyPackages;
in
{
# Reexport the overlay so other downstream flakes can use it to develop rhine projects with low effort.
overlays.default = overlay;
# Usage: nix fmt
formatter = forAllPlatforms (system: pkgs: pkgs.nixpkgs-fmt);
# This builds all rhine packages on all GHCs, as well as docs and sdist
# Usage: nix build
packages = forAllPlatforms (system: pkgs: {
default = pkgs.rhine-all;
});
# We re-export the entire nixpkgs package set with our overlay.
# Usage examples:
# - nix build .#haskellPackages.rhine
# - nix build .#haskell.packages.ghc98.rhine
# - nix build .#rhine-sdist
legacyPackages = forAllPlatforms (system: pkgs: pkgs);
# Usage: nix develop (will use the default GHC)
# Alternatively, specify the GHC: nix develop .#ghc98
devShells = forAllPlatforms (systems: pkgs: mapAttrs
(_: hp: hp.shellFor {
packages = ps: map (pname: ps.${pname}) pnames;
nativeBuildInputs = with hp; [
cabal-gild
cabal-install
fourmolu
haskell-language-server
];
})
(hpsFor pkgs));
};
}