-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
88 lines (78 loc) · 2.23 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
{
description = "advent of code 2023";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
# common
self,
flake-utils,
nixpkgs,
}: let
target_systems = ["x86_64-linux" "aarch64-darwin"];
in
flake-utils.lib.eachSystem target_systems (
system: let
pkgs = import nixpkgs {
inherit system;
};
shellcheck = {
src_dir,
script_name,
} @ inputs:
pkgs.runCommand "shellcheck" inputs ''
cd "$src_dir"
${pkgs.shellcheck}/bin/shellcheck "$script_name" -x
touch $out
'';
typ_files = let
typFilter = path: type: ((type == "directory") || (builtins.any (ext: pkgs.lib.hasSuffix ext path) [".typ"]));
in
pkgs.lib.cleanSourceWith {
src = ./.;
filter = typFilter;
};
in rec {
checks = {
nix-alejandra = pkgs.stdenvNoCC.mkDerivation {
name = "nix-alejandra";
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type: ((type == "directory") || (pkgs.lib.hasSuffix ".nix" path));
};
phases = ["buildPhase"];
nativeBuildInputs = [pkgs.alejandra];
buildPhase = "(alejandra -qc $src || alejandra -c $src) > $out";
};
};
packages = {
default = pkgs.runCommand "all" {} ''
# print commands, and use globstar
set -x
shopt -s globstar
cp -r "${typ_files}" src/
pushd src >/dev/null
src_files=(**/*.typ)
for f in "''${src_files[@]}" ; do
dest="$out/''${f%.typ}.pdf"
mkdir -p "$(dirname "$dest")"
"${pkgs.typst}/bin/typst" compile "$f" "$out/''${f%.typ}.pdf"
done
# revert settings
set +x
shopt -u globstar
'';
};
apps = {
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
pkgs.alejandra
pkgs.typst
pkgs.typstfmt
];
};
}
);
}