-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
130 lines (105 loc) · 3.44 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
{
description = "MuchPDF allows you to insert PDF files as images into your Typst document";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
};
outputs =
inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
perSystem =
{ self', pkgs, ... }:
let
stdenv = pkgs.stdenvNoCC;
emscripten = pkgs.emscripten.overrideAttrs (
finalAttrs: prevAttrs: {
version = "3.1.64";
src = pkgs.fetchFromGitHub {
owner = "emscripten-core";
repo = "emscripten";
hash = "sha256-AbO1b4pxZ7I6n1dRzxhLC7DnXIUnaCK9SbLy96Qxqr0=";
rev = finalAttrs.version;
};
patches = prevAttrs.patches ++ [
./patches/emscripten.patch
];
# Don't run (failing) tests.
installPhase =
builtins.replaceStrings [ "python test/runner.py test_hello_world" ] [ "" ]
prevAttrs.installPhase;
}
);
mupdf = pkgs.callPackage ./nix/mupdf.nix {
inherit emscripten;
};
typst-test = pkgs.callPackage ./nix/typst-test.nix { };
typstManifest = builtins.fromTOML (builtins.readFile ./typst.toml);
version = typstManifest.package.version;
in
{
# MuPDF compiled to WASM32.
packages.mupdf = mupdf;
# The WASM component of MuchPDF.
packages.muchpdf = stdenv.mkDerivation {
pname = "muchpdf";
inherit version;
src = ./.;
nativeBuildInputs = with pkgs; [
emscripten
meson
ninja
pkg-config
];
mesonFlags = [
"--cross-file=cross/wasm.txt"
];
preConfigure = ''
mkdir -p .emscriptencache
export EM_CACHE=$(mktemp -d)
'';
buildInputs = [
mupdf
];
};
# Everything packaged to be suitable for publication.
packages.publication =
pkgs.stdenvNoCC.mkDerivation {
pname = "muchpdf";
inherit version;
src = ./.;
installPhase = ''
runHook preInstall
mkdir $out
cp ${self'.packages.muchpdf}/lib/muchpdf.wasm $out/muchpdf.wasm
cp ./typst.toml ./LICENSE ./lib.typ README.md $out
runHook postInstall
'';
doCheck = true;
nativeCheckInputs = [
pkgs.typst
typst-test
];
checkPhase = ''
runHook preCheck
ln -s ${self'.packages.muchpdf}/lib/muchpdf.wasm muchpdf.wasm
typst-test run
runHook postCheck
'';
};
devShells.default = pkgs.mkShell.override { inherit stdenv; } {
name = "muchpdf";
inputsFrom = [
self'.packages.muchpdf
self'.packages.publication
];
packages = with pkgs; [
clang-tools
typst
typst-test
];
};
};
};
}