-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
116 lines (99 loc) · 3.58 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
# SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io/>
#
# SPDX-License-Identifier: MPL-2.0
{
nixConfig = {
flake-registry = "https://github.com/serokell/flake-registry/raw/master/flake-registry.json";
};
inputs = {
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
flake = false;
};
haskell-nix = {
inputs.hackage.follows = "hackage";
inputs.stackage.follows = "stackage";
};
hackage = {
flake = false;
};
stackage = {
flake = false;
};
};
outputs = { self, nixpkgs, haskell-nix, hackage, stackage, serokell-nix, flake-compat, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
haskellPkgs = haskell-nix.legacyPackages."${system}";
pkgs = import nixpkgs {
inherit system;
overlays = [
serokell-nix.overlay
];
};
lib = pkgs.lib;
hs-package-name = "with-utf8";
ghc-versions = [ "8107" "902" "928" "948" "966" "982" "9101" ];
# invoke haskell.nix for each ghc version listed in ghc-versions
pkgs-per-ghc = lib.genAttrs (map (v: "ghc${v}") ghc-versions)
(ghc: haskellPkgs.haskell-nix.cabalProject {
src = haskellPkgs.haskell-nix.haskellLib.cleanGit {
name = hs-package-name;
src = ./.;
};
compiler-nix-name = ghc;
# haskell.nix configuration
modules = [{
packages.${hs-package-name} = {
ghcOptions = [
# fail on warnings
"-Werror"
# disable optimisations, we don't need them if we don't package or deploy the executable
"-O0"
];
};
}];
});
# returns the list of all components for a package
get-package-components = pkg:
# library
lib.optional (pkg ? library) pkg.library
# haddock
++ lib.optional (pkg ? library) pkg.library.haddock
# exes, tests and benchmarks
++ lib.attrValues pkg.exes
++ lib.attrValues pkg.tests
++ lib.attrValues pkg.benchmarks;
# all components for each specified ghc version
build-all = lib.mapAttrs'
(ghc: pkg:
let components = get-package-components pkg.${hs-package-name}.components;
in lib.nameValuePair "${ghc}:build-all"
(pkgs.linkFarmFromDrvs "build-all" components)) pkgs-per-ghc;
# all tests for each specified ghc version
test-all = lib.mapAttrs'
(ghc: pkg:
let tests = lib.filter lib.isDerivation
(lib.attrValues pkg.${hs-package-name}.checks);
in lib.nameValuePair "${ghc}:test-all"
(pkgs.linkFarmFromDrvs "test-all" tests)) pkgs-per-ghc;
in {
# nixpkgs revision pinned by this flake
legacyPackages = pkgs;
devShells.default = pkgs.mkShell {
buildInputs = [ pkgs.hpack ];
};
# used to dynamically build a matrix in the GitHub pipeline
ghc-matrix = {
include = map (ver: { ghc = ver; }) ghc-versions;
};
# derivations that we can run from CI
checks = build-all // test-all // {
trailing-whitespace = pkgs.build.checkTrailingWhitespace ./.;
reuse-lint = pkgs.build.reuseLint ./.;
hlint = pkgs.build.haskell.hlint ./.;
stylish-haskell = pkgs.build.haskell.stylish-haskell ./.;
hpack = pkgs.build.haskell.hpack ./.;
};
});
}