-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathflake.nix
190 lines (165 loc) · 5.83 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
{
nixConfig = {
# For `nix build` stack should download packages directly from stackage and bypass nix.
# See: https://zimbatm.com/notes/nix-packaging-the-heretic-way
sandbox = "relaxed";
# The public build cache which is populated by successful GitHub Action runs.
# See: https://app.cachix.org/cache/gogol#pull
extra-substituters = [ "https://gogol.cachix.org" ];
extra-trusted-public-keys = [ "gogol.cachix.org-1:SaJ8mHVUCv4mXLskv46OTBvmE68IgIPtMnc1jlxD09Q=" ];
};
inputs = {
nixpkgs = {
url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
treefmt-nix,
}:
let
# Setup the various formatter's configuration.
mkFormatter =
pkgs:
treefmt-nix.lib.evalModule pkgs (
{ ... }:
{
projectRootFile = "flake.nix";
programs = {
cabal-fmt.enable = true;
nixfmt.enable = true;
ormolu.enable = true;
shellcheck.enable = true;
shfmt.enable = true;
shfmt.indent_size = 4;
yamlfmt.enable = true;
yamlfmt.settings.retain_line_breaks_single = true;
};
settings = {
global.excludes = [
"CONTRIBUTORS"
"cabal.project"
".github/**.yml"
"configs/*"
"**LICENSE"
"**Makefile"
"**.gitkeep"
"*.lhs"
"*.md"
];
formatter = {
cabal-fmt.options = [ "--indent=2" ];
};
};
}
);
# Create a nix shell for developing the project using the specified GHC version.
mkShell =
pkgs: ghcVersion:
let
haskellPackages = pkgs.haskell.packages.${ghcVersion};
ghc = haskellPackages.ghc;
# Adapted from https://www.tweag.io/blog/2022-06-02-haskell-stack-nix-shell/
stack-wrapped = pkgs.symlinkJoin {
name = "stack";
paths = [ pkgs.stack ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/stack \
--add-flags "\
--no-nix \
--no-install-ghc \
--system-ghc \
"
'';
};
in
pkgs.mkShell rec {
name = "gogol-${ghcVersion}-shell";
# Build inputs required by Haskell libraries built by stack. This corresponds to
# the total set of Cabal's `build-depends` fields in the package set.
buildInputs = [
pkgs.pkg-config
pkgs.icu
pkgs.zlib
];
# Tools to make available in the shell.
nativeBuildInputs = [
# Tools specific to the GHC version.
ghc
haskellPackages.cabal-install
haskellPackages.haskell-language-server
# The stack wrapper that uses the shell's GHC version.
stack-wrapped
# Haskell tools that are not tied to the GHC version above.
pkgs.haskellPackages.cabal-fmt
pkgs.haskellPackages.hlint
pkgs.haskellPackages.ormolu
# Generic tools used by the shell.
pkgs.cachix
pkgs.ncurses
];
# The following environment variables is so `stack` builds within the shell
# matches buildStackProject's behavior.
#
# See: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/generic-stack-builder.nix
# Set the implicit stack.yaml to use.
STACK_YAML = "stack-${ghcVersion}.yaml";
# Non-NixOS git needs certificate bundle.
GIT_SSL_CAINFO = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
# Fixes https://github.com/commercialhaskell/stack/issues/2358.
LANG = "en_US.UTF-8";
# Workaround for https://ghc.haskell.org/trac/ghc/ticket/11042.
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
# Convenience so `nix-env` works with the current shell's package set.
NIX_PATH = "nixpkgs=" + pkgs.path;
# Announce GHC version and STACK_YAML being used when entering the nix shell.
shellHook = ''
bold() {
tput bold
printf "$@"
tput sgr0
}
printf >&2 'Using %s with %s\n' "$(bold 'GHC ${ghc.version}')" "$(bold $STACK_YAML)"
'';
};
# Create the system-specific flake outputs by running a function per supported system.
forAllSystems =
f:
nixpkgs.lib.genAttrs [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
] (system: f nixpkgs.legacyPackages.${system});
in
{
# `nix develop` for the 'default' shell, or `nix develop .#<ghcVersion>` for a specific GHC version.
#
# Available GHC versions can be discovered via:
# ```
# $ nix repl
# nix-repl> :load-flake nixpkgs
# nix-repl> legacyPackages.x86_64-linux.haskell.packages.<TAB>
# ```
devShells = forAllSystems (pkgs: rec {
default = ghc910;
ghc910 = mkShell pkgs "ghc910";
ghc984 = mkShell pkgs "ghc984";
ghc966 = mkShell pkgs "ghc966";
});
# `nix fmt` to format the entire repository.
formatter = forAllSystems (pkgs: (mkFormatter pkgs).config.build.wrapper);
# `nix flake check`.
checks = {
formatter = forAllSystems (pkgs: (mkFormatter pkgs).config.build.check self);
};
};
}