This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
flake.nix
139 lines (124 loc) · 4.24 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
{
description = "Bayesian Statistics flake with a shell";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
inputs.treefmt-nix.url = "github:numtide/treefmt-nix";
outputs = { self, nixpkgs, flake-utils, pre-commit-hooks, treefmt-nix }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
julia = pkgs.julia-bin.overrideDerivation (oldAttrs: { doInstallCheck = false; });
typst-packages = builtins.fetchGit {
url = "https://github.com/typst/packages.git";
ref = "main";
rev = "aa400735cba3e5bd312b14c69a7b56a01a1b35e4";
};
typst-fonts = pkgs.stdenvNoCC.mkDerivation {
name = "typst-fonts";
src = self;
installPhase =
let
fonts = {
inherit (pkgs) fira fira-mono julia-mono inriafonts;
};
in
pkgs.lib.concatStringsSep "\n" (map
(name: ''
mkdir -p $out/share/fonts/${name}
cp -r ${fonts.${name}}/share/fonts/* $out/share/fonts/${name}
'')
(builtins.attrNames fonts));
};
in
rec {
formatter = treefmtEval.config.build.wrapper;
checks = {
formatting = treefmtEval.config.build.check self;
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
typos.enable = true;
treefmt = {
enable = true;
package = treefmtEval.config.build.wrapper;
};
typstyle = {
enable = true;
name = "typstyle";
entry = "${pkgs.typstyle}/bin/typstyle --check";
files = "\\.typ$";
language = "rust";
};
julia-formatter = {
enable = true;
name = "format julia code";
entry = ''
${julia}/bin/julia -e '
using Pkg
Pkg.activate(".")
Pkg.add("JuliaFormatter")
using JuliaFormatter
format("turing")
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have been formatted !!!"
write(stdout, out)
exit(1)
end'
'';
files = "\\.jl$";
language = "system";
pass_filenames = false;
};
};
};
};
devShells.default = pkgs.mkShell {
packages = with pkgs;[
bashInteractive
# pdfpc # FIXME: broken on darwin
typos
cmdstan
julia
# typst part
typst
typst-fonts
typst-live
typstfmt
hayagriva
];
shellHook = ''
export JULIA_NUM_THREADS="auto"
export JULIA_PROJECT="turing"
export CMDSTAN_HOME="${pkgs.cmdstan}/opt/cmdstan"
export TYPST_FONT_PATHS="${typst-fonts}/share/fonts"
${self.checks.${system}.pre-commit-check.shellHook}
'';
};
packages = {
inherit typst-fonts;
default = pkgs.stdenvNoCC.mkDerivation {
name = "slides";
src = self;
buildInputs = with pkgs; [
typst
typst-fonts
];
buildPhase = ''
mkdir -pv $out/.cache/typst
cp -rv ${typst-packages}/packages $out/.cache/typst
export XDG_CACHE_HOME="$out/.cache"
export TYPST_FONT_PATHS="${typst-fonts}/share/fonts"
typst compile ./slides/slides.typ ./slides/slides.pdf
'';
installPhase = ''
cp ./slides/slides.pdf $out/
'';
};
};
});
}