Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Build Thesis directly with Nix and Ironout some Typst 0.12 things #31

Merged
merged 7 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Build Thesis
run: nix -Lv develop .#default --command typst compile ./template/thesis.typ thesis.pdf --root "./"
run: nix -Lv build .#default
- name: Upload Release Asset - Assignment
id: upload
uses: actions/upload-artifact@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
path: ./thesis.pdf
path: ./result/thesis.pdf
name: thesis.pdf
retention-days: 5
- name: Comment PR Link
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Build Thesis
run: nix -Lv develop .#default --command typst compile ./template/thesis.typ thesis.pdf --root "./"
run: nix -Lv build .#default
- name: Create initial tag
run: |
if [ -z "$(git tag -l 'v*')" ]; then
Expand All @@ -46,4 +46,4 @@ jobs:
draft: false
prerelease: false
files: |
thesis.pdf
./result/thesis.pdf
69 changes: 28 additions & 41 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 61 additions & 67 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixos-unstable";
};
flake-utils = {
url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
pre-commit-hooks = {
url = "github:cachix/git-hooks.nix";
Expand All @@ -21,74 +20,69 @@
};
};
outputs =
{ self
, nixpkgs
, flake-utils
, pre-commit-hooks
, typst-nix
, typst-packages
, ...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
in
with pkgs;
{
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true;
inputs:
inputs.parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-darwin"
"x86_64-linux"
];
imports = [
inputs.pre-commit-hooks.flakeModule
];
perSystem =
{
system,
config,
pkgs,
...
}:
{
pre-commit = {
check.enable = true;
settings.hooks = {
nixfmt-rfc-style.enable = true;
deadnix.enable = true;
statix.enable = true;
typstyle.enable = true;
};
};
};

packages = {
default = typst-nix.lib.${system}.mkTypstDerivation {
name = "nixy-thesis-typst";
src = ./.;
extraFonts = with pkgs; [
noto-fonts
open-sans
jetbrains-mono
];
extraCompileFlags = [
"--root"
"./"
];
mainFile = "template/thesis.typ";
outputFile = "thesis.pdf";
typstPackages = {
preview = "${typst-packages}/packages/preview";
packages = {
default = inputs.typst-nix.lib.${system}.mkTypstDerivation {
name = "modern-uit-thesis";
src = ./.;
extraFonts = pkgs.symlinkJoin {
name = "typst-fonts";
paths = with pkgs; [
noto-fonts
open-sans
jetbrains-mono
texlivePackages.charter
];
};
extraCompileFlags = [
"--root"
"./"
];
mainFile = "template/thesis.typ";
outputFile = "thesis.pdf";
typstPackages = {
preview = "${inputs.typst-packages}/packages/preview";
};
};
};
};

devShells.default = mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;

nativeBuildInputs = [
self.checks.${system}.pre-commit-check.enabledPackages
typst
typstyle
tinymist
just
typos
];

TYPST_FONT_PATHS = pkgs.symlinkJoin {
name = "typst-fonts";
paths = with pkgs; [
noto-fonts
open-sans
jetbrains-mono
texlivePackages.charter
devShells.default = pkgs.mkShell {
packages = with pkgs; [
typst
typstyle
tinymist
just
typos
];

shellHook = ''
${config.pre-commit.installationScript}
'';
};
};
}
);
};
}
9 changes: 3 additions & 6 deletions lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@
// The value needs to be of the 'datetime' type.
// More info: https://typst.app/docs/reference/foundations/datetime/
// Example: datetime(year: 2024, month: 03, day: 17)
date: datetime.today(),

// The date that you are submitting your work.
submission-date: datetime.today(),
date: datetime(year: 2024, month: 12, day: 16),

// Format in which the date will be displayed on cover page.
// More info: https://typst.app/docs/reference/foundations/datetime/#format
Expand Down Expand Up @@ -258,7 +255,7 @@

// Set raw text font.
// Default is JetBrains Mono at 9tp with DejaVu Sans Mono as fallback
show raw: set text(font: ("JetBrains Mono", "Fira Code"), size: 9pt)
show raw: set text(font: ("JetBrains Mono", "DejaVu Sans Mono"), size: 9pt)

// Configure page size and margins.
set page(
Expand Down Expand Up @@ -520,7 +517,7 @@
faculty: faculty,
department: department,
major: major,
submission-date: submission-date,
date: date,
)

// Use front matter stylings
Expand Down
4 changes: 2 additions & 2 deletions modules/frontpage.typ
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
faculty: "",
department: "",
major: "",
submission-date: none,
date: none,
) = {
set document(title: title, author: author)
set page(
Expand Down Expand Up @@ -77,7 +77,7 @@
text(
10pt,
weight: "light",
degree + " thesis in " + major + " — " + submission-date.display("[month repr:long] [year]"),
degree + " thesis in " + major + " — " + date.display("[month repr:long] [year]"),
),
)

Expand Down
Binary file modified template/thesis.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion template/thesis.typ
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
table-index: true,
listing-index: true,
abbreviations: abbreviations,
submission-date: datetime.today(),
date: datetime(year: 2024, month: 12, day: 16),
bibliography: bibliography("refs.bib", title: "Bibliography", style: "ieee"),
)

Expand Down
2 changes: 1 addition & 1 deletion template/utils/feedback.typ
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)[
#text(
weight: 700,
counter("feedback").display() + ". Feedback: ",
context (counter("feedback").display() + ". Feedback: "),
)
#feedback
#if response != none {
Expand Down