-
Notifications
You must be signed in to change notification settings - Fork 0
/
haskell-project.nix
115 lines (110 loc) · 3.41 KB
/
haskell-project.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
inputs:
{
# A list of packages in the project.
# Example:
# [
# {
# name = "timeline";
# path = ./package.nix;
# }
# ]
cabalPackages
# A list of compiler versions supported in the project.
# Valid values are keys of haskell.compiler in nixpkgs.
, supportedCompilers
# Default compiler version to choose. Must be one of the supportedCompilers.
, defaultCompiler ? builtins.head supportedCompilers
# Extra tools to include in the shell. This is a function that takes nixpkgs
# as the argument and returns a list of packages.
, extraTools ? nixpkgs: [ ]
, haskellPackagesOverride ? { compilerName, haskellLib, final, prev }: { }
}:
inputs.flake-utils.lib.eachDefaultSystem (system:
let
nixpkgs = import inputs.nixpkgs { inherit system; };
makePackageSet = compilerName: haskellPackages: haskellPackages.override {
overrides = final: prev:
let
projectPackages =
builtins.listToAttrs
(
builtins.map
(cabalPackage: {
name = cabalPackage.name;
value = prev.callPackage cabalPackage.path { };
})
cabalPackages
);
overridenDependencies = haskellPackagesOverride {
inherit compilerName;
haskellLib = nixpkgs.haskell.lib;
inherit final;
inherit prev;
};
in
projectPackages // overridenDependencies;
};
essentialTools = with nixpkgs; [
cabal-install
hlint
nixpkgs-fmt
ormolu
haskellPackages.cabal-fmt
cabal2nix
haskell-ci
miniserve
] ++ extraTools nixpkgs;
makeShell = compilerName: haskellPackages: (makePackageSet compilerName haskellPackages).shellFor {
packages = p: builtins.map (cabalPackage: p.${cabalPackage.name}) cabalPackages;
withHoogle = true;
buildInputs = essentialTools ++ [
nixpkgs.haskellPackages.haskell-language-server
];
};
lightShell = nixpkgs.mkShell {
packages = essentialTools ++ [ nixpkgs.ghc ];
};
in
{
packages =
let packagesWithoutDefault =
builtins.listToAttrs
(
builtins.concatMap
(compilerName:
let pkgSet = makePackageSet compilerName nixpkgs.haskell.packages.${compilerName};
in
builtins.map
(cabalPackage: {
name = "${compilerName}-${cabalPackage.name}";
value = pkgSet.${cabalPackage.name};
})
cabalPackages
)
supportedCompilers
);
in
packagesWithoutDefault // {
default = nixpkgs.runCommand "aggregate"
{
buildInputs = builtins.map (name: packagesWithoutDefault.${name})
(builtins.attrNames packagesWithoutDefault);
} "touch $out";
};
devShells =
let devShellsWithoutDefault =
builtins.listToAttrs
(
builtins.map
(compilerName: {
name = compilerName;
value = makeShell compilerName nixpkgs.haskell.packages.${compilerName};
})
supportedCompilers
); in
devShellsWithoutDefault // {
default = devShellsWithoutDefault.${defaultCompiler};
light = lightShell;
};
}
)