-
Notifications
You must be signed in to change notification settings - Fork 137
/
flake.nix
207 lines (191 loc) · 6.47 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
{
description = "Declarative and reproducible Jupyter environments - powered by Nix";
nixConfig.extra-substituters = [
"https://tweag-jupyter.cachix.org"
];
nixConfig.extra-trusted-public-keys = [
"tweag-jupyter.cachix.org-1:UtNH4Zs6hVUFpFBTLaA4ejYavPo5EFFqgd7G7FxGW9g="
];
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
inputs.nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.05";
inputs.flake-compat.url = "github:edolstra/flake-compat";
inputs.flake-compat.flake = false;
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.ihaskell.url = "github:ihaskell/ihaskell";
inputs.ihaskell.inputs.nixpkgs.follows = "nixpkgs";
inputs.ihaskell.inputs.flake-compat.follows = "";
inputs.ihaskell.inputs.flake-utils.follows = "flake-utils";
inputs.nix-dart.url = "github:djacu/nix-dart";
inputs.nix-dart.inputs.nixpkgs.follows = "nixpkgs";
inputs.nix-dart.inputs.flake-utils.follows = "flake-utils";
inputs.npmlock2nix.url = "github:nix-community/npmlock2nix/0ba0746d62974403daf717cded3f24c617622bc7";
inputs.npmlock2nix.flake = false;
inputs.opam-nix.url = "github:tweag/opam-nix";
inputs.opam-nix.inputs.flake-compat.follows = "";
inputs.opam-nix.inputs.flake-utils.follows = "flake-utils";
inputs.opam-nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
inputs.pre-commit-hooks.inputs.flake-utils.follows = "flake-utils";
inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
inputs.pre-commit-hooks.inputs.flake-compat.follows = "";
# https://github.com/nix-community/poetry2nix/pull/1329
inputs.poetry2nix.url = "github:nix-community/poetry2nix";
inputs.poetry2nix.inputs.flake-utils.follows = "flake-utils";
inputs.poetry2nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.poetry2nix.inputs.treefmt-nix.follows = "";
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
inputs.rust-overlay.inputs.flake-utils.follows = "flake-utils";
inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
outputs = {
self,
nixpkgs,
nixpkgs-stable,
flake-compat,
flake-utils,
ihaskell,
nix-dart,
npmlock2nix,
opam-nix,
pre-commit-hooks,
poetry2nix,
rust-overlay,
...
} @ inputs: let
inherit (nixpkgs) lib;
SYSTEMS = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
welcomeText = ''
You have created a jupyenv template.
Run `nix run` to immediately try it out.
See the jupyenv documentation for more information.
https://jupyenv.io/documentation/getting-started/
'';
kernelLib = import ./lib/kernels.nix {inherit self lib;};
in
(flake-utils.lib.eachSystem SYSTEMS (
system: let
pkgs = nixpkgs.legacyPackages.${system}.appendOverlays [
poetry2nix.overlays.default
];
python = pkgs.python3;
baseArgs = {
inherit self system;
};
pre-commit = pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
alejandra.enable = true;
typos = {
enable = true;
types = ["file"];
files = "\\.((txt)|(md)|(nix)|\\d)$";
};
};
excludes = ["^\\.jupyter/"]; # JUPYTERLAB_DIR
settings = {
typos.write = true;
};
};
update-poetry-lock =
pkgs.writeShellApplication
{
name = "update-poetry-lock";
runtimeInputs = [
pkgs.poetry
];
text = ''
shopt -s globstar
for lock in **/poetry.lock; do
(
echo Updating "$lock"
cd "$(dirname "$lock")"
poetry update
)
done
'';
};
jupyenvLib = lib.makeScope lib.callPackageWith (final: {
inherit self system pkgs lib python nix-dart baseArgs kernelLib;
docsLib = final.callPackage ./lib/docs.nix {};
jupyterLib = final.callPackage ./lib/jupyter.nix {};
});
inherit (jupyenvLib) docsLib jupyterLib;
examples = kernelLib.mapKernelsFromPath (self + /examples) ["example"];
exampleJupyterlabKernelsNew = (
lib.mapAttrs'
(
name: value:
lib.nameValuePair
("jupyterlab-kernel-" + name)
(jupyterLib.mkJupyterlabNew value)
)
examples
);
exampleJupyterlabAllKernelsNew =
jupyterLib.mkJupyterlabNew (builtins.attrValues examples);
in {
lib =
jupyterLib
// kernelLib
// {};
packages =
rec {
jupyterlab-new = jupyterLib.mkJupyterlabNew ./config.nix;
jupyterlab = jupyterLib.mkJupyterlabNew {};
jupyterlab-all-example-kernels = exampleJupyterlabAllKernelsNew;
pub2nix-lock = nix-dart.packages."${system}".pub2nix-lock;
inherit update-poetry-lock;
inherit (docsLib) docs mkdocs;
default = jupyterlab;
}
// exampleJupyterlabKernelsNew;
devShells.default = pkgs.mkShell {
packages = [
pkgs.alejandra
pkgs.typos
pkgs.poetry2nix.cli
# FIXME: pkgs.poetry is segfaulting on nixpkgs-unstable & poetry2nix
# https://github.com/nix-community/poetry2nix/issues/1291
pkgs.poetry
self.packages."${system}".update-poetry-lock
];
shellHook = ''
${pre-commit.shellHook}
'';
};
checks = {
inherit pre-commit;
};
apps = {
update-poetry-lock =
flake-utils.lib.mkApp
{drv = self.packages."${system}".update-poetry-lock;};
};
}
))
// {
# https://flake.parts/options/jupyenv
flakeModule = {
_file = "${toString ./.}/flake.nix#flakeModule";
imports = [
./flake-module.nix
{jupyenv.flake = self;}
];
};
templates.default = self.templates.flake-utils;
templates.flake-utils = {
path = ./template/flake-utils;
description = "Boilerplate for your jupyenv project";
inherit welcomeText;
};
templates.flake-parts = {
path = ./template/flake-parts;
description = "Boilerplate for your jupyenv project";
inherit welcomeText;
};
};
}