-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
100 lines (97 loc) · 2.77 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
{
description = "kairos-spec";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs =
inputs@{ self
, flake-parts
, nixpkgs
, treefmt-nix
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" ];
imports = [
treefmt-nix.flakeModule
];
perSystem = { config, self', inputs', system, pkgs, lib, ... }:
let
requirements =
let
name = "requirements";
in
pkgs.runCommand name
{
nativeBuildInputs = with pkgs; [
typst
];
}
''
mkdir -p $out
cp -r ${self'.packages.diagrams}/* .
cp ${./${name}}/* .
typst compile main.typ $out/${name}.pdf
'';
design =
let
name = "design";
in
pkgs.runCommand name
{
nativeBuildInputs = with pkgs; [
typst
];
}
''
mkdir -p $out
cp -r ${self'.packages.diagrams}/* .
cp ${./${name}}/* .
typst compile main.typ $out/${name}.pdf
'';
diagrams = pkgs.runCommand "diagrams" { nativeBuildInputs = with pkgs; [ plantuml graphviz ]; }
''
mkdir -p $out
for file in "${./diagrams}"/*; do
filename=$(basename "$file")
base_filename="''${filename%.*}"
if [[ $file == *.puml ]]; then
echo "$file"
plantuml "$file" -tsvg -o $out
fi
if [[ $file == *.dot ]]; then
plantuml "$file" -tsvg -o "$out"
dot -Tsvg "$file" > "$out/$base_filename.svg"
fi
done
'';
in
{
treefmt = {
projectRootFile = ".git/config";
programs.nixpkgs-fmt.enable = true;
settings.formatter = {
typst-fmt = {
command = "${pkgs.typst-fmt}/bin/typstfmt";
options = [
];
includes = [ "*.typ" ];
};
};
};
packages = {
inherit requirements diagrams design;
default = self'.packages.requirements;
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
typst
typst-lsp
graphviz
plantuml
];
};
};
};
}