-
Notifications
You must be signed in to change notification settings - Fork 81
/
flake.nix
171 lines (166 loc) · 6.36 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
{
inputs = {
haskellNix = {
url = "github:input-output-hk/haskell.nix";
# prevent nix-direnv from fetching stackage
inputs.stackage.url = "github:input-output-hk/empty-flake";
};
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks.url = "github:cachix/git-hooks.nix";
# for Ormolu Live
ghc-wasm-meta.url = "gitlab:ghc/ghc-wasm-meta?host=gitlab.haskell.org";
};
outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
inherit (inputs.haskellNix) config;
overlays = [ inputs.haskellNix.overlay ];
};
inherit (pkgs) lib haskell-nix;
inherit (haskell-nix) haskellLib;
ghcVersions = [ "ghc965" "ghc982" "ghc9101" ];
defaultGHCVersion = builtins.head ghcVersions;
perGHC = lib.genAttrs ghcVersions (ghcVersion:
let
hsPkgs = pkgs.haskell-nix.cabalProject {
src = ./.;
compiler-nix-name = ghcVersion;
modules = [{
packages.ormolu.writeHieFiles = true;
packages.extract-hackage-info.writeHieFiles = true;
packages.ormolu.components.exes.ormolu.preBuild =
lib.mkIf (self ? rev) ''export ORMOLU_REV=${self.rev}'';
}];
};
inherit (hsPkgs.ormolu.components.exes) ormolu;
hackageTests = import ./expected-failures { inherit pkgs ormolu; };
regionTests = import ./region-tests { inherit pkgs ormolu; };
fixityTests = import ./fixity-tests { inherit pkgs ormolu; };
weeder = hsPkgs.tool "weeder" {
version = "2.6.0";
modules = [{ reinstallableLibGhc = false; }];
};
packages = lib.recurseIntoAttrs ({
inherit ormolu;
ormoluTests = haskellLib.collectChecks' hsPkgs;
dev = { inherit hsPkgs; };
} // hackageTests // regionTests // fixityTests
// lib.optionalAttrs (ghcVersion == defaultGHCVersion) {
inherit (hsPkgs.extract-hackage-info.components.exes) extract-hackage-info;
weeder = pkgs.runCommand "ormolu-weeder" { buildInputs = [ weeder ]; } ''
mkdir -p $out
weeder --config ${./weeder.toml} \
--hie-directory ${hsPkgs.ormolu.components.library.hie} \
--hie-directory ${hsPkgs.ormolu.components.exes.ormolu.hie} \
--hie-directory ${hsPkgs.ormolu.components.tests.tests.hie} \
--hie-directory ${hsPkgs.extract-hackage-info.components.exes.extract-hackage-info.hie}
'';
});
in
packages // {
ci = pkgs.linkFarm "ormolu-ci-${ghcVersion}"
(flake-utils.lib.flattenTree packages);
});
defaultGHC = perGHC.${defaultGHCVersion};
binaries =
let
hsPkgs = defaultGHC.dev.hsPkgs.appendModule {
modules = [{
dontStrip = false;
dontPatchELF = false;
enableDeadCodeElimination = true;
}];
};
ormoluExe = hsPkgs: hsPkgs.hsPkgs.ormolu.components.exes.ormolu;
linuxWindows = {
native = ormoluExe hsPkgs.projectCross.musl64;
windows = ormoluExe hsPkgs.projectCross.mingwW64;
};
macOS.native = pkgs.runCommand "ormolu-macOS"
{
nativeBuildInputs = [
pkgs.macdylibbundler
pkgs.darwin.autoSignDarwinBinariesHook
];
} ''
mkdir -p $out/bin
cp ${ormoluExe hsPkgs}/bin/ormolu $out/bin/ormolu
chmod 755 $out/bin/ormolu
dylibbundler -b --no-codesign \
-x $out/bin/ormolu \
-d $out/bin \
-p '@executable_path'
signDarwinBinariesInAllOutputs
'';
in
lib.recurseIntoAttrs
(lib.optionalAttrs (system == "x86_64-linux") linuxWindows
// lib.optionalAttrs pkgs.hostPlatform.isDarwin macOS);
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
cabal-gild.enable = true;
nixpkgs-fmt.enable = true;
deadnix.enable = true;
};
};
ormoluLive = import ./ormolu-live { inherit system inputs; };
in
{
packages = flake-utils.lib.flattenTree {
inherit binaries pre-commit-check;
default = defaultGHC.ormolu;
};
apps = {
default = flake-utils.lib.mkApp {
drv = defaultGHC.ormolu;
exePath = "/bin/ormolu";
};
extract-hackage-info = flake-utils.lib.mkApp {
drv = defaultGHC.extract-hackage-info;
exePath = "/bin/extract-hackage-info";
};
format = flake-utils.lib.mkApp {
drv = pkgs.writeShellApplication {
name = "ormolu-format";
text = builtins.readFile ./nix/format.sh;
runtimeInputs = [
defaultGHC.ormolu
];
};
};
};
devShells = {
default = defaultGHC.dev.hsPkgs.shellFor {
tools = {
cabal = "latest";
haskell-language-server = {
src = inputs.haskellNix.inputs."hls-2.8";
configureArgs = "--disable-benchmarks --disable-tests";
};
};
nativeBuildInputs = pre-commit-check.enabledPackages;
withHoogle = false;
exactDeps = false;
inherit (pre-commit-check) shellHook;
};
ormoluLive = ormoluLive.shell;
};
legacyPackages = defaultGHC // perGHC;
});
nixConfig = {
extra-substituters = [
"https://cache.iog.io"
"https://cache.zw3rk.com"
"https://tweag-ormolu.cachix.org"
];
extra-trusted-public-keys = [
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
"loony-tools:pr9m4BkM/5/eSTZlkQyRt57Jz7OMBxNSUiMC4FkcNfk="
"tweag-ormolu.cachix.org-1:3O4XG3o4AGquSwzzmhF6lov58PYG6j9zHcTDiROqkjM="
];
};
}