-
Notifications
You must be signed in to change notification settings - Fork 8
/
devShells.nix
285 lines (263 loc) · 8.21 KB
/
devShells.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
##################################################################
# Development shells
##################################################################
{ self, ... }:
{
perSystem =
{ pkgs, config, ... }:
{
pre-commit.check.enable = true;
pre-commit.devShell = self.devShells.default;
pre-commit.settings.hooks = {
actionlint.enable = true;
shellcheck.enable = true;
stylua.enable = true;
luacheck.enable = false;
deadnix.enable = true;
deadnix.excludes = [ "nix/overlays/nodePackages/node2nix" ];
nixfmt-rfc-style.enable = true;
dune-fmt.enable = true;
dune-fmt.settings.extraRuntimeInputs = [ pkgs.ocamlPackages.ocamlformat ];
dune-fmt.files = "apps/rin.rocks";
dune-fmt.entry = "dune build @fmt --root=apps/rin.rocks --auto-promote";
};
devShells =
let
inherit (pkgs) lib;
mutFirstChar =
f: s:
let
firstChar = f (lib.substring 0 1 s);
rest = lib.substring 1 (-1) s;
in
# matched = builtins.match "(.)(.*)" s;
# firstChar = f (lib.elemAt matched 0);
# rest = lib.elemAt matched 1;
firstChar + rest;
toCamelCase_ =
sep: s:
mutFirstChar lib.toLower (lib.concatMapStrings (mutFirstChar lib.toUpper) (lib.splitString sep s));
toCamelCase =
s:
builtins.foldl' (s: sep: toCamelCase_ sep s) s [
"-"
"_"
"."
];
mkNodeShell =
name:
let
node = pkgs.${name};
corepackShim = pkgs.nodeCorepackShims.overrideAttrs (_: {
buildInputs = [ node ];
});
in
pkgs.mkShell {
description = "${name} Development Environment";
buildInputs = [
node
corepackShim
];
};
mkGoShell =
name:
let
go = pkgs.${name};
in
pkgs.mkShell {
description = "${name} Development Environment";
buildInputs = [ go ];
shellHook = ''
export GOPATH="$(${go}/bin/go env GOPATH)"
export PATH="$PATH:$GOPATH/bin"
'';
};
mkShell =
pkgName: name:
if lib.strings.hasPrefix "nodejs_" pkgName then
mkNodeShell name
else if lib.strings.hasPrefix "go_" pkgName then
mkGoShell name
else
builtins.throw "Unknown package ${pkgName} for making shell environment";
mkShells =
pkgName:
let
mkShell_ = mkShell pkgName;
in
builtins.foldl' (acc: name: acc // { "${toCamelCase name}" = mkShell_ name; }) { } (
builtins.filter (lib.strings.hasPrefix pkgName) (builtins.attrNames pkgs)
);
in
####################################################################################################
# see nodejs_* definitions in {https://search.nixos.org/packages?query=nodejs_}
#
# versions: 14, 18, 20, 22, Latest
#
# $ nix develop github:r17x/nixpkgs#<nodejsVERSION>
#
#
mkShells "nodejs_"
// mkShells "go_"
// {
default = pkgs.mkShell {
shellHook = ''
${config.pre-commit.installationScript}
'';
};
#
#
# $ nix develop github:r17x/nixpkgs#ocaml
#
#
ocaml = pkgs.mkShell {
description = "OCaml development environment";
buildInputs = with pkgs.ocamlPackages; [
dune
ocaml
opam
merlin
];
};
#
#
# $ nix develop github:r17x/nixpkgs#ocamlorg
#
#
ocamlorg =
let
ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_14;
in
pkgs.mkShell {
description = "OCaml.org development environment";
buildInputs = with ocamlPackages; [
ocaml
merlin
];
nativeBuildInputs = with pkgs; [
opam
pkg-config
libev
oniguruma
openssl
gmp
];
};
#
#
# $ nix develop github:r17x/nixpkgs#melange
#
#
melange = pkgs.mkShell {
description = "Melange Development Environment with OCaml 5_2";
shellHook = config.pre-commit.installationScript;
nativeBuildInputs = with pkgs.ocamlPackages; [
ocaml
dune_3
findlib
ocaml-lsp
ocamlformat
reason
merlin
melange
];
buildInputs = with pkgs.ocamlPackages; [
angstrom
dream
melange
melange-webapi
reason-react
reason-react-ppx
server-reason-react
atdgen
atdgen-runtime
yojson
lwt
lwt_ppx
cohttp
cohttp-lwt-unix
# TODO: styled-ppx fix build
# styled-ppx
pkgs.nodejs_20
(pkgs.nodeCorepackShims.overrideAttrs (_: {
buildInputs = [ pkgs.nodejs_20 ];
}))
];
};
#
#
# $ nix develop github:r17x/nixpkgs#go
#
#
go = pkgs.mkShell {
description = "Go Development Environment";
nativeBuildInputs = [ pkgs.go ];
shellHook = ''
export GOPATH="$(${pkgs.go}/bin/go env GOPATH)"
export PATH="$PATH:$GOPATH/bin"
'';
};
#
#
# $ nix develop github:r17x/nixpkgs#rust-wasm
#
#
rust-wasm = pkgs.mkShell {
description = "Rust Development Environment";
# declared ENV variables when starting shell
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
nativeBuildInputs = with pkgs; [
rustc
cargo
gcc
rustfmt
clippy
];
};
rust-cap = pkgs.mkShell {
description = "Rust Development Environment";
# declared ENV variables when starting shell
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
shellHook =
''
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
''
+ lib.optionalString pkgs.stdenv.isDarwin ''
export NIX_LDFLAGS="-F${pkgs.darwin.apple_sdk.frameworks.CoreFoundation}/Library/Frameworks -framework CoreFoundation $NIX_LDFLAGS";
'';
nativeBuildInputs =
with pkgs;
[
rustup
rustc
cargo
rustfmt
clippy
ffmpeg
]
++ lib.optionals pkgs.stdenv.isDarwin (
with pkgs.darwin.apple_sdk;
[
pkgs.libiconv
pkgs.pkg-config
frameworks.Security
frameworks.SystemConfiguration
frameworks.CoreFoundation
frameworks.Cocoa
frameworks.CoreMedia
frameworks.Metal
frameworks.AVFoundation
frameworks.WebKit
pkgs.darwin.apple_sdk_12_3.frameworks.ScreenCaptureKit
]
);
};
#
#
# $ nix develop github:r17x/nixpkgs#bun
#
#
bun = pkgs.mkShell { buildInputs = [ pkgs.bun ]; };
};
};
}