177 lines
5.1 KiB
Nix
177 lines
5.1 KiB
Nix
{
|
|
description = "A Nix flake for compiling NURE works";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
|
|
typix.url = "github:loqusion/typix";
|
|
typix.inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
# local-nure-upstream.url = "git+ssh://gitea@linerds.us/unexplrd/typst_nure_template?ref=multi-pages";
|
|
# local-nure-upstream.flake = false;
|
|
|
|
# local-nure.url = "git+ssh://gitea@linerds.us/pencelheimer/typst_nure_template";
|
|
local-nure.url = "git+ssh://gitea@linerds.us/unexplrd/typst_nure_template?ref=multi-pages";
|
|
local-nure.flake = false;
|
|
|
|
# Example of downloading icons from a non-flake source
|
|
# font-awesome = {
|
|
# url = "github:FortAwesome/Font-Awesome";
|
|
# flake = false;
|
|
# };
|
|
};
|
|
|
|
outputs = inputs @ {
|
|
nixpkgs,
|
|
typix,
|
|
flake-utils,
|
|
...
|
|
}:
|
|
flake-utils.lib.eachDefaultSystem (system: let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
inherit (pkgs) lib;
|
|
inherit (lib.strings) escapeShellArg;
|
|
|
|
typixLib = typix.lib.${system};
|
|
|
|
src = lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = lib.fileset.unions [
|
|
# lib/ gets imported, which is unwanted
|
|
# (lib.fileset.fromSource (typixLib.cleanTypstSource ./.))
|
|
# ./main.typ
|
|
# (lib.fileset.maybeMissing ./doc.toml)
|
|
# (lib.fileset.maybeMissing ./utils.typ)
|
|
# (lib.fileset.maybeMissing ./chapters)
|
|
# (lib.fileset.maybeMissing ./assets)
|
|
# (lib.fileset.maybeMissing ./figures)
|
|
./src
|
|
];
|
|
};
|
|
commonArgs = {
|
|
typstSource = "src/main.typ";
|
|
|
|
fontPaths = [
|
|
"${pkgs.liberation_ttf}/share/fonts/truetype"
|
|
];
|
|
|
|
# Make sure to override outdated files/links (in case of updated flake.lock)
|
|
# (may be undesirable with config/universities.yaml in case of custom subjects)
|
|
forceVirtualPaths = true;
|
|
|
|
virtualPaths = [
|
|
# Add paths that must be locally accessible to typst here
|
|
# {
|
|
# dest = "src/lib";
|
|
# src = "${inputs.local-nure}/src";
|
|
# }
|
|
# {
|
|
# dest = "config/universities.yaml";
|
|
# src = "${inputs.local-nure}/src/config/universities.yaml";
|
|
# }
|
|
];
|
|
};
|
|
|
|
mkTypstPackagesDrv = name: entries: let
|
|
linkFarmEntries =
|
|
lib.foldl (set: {
|
|
name,
|
|
version,
|
|
namespace,
|
|
input,
|
|
}:
|
|
set
|
|
// {
|
|
"${namespace}/${name}/${version}" = input;
|
|
})
|
|
{}
|
|
entries;
|
|
in
|
|
pkgs.linkFarm name linkFarmEntries;
|
|
|
|
unpublishedTypstPackages = mkTypstPackagesDrv "unpublished-packages" [
|
|
# {
|
|
# namespace = "unexplrd";
|
|
# name = "test-multifile";
|
|
# version = "0.1.0";
|
|
# input = inputs.local-nure;
|
|
# }
|
|
{
|
|
namespace = "local";
|
|
name = "nure";
|
|
version = "0.1.0";
|
|
input = inputs.local-nure;
|
|
}
|
|
];
|
|
|
|
# Any transitive dependencies must be added here
|
|
# See https://loqusion.github.io/typix/recipes/using-typst-packages.html#the-typstpackages-attribute
|
|
# unstable_typstPackages = [
|
|
# {
|
|
# name = "oxifmt";
|
|
# version = "0.2.1";
|
|
# hash = "sha256-8PNPa9TGFybMZ1uuJwb5ET0WGIInmIgg8h24BmdfxlU=";
|
|
# }
|
|
# ];
|
|
|
|
# Compile a Typst project, *without* copying the result
|
|
# to the current directory
|
|
build-drv = typixLib.buildTypstProject (commonArgs
|
|
// {
|
|
inherit src;
|
|
# inherit unstable_typstPackages;
|
|
TYPST_PACKAGE_PATH = unpublishedTypstPackages;
|
|
});
|
|
|
|
# Compile a Typst project, and then copy the result
|
|
# to the current directory
|
|
build-script = typixLib.buildTypstProjectLocal (commonArgs
|
|
// {
|
|
inherit src;
|
|
# inherit unstable_typstPackages;
|
|
TYPST_PACKAGE_PATH = unpublishedTypstPackages;
|
|
});
|
|
|
|
# Watch a project and recompile on changes
|
|
watch-script = typixLib.watchTypstProject (lib.recursiveUpdate commonArgs
|
|
{
|
|
typstWatchCommand = "TYPST_PACKAGE_PATH=${escapeShellArg unpublishedTypstPackages} typst watch";
|
|
});
|
|
in {
|
|
checks = {inherit build-drv build-script watch-script;};
|
|
|
|
packages.default = build-drv;
|
|
packages.watch = watch-script;
|
|
|
|
apps = rec {
|
|
default = watch;
|
|
build = flake-utils.lib.mkApp {
|
|
drv = build-script;
|
|
};
|
|
watch = flake-utils.lib.mkApp {
|
|
drv = watch-script;
|
|
};
|
|
};
|
|
|
|
devShells.default = typixLib.devShell {
|
|
inherit (commonArgs) fontPaths virtualPaths;
|
|
|
|
env = {
|
|
TYPST_PACKAGE_PATH = escapeShellArg unpublishedTypstPackages;
|
|
};
|
|
packages = with pkgs; [
|
|
# WARNING: Don't run `typst-build` directly, instead use `nix run .#build`
|
|
# See https://github.com/loqusion/typix/issues/2
|
|
# build-script
|
|
watch-script
|
|
|
|
just
|
|
typstyle
|
|
yq
|
|
];
|
|
};
|
|
});
|
|
}
|