-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathflake.nix
206 lines (169 loc) · 5.39 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
{
description = "Zero to Nix: Your guide to learning Nix and flakes";
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*";
outputs =
{ self
, nixpkgs
}:
let
# Systems supported
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
"aarch64-linux" # 64-bit ARM Linux
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
# Helper function for scripting
runPkg = pkgs: pkg: "${pkgs.${pkg}}/bin/${pkg}";
in
{
devShells = forAllSystems
({ pkgs }:
let
common = with pkgs; [
# Language
vale
# Link checking
htmltest
lychee
# JS
nodejs
pnpm
# Serve locally
static-web-server
];
run = pkg: runPkg pkgs pkg;
scripts = with pkgs; [
(writeScriptBin "clean" ''
rm -rf dist
'')
(writeScriptBin "setup" ''
clean
${run "pnpm"} install
'')
(writeScriptBin "build" ''
setup
${run "pnpm"} run build
'')
(writeScriptBin "build-ci" ''
setup
ENV=ci ${run "pnpm"} run build
'')
(writeScriptBin "dev" ''
setup
${run "pnpm"} run dev
'')
(writeScriptBin "format" ''
setup
${run "pnpm"} run format
'')
(writeScriptBin "check-internal-links" ''
${run "htmltest"} --conf ./.htmltest.internal.yml
'')
(writeScriptBin "check-external-links" ''
${run "htmltest"} --conf ./.htmltest.external.yml
'')
(writeScriptBin "lint-style" ''
${run "vale"} src/pages
'')
(writeScriptBin "preview" ''
build
${run "pnpm"} run preview
'')
# Run this to see if CI will pass
(writeScriptBin "ci" ''
set -e
build-ci
check-internal-links
lint-style
'')
];
exampleShells = import ./nix/shell/example.nix { inherit pkgs; };
in
{
inherit (exampleShells) example cpp haskell hook javascript python go rust scala multi;
} // {
default = pkgs.mkShell
{
packages = common ++ scripts;
};
});
apps = forAllSystems ({ pkgs }:
let
run = pkg: runPkg pkgs pkg;
runLocal = pkgs.writeScriptBin "run-local" ''
rm -rf dist
${run "pnpm"} install
${run "pnpm"} run build
${run "pnpm"} run preview
'';
in
{
default = {
type = "app";
program = "${runLocal}/bin/run-local";
};
});
templates = {
cpp-dev = {
path = ./nix/templates/dev/cpp;
description = "C++ dev environment template for Zero to Nix";
};
go-dev = {
path = ./nix/templates/dev/golang;
description = "Go dev environment template for Zero to Nix";
};
haskell-dev = {
path = ./nix/templates/dev/haskell;
description = "Haskell dev environment template for Zero to Nix";
};
javascript-dev = {
path = ./nix/templates/dev/javascript;
description = "JavaScript dev environment template for Zero to Nix";
};
python-dev = {
path = ./nix/templates/dev/python;
description = "Python dev environment template for Zero to Nix";
};
rust-dev = {
path = ./nix/templates/dev/rust;
description = "Rust dev environment template for Zero to Nix";
};
scala-dev = {
path = ./nix/templates/dev/scala;
description = "Scala dev environment template for Zero to Nix";
};
cpp-pkg = {
path = ./nix/templates/pkg/cpp;
description = "C++ package starter template for Zero to Nix";
};
go-pkg = {
path = ./nix/templates/pkg/golang;
description = "Go package starter template for Zero to Nix";
};
haskell-pkg = {
path = ./nix/templates/pkg/haskell;
description = "Haskell package starter template for Zero to Nix";
};
javascript-pkg = {
path = ./nix/templates/pkg/javascript;
description = "JavaScript package starter template for Zero to Nix";
};
python-pkg = {
path = ./nix/templates/pkg/python;
description = "Python package starter template for Zero to Nix";
};
rust-pkg = {
path = ./nix/templates/pkg/rust;
description = "Rust package starter template for Zero to Nix";
};
scala-pkg = {
path = ./nix/templates/pkg/scala;
description = "Scala package starter template for Zero to Nix";
};
};
};
}