forked from unionlabs/goblinbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
103 lines (95 loc) · 3.09 KB
/
flake.nix
File metadata and controls
103 lines (95 loc) · 3.09 KB
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
{
description = "Interop: Principles, Techniques, and Tools";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix.url = "github:numtide/treefmt-nix";
mdbook-shiftinclude = {
url = "github:daviddrysdale/mdbook-shiftinclude";
flake = false;
};
};
outputs =
inputs@{
flake-parts,
treefmt-nix,
mdbook-shiftinclude,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ treefmt-nix.flakeModule ];
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
perSystem =
{
self',
pkgs,
system,
...
}:
{
# Build mdbook-shiftinclude
packages = rec {
shiftinclude = pkgs.rustPlatform.buildRustPackage {
pname = "mdbook-shiftinclude";
version = "0.1.0";
src = mdbook-shiftinclude;
cargoLock.lockFile = "${mdbook-shiftinclude}/Cargo.lock";
};
default = pkgs.stdenv.mkDerivation {
name = "goblinbook";
src = ./.;
buildInputs = with pkgs; [
mdbook
mdbook-mermaid
nodePackages.mermaid-cli
shiftinclude
];
buildPhase = ''
# Find all .md files and process Mermaid diagrams to SVG
find src -name "*.md" -type f -exec sh -c '
file="$1"
echo "Processing $file"
awk "/^```mermaid$/,/^```$/{p=NR};p&&NR>=p{a[NR]=\$0}p&&/^```$/{
print \"Converting diagram to SVG...\"
for(i=p+1;i<NR;i++) printf \"%s\\n\", a[i] > \"temp.mmd\"
system(\"mmdc -i temp.mmd -o \" substr(\$file,1,length(\$file)-3) NR \".svg\")
print \"-3) NR \".svg)\"
delete a
p=0
}" "$file" > "$file.new"
mv "$file.new" "$file"
' sh {} \;
export PATH=$PATH:${shiftinclude}/bin
mdbook build
'';
installPhase = ''
mkdir -p $out
cp -r book $out/
'';
};
};
devShells.default = pkgs.mkShell {
packages = with pkgs; [
mdbook
mdbook-mermaid
nodePackages.mermaid-cli
nodePackages.graphqurl
self'.packages.shiftinclude
];
};
treefmt = {
projectRootFile = "flake.nix";
programs.nixfmt.enable = pkgs.lib.meta.availableOn pkgs.stdenv.buildPlatform pkgs.nixfmt-rfc-style.compiler;
programs.nixfmt.package = pkgs.nixfmt-rfc-style;
programs.mdformat.enable = true;
programs.prettier.enable = true;
programs.taplo.enable = true;
};
};
};
}