-
Notifications
You must be signed in to change notification settings - Fork 178
/
Copy pathflake.nix
130 lines (118 loc) · 3.79 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 = "Install latex reqs";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
# Build the plannergen as a binary using fixed input versions
# This means that the subsequent pdf generation does not need internet access
# and is therefore a "pure" nix output
plannergen = pkgs.buildGoModule {
src = self;
name = "plannergen";
vendorSha256 = "sha256:F3cln/CPSAonLTCvjSCMHhrzEQgWIOWw0vWwb6BG+pI=";
};
# Go is packaged into the devShell for developing the package,
# but is not used for the "nix build" outputs - these use the pre-built
# binary instead
goDeps = [
pkgs.go
];
# Dependencies for building the latex files
texDeps = with pkgs; [
libuuid # for the "rev" utility
ps # Used by build.sh
python3 # used in the build scripts
(texlive.combine {
inherit (texlive)
metafont
scheme-small
xcolor
pgf
wrapfig
makecell
multirow
leading
marginnote
adjustbox
multido
varwidth
blindtext
setspace
ifmtarg
extsizes
dashrule
;
})
];
in
rec
{
devShell = pkgs.mkShell {
shellHook = ''
unset GOPATH
unset GOROOT
unset GO_VERSION
'';
buildInputs = [
pkgs.nixpkgs-fmt # utility for pretty formatting of .nix files
] ++ goDeps ++ texDeps;
};
defaultPackage = packages.pdf-next;
packages =
let
# Next year, as a string
next-year = builtins.readFile (
pkgs.stdenv.mkDerivation {
name = "current-year";
buildInputs = [ pkgs.coreutils ];
buildCommand = ''
date -d "+1 year" +%Y > $out
'';
});
# List of years to always build
build-years = [
"2025"
"2026"
"2027"
"2028"
"2029"
"2030"
];
# Function that, given a year, builds a pdf for it
make-PDF = year: pkgs.stdenv.mkDerivation
{
name = "pdfs";
# Minimal set of dependencies to build the pdfs:
# Latex and the built plannergen binary
buildInputs = texDeps ++ [ plannergen ];
src = "${self}";
buildCommand = ''
cp -r $src/* .
patchShebangs .
chmod -R 770 *
chmod +x *.sh
PLANNERGEN_BINARY=plannergen eval $PWD/build.sh ${year}
mkdir $out
cp *.pdf $out/.
'';
};
list-of-pdfs = map (y: { name = "pdf-${y}"; value = make-PDF y; }) build-years;
in
builtins.listToAttrs list-of-pdfs
// {
# Append next year's pdf which is the default output
pdf-next = make-PDF next-year;
# Also output all pdfs in the same derivation for the GitHub action
pdf-all = pkgs.stdenv.mkDerivation {
name = "all-pdfs";
buildCommand = ''
mkdir $out
cp -r ${builtins.concatStringsSep " " (map (x: "${x.value}/*" ) list-of-pdfs)} $out/.
'';
};
};
}
);
}