-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathmain.nix
More file actions
175 lines (157 loc) · 4.58 KB
/
Copy pathmain.nix
File metadata and controls
175 lines (157 loc) · 4.58 KB
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
# NOTE: update mirrored args in `default.nix` when modifying public inputs
{
self ? import ./flake-compat.nix,
system ? builtins.currentSystem,
nixpkgs ? self.inputs.nixpkgs,
treefmt-nix ? self.inputs.treefmt-nix,
lib ? nixpkgs.lib or (import (nixpkgs + "/lib")),
}:
let
overlay = finalPkgs: prevPkgs: {
haskell = prevPkgs.haskell // {
packageOverrides = final: prev: {
nixfmt = final.callCabal2nix "nixfmt" haskellSource { };
};
};
};
pkgs = import nixpkgs {
inherit system;
overlays = [
overlay
];
config = { };
};
inherit (pkgs) haskell;
fs = lib.fileset;
allFiles = fs.gitTracked ./.;
# Used for source-wide checks
source = fs.toSource {
root = ./.;
fileset = allFiles;
};
haskellSource = fs.toSource {
root = ./.;
# Limit to only files needed for the Haskell build
fileset = fs.intersection allFiles (
fs.unions [
./nixfmt.cabal
./src
./main
./LICENSE
]
);
};
haskellBuildPipeline = [
haskell.lib.justStaticExecutables
haskell.lib.dontHaddock
(drv: lib.lazyDerivation { derivation = drv; })
];
build = lib.pipe pkgs.haskellPackages.nixfmt haskellBuildPipeline;
buildStatic = lib.pipe pkgs.pkgsStatic.haskellPackages.nixfmt haskellBuildPipeline;
treefmtEval = (import treefmt-nix).evalModule pkgs {
# Used to find the project root
projectRootFile = ".git/config";
# This uses the version from Nixpkgs instead of the local one,
# which would require building the package to get a development shell
programs.nixfmt.enable = true;
# We don't want to format the files we use to test the formatter!
settings.formatter.nixfmt.excludes = [ "test/*" ];
# Haskell formatter
programs.fourmolu.enable = true;
# GitHub Actions linter
programs.actionlint.enable = true;
programs.zizmor.enable = true;
};
checks = {
inherit build buildStatic;
cabal-check = pkgs.stdenvNoCC.mkDerivation {
name = "nixfmt-cabal-check";
src = source;
nativeBuildInputs = with pkgs; [
cabal-install
];
buildPhase = lib.escapeShellArgs [
"cabal"
"check"
# Ignore some warnings about missing dependency bounds. We don't bother
# specifying upper bounds, as we're not a Haskell
# library for others to consume. We get reproducibility by virtue of
# using the nixpkgs Haskell package set. When we update nixpkgs, we
# rely upon our tests to tell us if anything broke.
"--ignore=missing-upper-bounds"
"--ignore=missing-bounds-important"
# We enable `werror` by default. This is OK because we only support one
# version of GHC at a time.
"--ignore=werror"
];
installPhase = "touch $out";
};
hlint =
pkgs.runCommand "hlint"
{
nativeBuildInputs = [ pkgs.haskellPackages.hlint ];
}
''
cd ${haskellSource}
hlint .
touch $out
'';
reuse = pkgs.stdenvNoCC.mkDerivation {
name = "nixfmt-reuse";
src = source;
nativeBuildInputs = with pkgs; [ reuse ];
buildPhase = "reuse lint";
installPhase = "touch $out";
};
tests = pkgs.stdenvNoCC.mkDerivation {
name = "nixfmt-tests";
src = fs.toSource {
root = ./.;
fileset = fs.intersection allFiles ./test;
};
nativeBuildInputs = with pkgs; [
shellcheck
build
gitMinimal
];
patchPhase = "patchShebangs .";
buildPhase = ''
export HOME=$(mktemp -d)
export PAGER=cat
git config --global user.name "Test"
git config --global user.email "test@test.com"
git config --global init.defaultBranch main
./test/test.sh
./test/mergetool.sh
'';
installPhase = "touch $out";
};
treefmt = treefmtEval.config.build.check source;
};
skippedChecks = lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
# static pretty-simple fails to build on darwin
# https://github.com/NixOS/nixfmt/issues/411
"buildStatic"
];
in
{
packages = {
nixfmt = build;
nixfmt-static = buildStatic;
};
inherit pkgs lib;
shell = pkgs.haskellPackages.shellFor {
packages = p: [ p.nixfmt ];
nativeBuildInputs = with pkgs; [
cabal-install
stylish-haskell
haskellPackages.haskell-language-server
shellcheck
hlint
treefmtEval.config.build.wrapper
];
};
inherit checks;
ci = pkgs.linkFarm "ci" (removeAttrs checks skippedChecks);
treefmt = treefmtEval.config.build.wrapper;
}