-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathflake.nix
225 lines (216 loc) · 7.24 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
{
description = "srid/haskell-template: Nix template for Haskell projects";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/3a05eebede89661660945da1f151959900903b6a";
nixpkgs-lib.url = "github:nixos/nixpkgs/3a05eebede89661660945da1f151959900903b6a?dir=lib";
systems.url = "github:nix-systems/default";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs-lib";
};
haskell-flake.url = "github:srid/haskell-flake";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
devshell = {
url = "github:deemp/devshell";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.inputs.systems.follows = "systems";
};
};
outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
inputs.haskell-flake.flakeModule
inputs.treefmt-nix.flakeModule
inputs.devshell.flakeModule
];
perSystem =
{
self',
system,
lib,
config,
pkgs,
...
}:
let
ghcVersion = "9101";
haskellPackages = pkgs.haskell.packages."ghc${ghcVersion}";
devTools =
let
wrapTool =
pkgsName: pname: flags:
let
pkg = pkgs.${pkgsName};
in
pkgs.symlinkJoin {
name = pname;
paths = [ pkg ];
meta = pkg.meta;
version = pkg.version;
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/${pname} \
--add-flags "${flags}"
'';
};
in
{
cabal = wrapTool "cabal-install" "cabal" "-v0";
hpack = pkgs.haskellPackages.hpack_0_37_0;
ghc = builtins.head (
builtins.filter (
x: pkgs.lib.attrsets.isDerivation x && pkgs.lib.strings.hasPrefix "ghc-" x.name
) config.haskellProjects.default.outputs.devShell.nativeBuildInputs
);
inherit (haskellPackages) haskell-language-server;
};
# Our only Haskell project. You can have multiple projects, but this template
# has only one.
# See https://github.com/srid/haskell-flake/blob/master/example/flake.nix
haskellProjects.default = {
# To avoid unnecessary rebuilds, we filter projectRoot:
# https://community.flake.parts/haskell-flake/local#rebuild
projectRoot = builtins.toString (
lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./app
./src
./updater.cabal
./LICENSE
./README.md
./CHANGELOG.md
];
}
);
# The base package set (this value is the default)
basePackages = haskellPackages.override {
overrides =
self: super:
let
jailbreakUnbreak =
pkg:
pkgs.haskell.lib.doJailbreak (
pkg.overrideAttrs (_: {
meta = { };
})
);
packageFromHackage =
pkg: ver: sha256:
super.callHackageDirect { inherit pkg ver sha256; } { };
in
{
co-log =
packageFromHackage "co-log" "0.6.1.2"
"sha256-3drK/5n45xLc2DES0tTAqGvR6DHpgWnWvPjdx987DeE=";
co-log-concurrent = jailbreakUnbreak super.co-log-concurrent;
with-utf8 = super.with-utf8_1_1_0_0;
bytebuild = super.bytebuild_0_3_16_3;
chronos = super.chronos_1_1_6_2;
};
};
settings =
let
default = {
haddock = false;
check = false;
};
in
{
co-log = {
check = false;
};
co-log-concurrent = {
check = false;
};
with-utf8 = {
check = false;
};
bytebuild = default;
chronos = default;
PyF = {
check = false;
};
};
# Development shell configuration
devShell = {
hlsCheck.enable = false;
hoogle = false;
tools = hp: {
cabal-install = null;
hlint = null;
haskell-language-server = null;
ghcid = null;
};
};
# What should haskell-flake add to flake outputs?
autoWire = [
"packages"
"apps"
"checks"
]; # Wire all but the devShell
};
# Auto formatters. This also adds a flake check to ensure that the
# source tree was auto formatted.
treefmt.config = {
projectRootFile = "flake.nix";
programs.fourmolu.enable = true;
programs.nixfmt-rfc-style.enable = true;
programs.hlint.enable = true;
};
# Default package & app.
packages.default =
let
updater = pkgs.haskell.lib.justStaticExecutables self'.packages.updater;
updaterBin = "$out/bin/${updater.meta.mainProgram}";
in
pkgs.stdenv.mkDerivation {
name = updater.name;
phases = [ "installPhase" ];
installPhase =
# https://sandervanderburg.blogspot.com/2015/10/deploying-prebuilt-binary-software-with.html
# https://wiki.nixos.org/wiki/Packaging/Binaries
# https://github.com/NixOS/patchelf
''
mkdir -p $out/bin
cp -p ${lib.getExe updater} $out/bin
chmod +rw ${updaterBin}
patchelf \
--set-interpreter "$(cat $${pkgs.stdenv.cc}/nix-support/dynamic-linker)" \
--add-needed libgcc_s.so.1 ${updaterBin} \
--set-rpath "$(patchelf --print-rpath ${updaterBin})":${lib.makeLibraryPath [ pkgs.gcc.cc.lib ]} \
${updaterBin}
'';
meta.mainProgram = "updater";
};
# Default shell.
devshells.default = {
commands = {
tools = [
{
expose = true;
packages = devTools;
}
];
};
};
in
{
inherit
devshells
treefmt
packages
haskellProjects
;
};
};
}