Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
92 lines (91 loc) · 4.07 KB
/
Copy pathflake.nix
File metadata and controls
92 lines (91 loc) · 4.07 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
{
description = "Ressources pédagogiques mpi-informatique/exercices";
inputs.environnement.url = "github:mpi-informatique/tp-environnement";
inputs.nixpkgs.follows = "environnement/nixpkgs";
inputs.code-extract = {
url = "github:mpi-informatique/typst-code-extract";
inputs.nixpkgs.follows = "nixpkgs";
};
inputs.mpi = {
url = "github:mpi-informatique/lib";
inputs.environnement.follows = "environnement";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, environnement, code-extract, mpi }:
let
systems = environnement.lib.systems;
forAllSystems = nixpkgs.lib.genAttrs systems;
packagesFor = system: environnement.legacyPackages.${system}.pkgs;
manifest = (builtins.fromTOML (builtins.readFile ./typst.toml)).package;
source = nixpkgs.lib.cleanSourceWith {
src = self;
filter = path: type:
let name = builtins.baseNameOf path; in
!(builtins.elem name [ ".git" ".direnv" ".astro" "dist" "build" "tmp" "__pycache__" "node_modules" ".DS_Store" "web" "shared" "worker" ])
&& !(nixpkgs.lib.hasSuffix ".log" name);
};
typst = system:
let pkgs = packagesFor system; in {
packages = [ pkgs.typst pkgs.just pkgs.python3 pkgs.ripgrep ];
TYPST_PACKAGE_PATH = self.packages.${system}.typst-packages;
TYPST_FONT_PATHS = "${pkgs.newcomputermodern}/share/fonts";
};
dependencies = builtins.fromJSON (builtins.readFile ./nix/typst-packages.json);
in {
lib = { inherit typst; };
packages = forAllSystems (system:
let
pkgs = packagesFor system;
package = pkgs.runCommand "exercices-typst-${manifest.version}" {
nativeBuildInputs = [ pkgs.python3 ];
TYPST_PACKAGE_PATH = code-extract.packages.${system}.default;
} ''
python3 ${source}/scripts/package.py --path "$out"
'';
previews = map (dependency: {
name = "preview/${dependency.name}/${dependency.version}";
path = pkgs.fetchzip {
url = "https://packages.typst.org/preview/${dependency.name}-${dependency.version}.tar.gz";
hash = dependency.hash;
stripRoot = false;
};
}) (builtins.filter (dependency: (dependency.namespace or "preview") == "preview") dependencies);
in {
default = package;
typst-package = package;
typst-packages = pkgs.linkFarm "exercices-typst-packages" (previews ++ [{
name = "local/code-extract/0.2.0";
path = "${code-extract.packages.${system}.default}/local/code-extract/0.2.0";
} {
name = "mpi-informatique/${manifest.name}/${manifest.version}";
path = "${package}/mpi-informatique/${manifest.name}/${manifest.version}";
}]);
});
devShells = forAllSystems (system:
let pkgs = packagesFor system; in {
default = environnement.lib.mkShell system ((typst system) // {
packages = (typst system).packages ++ [ mpi.packages.${system}.default ];
});
web = pkgs.mkShellNoCC ((typst system) // {
packages = (typst system).packages ++ [ pkgs.nodejs_22 pkgs.newcomputermodern pkgs.dejavu_fonts ];
EXERCICES_FONT_PATHS = "${pkgs.newcomputermodern}/share/fonts:${pkgs.dejavu_fonts}/share/fonts";
});
});
checks = forAllSystems (system:
let pkgs = packagesFor system; in {
documents = pkgs.runCommand "exercices-check" {
nativeBuildInputs = [ pkgs.typst pkgs.just pkgs.python3 pkgs.ocaml pkgs.ocamlPackages.findlib mpi.packages.${system}.default pkgs.stdenv.cc pkgs.git ];
TYPST_PACKAGE_PATH = self.packages.${system}.typst-packages;
TYPST_FONT_PATHS = "${pkgs.newcomputermodern}/share/fonts";
} ''
export HOME="$TMPDIR"
cp -R ${source} source
chmod -R u+w source
cd source
just check
mkdir -p "$out"
cp -R build/. "$out/"
'';
});
};
}