forked from IntersectMBO/plutus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
302 lines (285 loc) · 12 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# The flake.nix is the entrypoint of all nix code.
#
# This repository uses the std tool https://github.com/divnix/std.
# Familiarity with std is required to be able to contribute effectively.
# While official documentation for std can be found in its GitHub, this flake
# has been thoroughly commented so as to quickstart new maintainers.
#
# Most of what there is to know about the nix code inside this repository
# can be learned by reading this file. A second read will be needed as some
# std-specific terms may be referenced first and defined later.
# You may also refer to the glossary: https://divnix.github.io/std/glossary.html
{
description = "Plutus Core";
# TODO(std) these are the onl inputs, remove once the new inputs are fully migrated.
inputs = {
__old__nixpkgs = {
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "nixpkgs-unstable";
flake = false;
};
__old__haskell-nix = {
url = "github:input-output-hk/haskell.nix";
flake = false;
};
__old__cardano-repo-tool = {
url = "github:input-output-hk/cardano-repo-tool";
flake = false;
};
__old__gitignore-nix = {
url = "github:hercules-ci/gitignore.nix";
flake = false;
};
__old__hackage-nix = {
url = "github:input-output-hk/hackage.nix";
flake = false;
};
__old__iohk-nix = {
url = "github:input-output-hk/iohk-nix";
flake = false;
};
__old__pre-commit-hooks-nix = {
url = "github:cachix/pre-commit-hooks.nix";
flake = false;
};
# TODO(std) these are the new inputs: remove this comment once the old inputs are truly gone.
# The flake inputs will be accessible by name in each nix file like so:
# { inputs, cell }: inputs.nixpkgs, inputs.haskell-nix
# inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/e14f9fb57315f0d4abde222364f19f88c77d2b79";
};
std = {
url = "github:divnix/std/a32f17f7f51166d6f11d3f7852f5078dc6cd8685";
inputs.nixpkgs.follows = "nixpkgs";
};
haskell-nix = {
url = "github:input-output-hk/haskell.nix/11f6d7ae562f4f13e5965a1684fce714a498ede8";
inputs = {
hackage.follows = "hackage-nix";
nixpkgs.follows = "nixpkgs";
};
};
hackage-nix = {
url = "github:input-output-hk/hackage.nix/3c491f25bd4fc1138ea4350ede0ec876fc4df7c4";
flake = false;
};
sphinxcontrib-haddock = {
url = "github:michaelpj/sphinxcontrib-haddock";
flake = false;
};
gitignore-nix = {
url = "github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73";
inputs.nixpkgs.follows = "nixpkgs";
};
haskell-language-server = {
# Pinned to a release
url = "github:haskell/haskell-language-server?ref=1.8.0.0";
flake = false;
};
pre-commit-hooks-nix = {
url = "github:cachix/pre-commit-hooks.nix/60cad1a326df17a8c6cf2bb23436609fdd83024e";
inputs.nixpkgs.follows = "nixpkgs";
};
iohk-nix = {
url = "github:input-output-hk/iohk-nix/e936cc0972fceb544dd7847e39fbcace1c9c00de";
inputs.nixpkgs.follows = "nixpkgs";
};
};
# The flake outputs are managed by std.
outputs = inputs:
# The growOn function accepts a first argument defining the cell blocks.
inputs.std.growOn
{
# Boilerplate
inherit inputs;
# ALL nix files will reside inside this folder, no exception.
# Each subfolder is a "cell".
# Cell names are arbitrary.
# Cells are for highest-level organization and grouping of nix code.
#
# In this repository we have four cells:
# automation
# Hydra jobsets and GHA tasks
# doc
# Develop and build all the documentation artifacts
# plutus
# Develop and build all haskell components
# toolchain
# Common tools and functions shared across multiple cells
cellsFrom = ./__std__/nix;
# Each cell contains arbitrary "cell blocks".
# Each cell block must be either:
# A nix file named after the cell block
# A directory named after the cell block and containing a default.nix
# Cell blocks have types.
# Not all cells have the same cell blocks.
# All cell blocks belong in a cell.
#
# In this repository we have five cell blocks, listed below with their type:
# devshells :: devshells
# Development shells available via nix develop
# packages :: installables
# Packages available via nix build
# devshellProfiles :: functions
# Building blocks for devshells, not exposed to the flake
# scripts :: functions
# Bash scripts simplifying or automating a variety of tasks
# Generally these are available as commands inside the development shell
# These are very repository specific but are exposed to the flake nonetheless
# library :: functions
# Everything that is not a derivation goes here
# Includes functions, attrsets and simple literal values shared across cells
# These are not exposed to the flake
# hydraJobs :: installables
# Jobsets for our Hydra CI
#
# std provides a TUI to interact with the cell blocks.
# Available interactions are determined by the cell block's type.
# Because this repository does not yet use the TUI, the type is mostly irrelevant.
cellBlocks = [
(inputs.std.devshells "devshells")
(inputs.std.installables "packages")
(inputs.std.functions "devshellProfiles")
(inputs.std.functions "scripts")
(inputs.std.functions "library")
(inputs.std.installables "hydraJobs")
];
}
# The growOn function will then accept an arbitrary number of "soil" attrs.
# This is where we translate cells and cell blocks into a standard nix flake
# outputs attrs.
#
# This is where we also decide which cells and which cell blocks will
# make it into the flake. To exclude stuff from the flake, we simply
# do not "harvest" it.
#
# The attrs will be recursively merged in the order in which they appear.
{
# Here we say that we want the devshells cell block of the doc cell
# (which contains a number of shell-able derivations) to be exposed
# by the flake and accessible via nix develop.
devShells = inputs.std.harvest inputs.self [ "doc" "devshells" ];
# Here we say that we want the packages cell block of the doc cell
# (which contains a number of buildable derivations) to be exposed
# by the flake and accessible via nix build (or nix run).
packages = inputs.std.harvest inputs.self [ "doc" "packages" ];
}
{
packages = inputs.std.harvest inputs.self [ "doc" "scripts" ];
}
{
# The devshells inside the haskell cells will be added to the ones
# already harvested from the doc shell. Same for packages.
devShells = inputs.std.harvest inputs.self [ "plutus" "devshells" ];
packages = inputs.std.harvest inputs.self [ "plutus" "packages" ];
}
{
hydraJobs = inputs.std.harvest inputs.self [ "automation" "hydraJobs" ];
packages = inputs.std.harvest inputs.self [ "automation" "hydraJobs" ];
}
{
packages = inputs.std.harvest inputs.self [ "toolchain" "packages" ];
}
{
packages = inputs.std.harvest inputs.self [ "toolchain" "scripts" ];
};
# TODO(std) move this part of the doc (which doesn't need to reference the code
# in flake.nix) into the README or in a separate doc.
# # # # # THE STANDARD FORMAT OF NIX FILES
#
# Notice how *every single nix file* in this repository (with the exception
# of flake.nix) has the same format:
#
# { inputs, cell }: ...
#
# There is no escaping this.
# A description of the arguments follows:
#
# inputs.self
# This is a path pointing to the top level of the repository.
# It is the *only* way to reference source files inside the repository.
# e.g.: { src = inputs.self + /plutus-core-spec; }
#
# inputs.cells
# Provides access to all cells.
# Remember that a cell is named after its folder.
# The full format is inputs.cells.<cell>.<cell-block>.value
# e.g.: inputs.cells.doc.packages.read-the-docs-site
# e.g.: inputs.cells.toolchain.devshellsProfiles.common
# e.g.: inputs.cells.haskell.devshells.haskell-shell
#
# inputs.*flakeInput*
# The flake inputs proper.
# e.g.: inputs.std
# e.g.: inputs.nixpkgs
# e.g.: inputs.sphinxcontrib-haddock
#
# cell.*cell block*
# The cell value gives access to all its cell blocks:
# e.g.: cell.scripts.serve-read-the-docs-site (only works for code in /nix/scripts)
# Alternatively: inputs.cells.doc.scripts.serve-read-the-docs-site (works everywhere)
# e.g.: cell.packages.repo-root.nix (only works for code in /nix/toolchain)
# Alternatively: inputs.cells.toolchain.packages.repo-root (works everywhere)
# # # # # ONE DERIVATION PER NIX FILE
#
# To enforce further discipline, we enact a one-derivation-per-file policy.
# This is currently applied *without exception*.
#
# This means that every single nix file in this repository is either:
# - A default.nix cell block importing and thus grouping all files in its folder
# - A file evaluating to a single derivation
#
# Further, we enforce that the nix fragment name be equal to the file name.
# This means that if one looks at the fully expanded structure of the cellsFrom folder,
# one will conclude that there are exactly as many fragments as there are nix files
# (excluding the default.nix files, which again merely act as a grouper for the cell block).
#
# Finally this means that for each nix file "some-fragment.nix", one can run:
# nix (develop|build|run) .#some-fragment
# That is unless the relevant cell block was not exposed by the flake.
#
# Also note that while virtually all nix files evaluate to derivations, some
# (like the ones in the library cell block) actually evaluate to functions.
# So it is more accurate to say that the convention is to export one
# (non-attribute-set!) nix value per nix file.
# # # # # REFERENCE EXAMPLE
#
# As an example, consider the file /nix/doc/packages/eutxo-paper.nix:
#
# - /doc is the cell name
# - /doc is accessible via cell.* from { inputs, cell } (while inside /nix/doc)
# - /doc is accessible via inputs.cells.doc (everywhere)
# - /packages is the cell block name
# - /packages is accessible via cell.packages (while inside /nix/doc)
# - /packages is accessible via inputs.cells.doc.packages (everywhere)
# - /eutxo-paper.nix contains a *single derivation*
# - eutxo-paper is the name of the flake fragment
# - A derivation named eutxo-paper is accessible via cell.packages.eutxo-paper
# - And also accessible via inputs.cells.doc.packages.eutxo-paper
# - And also buildable via nix build .#eutxo-paper
#
# As another example, consider the file /nix/toolchain/packages/default.nix
#
# - /toolchain is the cell name
# - /toolchain is accessible via cell.* from { inputs, cell } (while inside /nix/toolchain)
# - /toolchain is accessible via inputs.cells.toolchain (everywhere)
# - /packages is the cell block name
# - /packages is accessible via cell.packages (while inside /nix/toolchain)
# - /packages is accessible via inputs.cells.toolchain.packages (everywhere)
# - /default.nix imports every file in its directory
# - /default.nix contains a derivation for each file in its directory
# - Each attrs field in /default.nix is named after the file it imports (minus the .nix)
nixConfig = {
extra-substituters = [
"https://cache.iog.io"
"https://hydra.iohk.io"
];
extra-trusted-public-keys = [
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
];
allow-import-from-derivation = true;
};
}