-
Notifications
You must be signed in to change notification settings - Fork 137
/
flake.nix
185 lines (170 loc) · 6.01 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
{
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/nixos-unstable";
inputs.nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-22.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 = "flake-compat";
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/75199758e1954f78286e7e79c0e3916e28b732b0";
inputs.opam-nix.inputs.flake-compat.follows = "flake-compat";
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.poetry2nix.url = "github:nix-community/poetry2nix";
inputs.poetry2nix.inputs.flake-utils.follows = "flake-utils";
inputs.poetry2nix.inputs.nixpkgs.follows = "nixpkgs";
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,
}: let
inherit (nixpkgs) lib;
SYSTEMS = [
flake-utils.lib.system.x86_64-linux
# TODO - Fix linux first and then get macos working.
# flake-utils.lib.system.x86_64-darwin
];
kernelLib = import ./lib/kernels.nix {inherit self lib;};
in
(flake-utils.lib.eachSystem SYSTEMS (
system: let
pkgs = nixpkgs.legacyPackages.${system};
python = pkgs.python3;
poetry2nixPkgs = import "${poetry2nix}/default.nix" {inherit pkgs poetry;};
poetry = pkgs.callPackage "${poetry2nix}/pkgs/poetry" {inherit python;};
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 = [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 =
{
jupyterlab-new = jupyterLib.mkJupyterlabNew ./config.nix;
jupyterlab = jupyterLib.jupyterlabEnvWrapped baseArgs;
jupyterlab-all-example-kernels = exampleJupyterlabAllKernelsNew;
pub2nix-lock = nix-dart.packages."${system}".pub2nix-lock;
inherit update-poetry-lock;
inherit (docsLib) docs mkdocs;
default = jupyterLib.jupyterlabEnvWrapped baseArgs;
}
// exampleJupyterlabKernelsNew;
devShells.default = pkgs.mkShell {
packages = [
pkgs.alejandra
pkgs.typos
poetry2nixPkgs.cli
poetry
pkgs.rnix-lsp
self.packages."${system}".update-poetry-lock
docsLib.mkdocs
];
shellHook = ''
${pre-commit.shellHook}
'';
};
checks = {
inherit pre-commit;
jupyterlabEnv = jupyterLib.jupyterlabEnvWrapped baseArgs;
};
apps = {
update-poetry-lock =
flake-utils.lib.mkApp
{drv = self.packages."${system}".update-poetry-lock;};
};
}
))
// {
templates.default = {
path = ./template;
description = "Boilerplate for your jupyenv project";
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/
'';
};
};
}