-
Notifications
You must be signed in to change notification settings - Fork 154
/
flake.nix
176 lines (151 loc) · 5.7 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
{
description = "A functional hardware description language";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
ghc-tcplugins-extra = {
url = "github:clash-lang/ghc-tcplugins-extra";
flake = false;
};
ghc-typelits-extra = {
url = "github:clash-lang/ghc-typelits-extra";
flake = false;
};
ghc-typelits-knownnat = {
url = "github:clash-lang/ghc-typelits-knownnat";
flake = false;
};
ghc-typelits-natnormalise = {
url = "github:clash-lang/ghc-typelits-natnormalise";
flake = false;
};
};
outputs = args@{ self, nixpkgs, flake-utils, ... }:
let
# The versions of GHC that we want to be able to build / develop against
# within the nix environment. Since nix is lazy, only derivations for
# versions of GHC which are used are actually evaluated.
ghcVersions = [ "ghc902" "ghc962" ];
# We pick a single version of GHC to use by default within nix. This is
# probably cleaner than always having N copies of each package / app and
# being forced to refer to them by their GHC version.
defaultGhcVersion = "ghc962";
# Overlays are not per-system, so let's only compute them once.
# For each version of GHC we produce a `pkgs.clashPackages-ghcVER`, e.g.
# `pkgs.clashPackages-ghc962`.
overlays =
let
makeOverlay =
import (./. + "/nix/overlay.nix") {
inherit (args)
ghc-tcplugins-extra
ghc-typelits-extra
ghc-typelits-knownnat
ghc-typelits-natnormalise;
};
clashOverlays =
nixpkgs.lib.attrsets.genAttrs ghcVersions makeOverlay;
in
clashOverlays // { default = clashOverlays.${defaultGhcVersion}; };
in
# Overlays are specified here, since they are not a per-system attribute of
# a flake (unlike packages, apps, devShells etc.) which are system-specific.
{ inherit overlays; } //
flake-utils.lib.eachDefaultSystem (system:
let
# Our final nixpkgs has an overlay applied for each supported version of
# GHC for the repository. We can extract all the flake outputs from this
# beefed-up nixpkgs.
pkgs =
let
overlay =
nixpkgs.lib.composeManyExtensions
(nixpkgs.lib.attrsets.attrValues
# The default overlay is just a copy of the overlay for the
# default version of GHC. We don't need to apply it twice.
(builtins.removeAttrs overlays [ "default" ]));
in
nixpkgs.legacyPackages.${system}.extend overlay;
in
assert pkgs.lib.asserts.assertOneOf "defaultGhcVersion" defaultGhcVersion ghcVersions;
{
packages = {
inherit (pkgs."clashPackages-${defaultGhcVersion}")
clash-benchmark
clash-cores
clash-cosim
clash-ffi
clash-ghc
clash-lib
clash-lib-hedgehog
clash-prelude
clash-prelude-hedgehog
clash-profiling
clash-profiling-prepare
clash-term
clash-testsuite;
default =
pkgs."clashPackages-${defaultGhcVersion}".clash-ghc;
};
apps = {
# Executables listed here can be run using the `nix run` command, which
# is more convenient than finding / digging around in the store path of
# the output from `nix build`.
clash = {
type = "app";
program = "${self.packages.${system}.clash-ghc}/bin/clash";
};
clashi = {
type = "app";
program = "${self.packages.${system}.clash-ghc}/bin/clashi";
};
clash-benchmark-normalization = {
type = "app";
program = "${self.packages.${system}.clash-benchmark}/bin/clash-benchmark-normalization";
};
clash-benchmark-concurrency = {
type = "app";
program = "${self.packages.${system}.clash-benchmark}/bin/clash-benchmark-concurrency";
};
clash-profile-netlist-prepare = {
type = "app";
program = "${self.packages.${system}.clash-profiling-prepare}/bin/clash-profile-netlist-prepare";
};
clash-profile-netlist-run = {
type = "app";
program = "${self.packages.${system}.clash-profiling}/bin/clash-profile-netlist-run";
};
clash-profile-normalization-prepare = {
type = "app";
program = "${self.packages.${system}.clash-profiling-prepare}/bin/clash-profile-normalization-prepare";
};
clash-profile-normalization-run = {
type = "app";
program = "${self.packages.${system}.clash-profiling}/bin/clash-profile-normalization-run";
};
clash-term = {
type = "app";
program = "${self.packages.${system}.clash-term}/bin/clash-term";
};
clash-testsuite = {
type = "app";
program = "${self.packages.${system}.clash-testsuite}/bin/clash-testsuite";
};
default = self.apps.${system}.clashi;
};
devShells =
let
makeDevShell = import ./nix/devshell.nix {
inherit pkgs;
};
clashDevShells =
pkgs.lib.attrsets.genAttrs ghcVersions makeDevShell;
in
clashDevShells // { default = clashDevShells.${defaultGhcVersion}; };
}
);
}